Merge branch '15781-multi-value-property-search'
[arvados.git] / sdk / go / arvados / api.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package arvados
6
7 import (
8         "context"
9         "encoding/json"
10 )
11
12 type APIEndpoint struct {
13         Method string
14         Path   string
15         // "new attributes" key for create/update requests
16         AttrsKey string
17 }
18
19 var (
20         EndpointConfigGet                     = APIEndpoint{"GET", "arvados/v1/config", ""}
21         EndpointLogin                         = APIEndpoint{"GET", "login", ""}
22         EndpointCollectionCreate              = APIEndpoint{"POST", "arvados/v1/collections", "collection"}
23         EndpointCollectionUpdate              = APIEndpoint{"PATCH", "arvados/v1/collections/{uuid}", "collection"}
24         EndpointCollectionGet                 = APIEndpoint{"GET", "arvados/v1/collections/{uuid}", ""}
25         EndpointCollectionList                = APIEndpoint{"GET", "arvados/v1/collections", ""}
26         EndpointCollectionProvenance          = APIEndpoint{"GET", "arvados/v1/collections/{uuid}/provenance", ""}
27         EndpointCollectionUsedBy              = APIEndpoint{"GET", "arvados/v1/collections/{uuid}/used_by", ""}
28         EndpointCollectionDelete              = APIEndpoint{"DELETE", "arvados/v1/collections/{uuid}", ""}
29         EndpointCollectionTrash               = APIEndpoint{"POST", "arvados/v1/collections/{uuid}/trash", ""}
30         EndpointCollectionUntrash             = APIEndpoint{"POST", "arvados/v1/collections/{uuid}/untrash", ""}
31         EndpointSpecimenCreate                = APIEndpoint{"POST", "arvados/v1/specimens", "specimen"}
32         EndpointSpecimenUpdate                = APIEndpoint{"PATCH", "arvados/v1/specimens/{uuid}", "specimen"}
33         EndpointSpecimenGet                   = APIEndpoint{"GET", "arvados/v1/specimens/{uuid}", ""}
34         EndpointSpecimenList                  = APIEndpoint{"GET", "arvados/v1/specimens", ""}
35         EndpointSpecimenDelete                = APIEndpoint{"DELETE", "arvados/v1/specimens/{uuid}", ""}
36         EndpointContainerCreate               = APIEndpoint{"POST", "arvados/v1/containers", "container"}
37         EndpointContainerUpdate               = APIEndpoint{"PATCH", "arvados/v1/containers/{uuid}", "container"}
38         EndpointContainerGet                  = APIEndpoint{"GET", "arvados/v1/containers/{uuid}", ""}
39         EndpointContainerList                 = APIEndpoint{"GET", "arvados/v1/containers", ""}
40         EndpointContainerDelete               = APIEndpoint{"DELETE", "arvados/v1/containers/{uuid}", ""}
41         EndpointContainerLock                 = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/lock", ""}
42         EndpointContainerUnlock               = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/unlock", ""}
43         EndpointUserActivate                  = APIEndpoint{"POST", "arvados/v1/users/{uuid}/activate", ""}
44         EndpointUserCreate                    = APIEndpoint{"POST", "arvados/v1/users", "user"}
45         EndpointUserCurrent                   = APIEndpoint{"GET", "arvados/v1/users/current", ""}
46         EndpointUserDelete                    = APIEndpoint{"DELETE", "arvados/v1/users/{uuid}", ""}
47         EndpointUserGet                       = APIEndpoint{"GET", "arvados/v1/users/{uuid}", ""}
48         EndpointUserGetCurrent                = APIEndpoint{"GET", "arvados/v1/users/current", ""}
49         EndpointUserGetSystem                 = APIEndpoint{"GET", "arvados/v1/users/system", ""}
50         EndpointUserList                      = APIEndpoint{"GET", "arvados/v1/users", ""}
51         EndpointUserMerge                     = APIEndpoint{"POST", "arvados/v1/users/merge", ""}
52         EndpointUserSetup                     = APIEndpoint{"POST", "arvados/v1/users/setup", "user"}
53         EndpointUserSystem                    = APIEndpoint{"GET", "arvados/v1/users/system", ""}
54         EndpointUserUnsetup                   = APIEndpoint{"POST", "arvados/v1/users/{uuid}/unsetup", ""}
55         EndpointUserUpdate                    = APIEndpoint{"PATCH", "arvados/v1/users/{uuid}", "user"}
56         EndpointUserUpdateUUID                = APIEndpoint{"POST", "arvados/v1/users/{uuid}/update_uuid", ""}
57         EndpointUserBatchUpdate               = APIEndpoint{"PATCH", "arvados/v1/users/batch", ""}
58         EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
59 )
60
61 type GetOptions struct {
62         UUID         string   `json:"uuid"`
63         Select       []string `json:"select"`
64         IncludeTrash bool     `json:"include_trash"`
65         ForwardedFor string   `json:"forwarded_for"`
66 }
67
68 type UntrashOptions struct {
69         UUID             string `json:"uuid"`
70         EnsureUniqueName bool   `json:"ensure_unique_name"`
71 }
72
73 type ListOptions struct {
74         ClusterID          string                 `json:"cluster_id"`
75         Select             []string               `json:"select"`
76         Filters            []Filter               `json:"filters"`
77         Where              map[string]interface{} `json:"where"`
78         Limit              int                    `json:"limit"`
79         Offset             int                    `json:"offset"`
80         Order              []string               `json:"order"`
81         Distinct           bool                   `json:"distinct"`
82         Count              string                 `json:"count"`
83         IncludeTrash       bool                   `json:"include_trash"`
84         IncludeOldVersions bool                   `json:"include_old_versions"`
85 }
86
87 type CreateOptions struct {
88         ClusterID        string                 `json:"cluster_id"`
89         EnsureUniqueName bool                   `json:"ensure_unique_name"`
90         Select           []string               `json:"select"`
91         Attrs            map[string]interface{} `json:"attrs"`
92 }
93
94 type UpdateOptions struct {
95         UUID  string                 `json:"uuid"`
96         Attrs map[string]interface{} `json:"attrs"`
97 }
98
99 type UpdateUUIDOptions struct {
100         UUID    string `json:"uuid"`
101         NewUUID string `json:"new_uuid"`
102 }
103
104 type UserActivateOptions struct {
105         UUID string `json:"uuid"`
106 }
107
108 type UserSetupOptions struct {
109         UUID                  string                 `json:"uuid,omitempty"`
110         Email                 string                 `json:"email,omitempty"`
111         OpenIDPrefix          string                 `json:"openid_prefix,omitempty"`
112         RepoName              string                 `json:"repo_name,omitempty"`
113         VMUUID                string                 `json:"vm_uuid,omitempty"`
114         SendNotificationEmail bool                   `json:"send_notification_email,omitempty"`
115         Attrs                 map[string]interface{} `json:"attrs"`
116 }
117
118 type UserMergeOptions struct {
119         NewUserUUID       string `json:"new_user_uuid,omitempty"`
120         OldUserUUID       string `json:"old_user_uuid,omitempty"`
121         NewOwnerUUID      string `json:"new_owner_uuid,omitempty"`
122         NewUserToken      string `json:"new_user_token,omitempty"`
123         RedirectToNewUser bool   `json:"redirect_to_new_user"`
124 }
125
126 type UserBatchUpdateOptions struct {
127         Updates map[string]map[string]interface{} `json:"updates"`
128 }
129
130 type UserBatchUpdateResponse struct{}
131
132 type DeleteOptions struct {
133         UUID string `json:"uuid"`
134 }
135
136 type LoginOptions struct {
137         ReturnTo string `json:"return_to"`        // On success, redirect to this target with api_token=xxx query param
138         Remote   string `json:"remote,omitempty"` // Salt token for remote Cluster ID
139         Code     string `json:"code,omitempty"`   // OAuth2 callback code
140         State    string `json:"state,omitempty"`  // OAuth2 callback state
141 }
142
143 type API interface {
144         ConfigGet(ctx context.Context) (json.RawMessage, error)
145         Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
146         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
147         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
148         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
149         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
150         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
151         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
152         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
153         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
154         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
155         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
156         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
157         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
158         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
159         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
160         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
161         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
162         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
163         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
164         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
165         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
166         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
167         UserCreate(ctx context.Context, options CreateOptions) (User, error)
168         UserUpdate(ctx context.Context, options UpdateOptions) (User, error)
169         UserUpdateUUID(ctx context.Context, options UpdateUUIDOptions) (User, error)
170         UserMerge(ctx context.Context, options UserMergeOptions) (User, error)
171         UserActivate(ctx context.Context, options UserActivateOptions) (User, error)
172         UserSetup(ctx context.Context, options UserSetupOptions) (map[string]interface{}, error)
173         UserUnsetup(ctx context.Context, options GetOptions) (User, error)
174         UserGet(ctx context.Context, options GetOptions) (User, error)
175         UserGetCurrent(ctx context.Context, options GetOptions) (User, error)
176         UserGetSystem(ctx context.Context, options GetOptions) (User, error)
177         UserList(ctx context.Context, options ListOptions) (UserList, error)
178         UserDelete(ctx context.Context, options DeleteOptions) (User, error)
179         UserBatchUpdate(context.Context, UserBatchUpdateOptions) (UserList, error)
180         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
181 }