Documentation: reflect the current state of anonymous token generation.
[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         EndpointLogout                        = APIEndpoint{"GET", "logout", ""}
23         EndpointCollectionCreate              = APIEndpoint{"POST", "arvados/v1/collections", "collection"}
24         EndpointCollectionUpdate              = APIEndpoint{"PATCH", "arvados/v1/collections/{uuid}", "collection"}
25         EndpointCollectionGet                 = APIEndpoint{"GET", "arvados/v1/collections/{uuid}", ""}
26         EndpointCollectionList                = APIEndpoint{"GET", "arvados/v1/collections", ""}
27         EndpointCollectionProvenance          = APIEndpoint{"GET", "arvados/v1/collections/{uuid}/provenance", ""}
28         EndpointCollectionUsedBy              = APIEndpoint{"GET", "arvados/v1/collections/{uuid}/used_by", ""}
29         EndpointCollectionDelete              = APIEndpoint{"DELETE", "arvados/v1/collections/{uuid}", ""}
30         EndpointCollectionTrash               = APIEndpoint{"POST", "arvados/v1/collections/{uuid}/trash", ""}
31         EndpointCollectionUntrash             = APIEndpoint{"POST", "arvados/v1/collections/{uuid}/untrash", ""}
32         EndpointSpecimenCreate                = APIEndpoint{"POST", "arvados/v1/specimens", "specimen"}
33         EndpointSpecimenUpdate                = APIEndpoint{"PATCH", "arvados/v1/specimens/{uuid}", "specimen"}
34         EndpointSpecimenGet                   = APIEndpoint{"GET", "arvados/v1/specimens/{uuid}", ""}
35         EndpointSpecimenList                  = APIEndpoint{"GET", "arvados/v1/specimens", ""}
36         EndpointSpecimenDelete                = APIEndpoint{"DELETE", "arvados/v1/specimens/{uuid}", ""}
37         EndpointContainerCreate               = APIEndpoint{"POST", "arvados/v1/containers", "container"}
38         EndpointContainerUpdate               = APIEndpoint{"PATCH", "arvados/v1/containers/{uuid}", "container"}
39         EndpointContainerGet                  = APIEndpoint{"GET", "arvados/v1/containers/{uuid}", ""}
40         EndpointContainerList                 = APIEndpoint{"GET", "arvados/v1/containers", ""}
41         EndpointContainerDelete               = APIEndpoint{"DELETE", "arvados/v1/containers/{uuid}", ""}
42         EndpointContainerLock                 = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/lock", ""}
43         EndpointContainerUnlock               = APIEndpoint{"POST", "arvados/v1/containers/{uuid}/unlock", ""}
44         EndpointContainerRequestCreate        = APIEndpoint{"POST", "arvados/v1/container_requests", "container_request"}
45         EndpointContainerRequestUpdate        = APIEndpoint{"PATCH", "arvados/v1/container_requests/{uuid}", "container_request"}
46         EndpointContainerRequestGet           = APIEndpoint{"GET", "arvados/v1/container_requests/{uuid}", ""}
47         EndpointContainerRequestList          = APIEndpoint{"GET", "arvados/v1/container_requests", ""}
48         EndpointContainerRequestDelete        = APIEndpoint{"DELETE", "arvados/v1/container_requests/{uuid}", ""}
49         EndpointUserActivate                  = APIEndpoint{"POST", "arvados/v1/users/{uuid}/activate", ""}
50         EndpointUserCreate                    = APIEndpoint{"POST", "arvados/v1/users", "user"}
51         EndpointUserCurrent                   = APIEndpoint{"GET", "arvados/v1/users/current", ""}
52         EndpointUserDelete                    = APIEndpoint{"DELETE", "arvados/v1/users/{uuid}", ""}
53         EndpointUserGet                       = APIEndpoint{"GET", "arvados/v1/users/{uuid}", ""}
54         EndpointUserGetCurrent                = APIEndpoint{"GET", "arvados/v1/users/current", ""}
55         EndpointUserGetSystem                 = APIEndpoint{"GET", "arvados/v1/users/system", ""}
56         EndpointUserList                      = APIEndpoint{"GET", "arvados/v1/users", ""}
57         EndpointUserMerge                     = APIEndpoint{"POST", "arvados/v1/users/merge", ""}
58         EndpointUserSetup                     = APIEndpoint{"POST", "arvados/v1/users/setup", "user"}
59         EndpointUserSystem                    = APIEndpoint{"GET", "arvados/v1/users/system", ""}
60         EndpointUserUnsetup                   = APIEndpoint{"POST", "arvados/v1/users/{uuid}/unsetup", ""}
61         EndpointUserUpdate                    = APIEndpoint{"PATCH", "arvados/v1/users/{uuid}", "user"}
62         EndpointUserUpdateUUID                = APIEndpoint{"POST", "arvados/v1/users/{uuid}/update_uuid", ""}
63         EndpointUserBatchUpdate               = APIEndpoint{"PATCH", "arvados/v1/users/batch_update", ""}
64         EndpointUserAuthenticate              = APIEndpoint{"POST", "arvados/v1/users/authenticate", ""}
65         EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
66 )
67
68 type GetOptions struct {
69         UUID         string   `json:"uuid,omitempty"`
70         Select       []string `json:"select"`
71         IncludeTrash bool     `json:"include_trash"`
72         ForwardedFor string   `json:"forwarded_for,omitempty"`
73         Remote       string   `json:"remote,omitempty"`
74 }
75
76 type UntrashOptions struct {
77         UUID             string `json:"uuid"`
78         EnsureUniqueName bool   `json:"ensure_unique_name"`
79 }
80
81 type ListOptions struct {
82         ClusterID          string                 `json:"cluster_id"`
83         Select             []string               `json:"select"`
84         Filters            []Filter               `json:"filters"`
85         Where              map[string]interface{} `json:"where"`
86         Limit              int64                  `json:"limit"`
87         Offset             int64                  `json:"offset"`
88         Order              []string               `json:"order"`
89         Distinct           bool                   `json:"distinct"`
90         Count              string                 `json:"count"`
91         IncludeTrash       bool                   `json:"include_trash"`
92         IncludeOldVersions bool                   `json:"include_old_versions"`
93         BypassFederation   bool                   `json:"bypass_federation"`
94         ForwardedFor       string                 `json:"forwarded_for,omitempty"`
95 }
96
97 type CreateOptions struct {
98         ClusterID        string                 `json:"cluster_id"`
99         EnsureUniqueName bool                   `json:"ensure_unique_name"`
100         Select           []string               `json:"select"`
101         Attrs            map[string]interface{} `json:"attrs"`
102 }
103
104 type UpdateOptions struct {
105         UUID             string                 `json:"uuid"`
106         Attrs            map[string]interface{} `json:"attrs"`
107         BypassFederation bool                   `json:"bypass_federation"`
108 }
109
110 type UpdateUUIDOptions struct {
111         UUID    string `json:"uuid"`
112         NewUUID string `json:"new_uuid"`
113 }
114
115 type UserActivateOptions struct {
116         UUID string `json:"uuid"`
117 }
118
119 type UserSetupOptions struct {
120         UUID                  string                 `json:"uuid,omitempty"`
121         Email                 string                 `json:"email,omitempty"`
122         OpenIDPrefix          string                 `json:"openid_prefix,omitempty"`
123         RepoName              string                 `json:"repo_name,omitempty"`
124         VMUUID                string                 `json:"vm_uuid,omitempty"`
125         SendNotificationEmail bool                   `json:"send_notification_email,omitempty"`
126         Attrs                 map[string]interface{} `json:"attrs"`
127 }
128
129 type UserMergeOptions struct {
130         NewUserUUID       string `json:"new_user_uuid,omitempty"`
131         OldUserUUID       string `json:"old_user_uuid,omitempty"`
132         NewOwnerUUID      string `json:"new_owner_uuid,omitempty"`
133         NewUserToken      string `json:"new_user_token,omitempty"`
134         RedirectToNewUser bool   `json:"redirect_to_new_user"`
135 }
136
137 type UserBatchUpdateOptions struct {
138         Updates map[string]map[string]interface{} `json:"updates"`
139 }
140
141 type UserBatchUpdateResponse struct{}
142
143 type DeleteOptions struct {
144         UUID string `json:"uuid"`
145 }
146
147 type LoginOptions struct {
148         ReturnTo string `json:"return_to"`        // On success, redirect to this target with api_token=xxx query param
149         Remote   string `json:"remote,omitempty"` // Salt token for remote Cluster ID
150         Code     string `json:"code,omitempty"`   // OAuth2 callback code
151         State    string `json:"state,omitempty"`  // OAuth2 callback state
152 }
153
154 type UserAuthenticateOptions struct {
155         Username string `json:"username,omitempty"` // PAM username
156         Password string `json:"password,omitempty"` // PAM password
157 }
158
159 type LogoutOptions struct {
160         ReturnTo string `json:"return_to"` // Redirect to this URL after logging out
161 }
162
163 type API interface {
164         ConfigGet(ctx context.Context) (json.RawMessage, error)
165         Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
166         Logout(ctx context.Context, options LogoutOptions) (LogoutResponse, error)
167         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
168         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
169         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
170         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
171         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
172         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
173         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
174         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
175         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
176         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
177         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
178         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
179         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
180         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
181         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
182         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
183         ContainerRequestCreate(ctx context.Context, options CreateOptions) (ContainerRequest, error)
184         ContainerRequestUpdate(ctx context.Context, options UpdateOptions) (ContainerRequest, error)
185         ContainerRequestGet(ctx context.Context, options GetOptions) (ContainerRequest, error)
186         ContainerRequestList(ctx context.Context, options ListOptions) (ContainerRequestList, error)
187         ContainerRequestDelete(ctx context.Context, options DeleteOptions) (ContainerRequest, error)
188         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
189         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
190         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
191         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
192         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
193         UserCreate(ctx context.Context, options CreateOptions) (User, error)
194         UserUpdate(ctx context.Context, options UpdateOptions) (User, error)
195         UserUpdateUUID(ctx context.Context, options UpdateUUIDOptions) (User, error)
196         UserMerge(ctx context.Context, options UserMergeOptions) (User, error)
197         UserActivate(ctx context.Context, options UserActivateOptions) (User, error)
198         UserSetup(ctx context.Context, options UserSetupOptions) (map[string]interface{}, error)
199         UserUnsetup(ctx context.Context, options GetOptions) (User, error)
200         UserGet(ctx context.Context, options GetOptions) (User, error)
201         UserGetCurrent(ctx context.Context, options GetOptions) (User, error)
202         UserGetSystem(ctx context.Context, options GetOptions) (User, error)
203         UserList(ctx context.Context, options ListOptions) (UserList, error)
204         UserDelete(ctx context.Context, options DeleteOptions) (User, error)
205         UserBatchUpdate(context.Context, UserBatchUpdateOptions) (UserList, error)
206         UserAuthenticate(ctx context.Context, options UserAuthenticateOptions) (APIClientAuthorization, error)
207         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
208 }