15781: Adds test proving that 'contains' does case-sensitive matching.
[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 }
66
67 type UntrashOptions struct {
68         UUID             string `json:"uuid"`
69         EnsureUniqueName bool   `json:"ensure_unique_name"`
70 }
71
72 type ListOptions struct {
73         ClusterID          string                 `json:"cluster_id"`
74         Select             []string               `json:"select"`
75         Filters            []Filter               `json:"filters"`
76         Where              map[string]interface{} `json:"where"`
77         Limit              int                    `json:"limit"`
78         Offset             int                    `json:"offset"`
79         Order              []string               `json:"order"`
80         Distinct           bool                   `json:"distinct"`
81         Count              string                 `json:"count"`
82         IncludeTrash       bool                   `json:"include_trash"`
83         IncludeOldVersions bool                   `json:"include_old_versions"`
84 }
85
86 type CreateOptions struct {
87         ClusterID        string                 `json:"cluster_id"`
88         EnsureUniqueName bool                   `json:"ensure_unique_name"`
89         Select           []string               `json:"select"`
90         Attrs            map[string]interface{} `json:"attrs"`
91 }
92
93 type UpdateOptions struct {
94         UUID  string                 `json:"uuid"`
95         Attrs map[string]interface{} `json:"attrs"`
96 }
97
98 type UpdateUUIDOptions struct {
99         UUID    string `json:"uuid"`
100         NewUUID string `json:"new_uuid"`
101 }
102
103 type UserActivateOptions struct {
104         UUID string `json:"uuid"`
105 }
106
107 type UserSetupOptions struct {
108         UUID                  string                 `json:"uuid,omitempty"`
109         Email                 string                 `json:"email,omitempty"`
110         OpenIDPrefix          string                 `json:"openid_prefix,omitempty"`
111         RepoName              string                 `json:"repo_name,omitempty"`
112         VMUUID                string                 `json:"vm_uuid,omitempty"`
113         SendNotificationEmail bool                   `json:"send_notification_email,omitempty"`
114         Attrs                 map[string]interface{} `json:"attrs"`
115 }
116
117 type UserMergeOptions struct {
118         NewUserUUID       string `json:"new_user_uuid,omitempty"`
119         OldUserUUID       string `json:"old_user_uuid,omitempty"`
120         NewOwnerUUID      string `json:"new_owner_uuid,omitempty"`
121         NewUserToken      string `json:"new_user_token,omitempty"`
122         RedirectToNewUser bool   `json:"redirect_to_new_user"`
123 }
124
125 type UserBatchUpdateOptions struct {
126         Updates map[string]map[string]interface{} `json:"updates"`
127 }
128
129 type UserBatchUpdateResponse struct{}
130
131 type DeleteOptions struct {
132         UUID string `json:"uuid"`
133 }
134
135 type LoginOptions struct {
136         ReturnTo string `json:"return_to"`        // On success, redirect to this target with api_token=xxx query param
137         Remote   string `json:"remote,omitempty"` // Salt token for remote Cluster ID
138         Code     string `json:"code,omitempty"`   // OAuth2 callback code
139         State    string `json:"state,omitempty"`  // OAuth2 callback state
140 }
141
142 type API interface {
143         ConfigGet(ctx context.Context) (json.RawMessage, error)
144         Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
145         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
146         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
147         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
148         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
149         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
150         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
151         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
152         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
153         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
154         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
155         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
156         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
157         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
158         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
159         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
160         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
161         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
162         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
163         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
164         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
165         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
166         UserCreate(ctx context.Context, options CreateOptions) (User, error)
167         UserUpdate(ctx context.Context, options UpdateOptions) (User, error)
168         UserUpdateUUID(ctx context.Context, options UpdateUUIDOptions) (User, error)
169         UserMerge(ctx context.Context, options UserMergeOptions) (User, error)
170         UserActivate(ctx context.Context, options UserActivateOptions) (User, error)
171         UserSetup(ctx context.Context, options UserSetupOptions) (map[string]interface{}, error)
172         UserUnsetup(ctx context.Context, options GetOptions) (User, error)
173         UserGet(ctx context.Context, options GetOptions) (User, error)
174         UserGetCurrent(ctx context.Context, options GetOptions) (User, error)
175         UserGetSystem(ctx context.Context, options GetOptions) (User, error)
176         UserList(ctx context.Context, options ListOptions) (UserList, error)
177         UserDelete(ctx context.Context, options DeleteOptions) (User, error)
178         UserBatchUpdate(context.Context, UserBatchUpdateOptions) (UserList, error)
179         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
180 }