Merge branch '16263-logincluster-user-list-fix' refs #16263
[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         EndpointUserActivate                  = APIEndpoint{"POST", "arvados/v1/users/{uuid}/activate", ""}
45         EndpointUserCreate                    = APIEndpoint{"POST", "arvados/v1/users", "user"}
46         EndpointUserCurrent                   = APIEndpoint{"GET", "arvados/v1/users/current", ""}
47         EndpointUserDelete                    = APIEndpoint{"DELETE", "arvados/v1/users/{uuid}", ""}
48         EndpointUserGet                       = APIEndpoint{"GET", "arvados/v1/users/{uuid}", ""}
49         EndpointUserGetCurrent                = APIEndpoint{"GET", "arvados/v1/users/current", ""}
50         EndpointUserGetSystem                 = APIEndpoint{"GET", "arvados/v1/users/system", ""}
51         EndpointUserList                      = APIEndpoint{"GET", "arvados/v1/users", ""}
52         EndpointUserMerge                     = APIEndpoint{"POST", "arvados/v1/users/merge", ""}
53         EndpointUserSetup                     = APIEndpoint{"POST", "arvados/v1/users/setup", "user"}
54         EndpointUserSystem                    = APIEndpoint{"GET", "arvados/v1/users/system", ""}
55         EndpointUserUnsetup                   = APIEndpoint{"POST", "arvados/v1/users/{uuid}/unsetup", ""}
56         EndpointUserUpdate                    = APIEndpoint{"PATCH", "arvados/v1/users/{uuid}", "user"}
57         EndpointUserUpdateUUID                = APIEndpoint{"POST", "arvados/v1/users/{uuid}/update_uuid", ""}
58         EndpointUserBatchUpdate               = APIEndpoint{"PATCH", "arvados/v1/users/batch_update", ""}
59         EndpointUserAuthenticate              = APIEndpoint{"POST", "arvados/v1/users/authenticate", ""}
60         EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
61 )
62
63 type GetOptions struct {
64         UUID         string   `json:"uuid,omitempty"`
65         Select       []string `json:"select"`
66         IncludeTrash bool     `json:"include_trash"`
67         ForwardedFor string   `json:"forwarded_for,omitempty"`
68         Remote       string   `json:"remote,omitempty"`
69 }
70
71 type UntrashOptions struct {
72         UUID             string `json:"uuid"`
73         EnsureUniqueName bool   `json:"ensure_unique_name"`
74 }
75
76 type ListOptions struct {
77         ClusterID          string                 `json:"cluster_id"`
78         Select             []string               `json:"select"`
79         Filters            []Filter               `json:"filters"`
80         Where              map[string]interface{} `json:"where"`
81         Limit              int64                  `json:"limit"`
82         Offset             int64                  `json:"offset"`
83         Order              []string               `json:"order"`
84         Distinct           bool                   `json:"distinct"`
85         Count              string                 `json:"count"`
86         IncludeTrash       bool                   `json:"include_trash"`
87         IncludeOldVersions bool                   `json:"include_old_versions"`
88         BypassFederation   bool                   `json:"bypass_federation"`
89 }
90
91 type CreateOptions struct {
92         ClusterID        string                 `json:"cluster_id"`
93         EnsureUniqueName bool                   `json:"ensure_unique_name"`
94         Select           []string               `json:"select"`
95         Attrs            map[string]interface{} `json:"attrs"`
96 }
97
98 type UpdateOptions struct {
99         UUID             string                 `json:"uuid"`
100         Attrs            map[string]interface{} `json:"attrs"`
101         BypassFederation bool                   `json:"bypass_federation"`
102 }
103
104 type UpdateUUIDOptions struct {
105         UUID    string `json:"uuid"`
106         NewUUID string `json:"new_uuid"`
107 }
108
109 type UserActivateOptions struct {
110         UUID string `json:"uuid"`
111 }
112
113 type UserSetupOptions struct {
114         UUID                  string                 `json:"uuid,omitempty"`
115         Email                 string                 `json:"email,omitempty"`
116         OpenIDPrefix          string                 `json:"openid_prefix,omitempty"`
117         RepoName              string                 `json:"repo_name,omitempty"`
118         VMUUID                string                 `json:"vm_uuid,omitempty"`
119         SendNotificationEmail bool                   `json:"send_notification_email,omitempty"`
120         Attrs                 map[string]interface{} `json:"attrs"`
121 }
122
123 type UserMergeOptions struct {
124         NewUserUUID       string `json:"new_user_uuid,omitempty"`
125         OldUserUUID       string `json:"old_user_uuid,omitempty"`
126         NewOwnerUUID      string `json:"new_owner_uuid,omitempty"`
127         NewUserToken      string `json:"new_user_token,omitempty"`
128         RedirectToNewUser bool   `json:"redirect_to_new_user"`
129 }
130
131 type UserBatchUpdateOptions struct {
132         Updates map[string]map[string]interface{} `json:"updates"`
133 }
134
135 type UserBatchUpdateResponse struct{}
136
137 type DeleteOptions struct {
138         UUID string `json:"uuid"`
139 }
140
141 type LoginOptions struct {
142         ReturnTo string `json:"return_to"`        // On success, redirect to this target with api_token=xxx query param
143         Remote   string `json:"remote,omitempty"` // Salt token for remote Cluster ID
144         Code     string `json:"code,omitempty"`   // OAuth2 callback code
145         State    string `json:"state,omitempty"`  // OAuth2 callback state
146 }
147
148 type UserAuthenticateOptions struct {
149         Username string `json:"username,omitempty"` // PAM username
150         Password string `json:"password,omitempty"` // PAM password
151 }
152
153 type LogoutOptions struct {
154         ReturnTo string `json:"return_to"` // Redirect to this URL after logging out
155 }
156
157 type API interface {
158         ConfigGet(ctx context.Context) (json.RawMessage, error)
159         Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
160         Logout(ctx context.Context, options LogoutOptions) (LogoutResponse, error)
161         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
162         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
163         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
164         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
165         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
166         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
167         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
168         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
169         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
170         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
171         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
172         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
173         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
174         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
175         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
176         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
177         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
178         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
179         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
180         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
181         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
182         UserCreate(ctx context.Context, options CreateOptions) (User, error)
183         UserUpdate(ctx context.Context, options UpdateOptions) (User, error)
184         UserUpdateUUID(ctx context.Context, options UpdateUUIDOptions) (User, error)
185         UserMerge(ctx context.Context, options UserMergeOptions) (User, error)
186         UserActivate(ctx context.Context, options UserActivateOptions) (User, error)
187         UserSetup(ctx context.Context, options UserSetupOptions) (map[string]interface{}, error)
188         UserUnsetup(ctx context.Context, options GetOptions) (User, error)
189         UserGet(ctx context.Context, options GetOptions) (User, error)
190         UserGetCurrent(ctx context.Context, options GetOptions) (User, error)
191         UserGetSystem(ctx context.Context, options GetOptions) (User, error)
192         UserList(ctx context.Context, options ListOptions) (UserList, error)
193         UserDelete(ctx context.Context, options DeleteOptions) (User, error)
194         UserBatchUpdate(context.Context, UserBatchUpdateOptions) (UserList, error)
195         UserAuthenticate(ctx context.Context, options UserAuthenticateOptions) (APIClientAuthorization, error)
196         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
197 }