Bump loofah from 2.2.3 to 2.3.1 in /apps/workbench
[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         EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
44 )
45
46 type GetOptions struct {
47         UUID         string   `json:"uuid"`
48         Select       []string `json:"select"`
49         IncludeTrash bool     `json:"include_trash"`
50 }
51
52 type UntrashOptions struct {
53         UUID             string `json:"uuid"`
54         EnsureUniqueName bool   `json:"ensure_unique_name"`
55 }
56
57 type ListOptions struct {
58         ClusterID          string                 `json:"cluster_id"`
59         Select             []string               `json:"select"`
60         Filters            []Filter               `json:"filters"`
61         Where              map[string]interface{} `json:"where"`
62         Limit              int                    `json:"limit"`
63         Offset             int                    `json:"offset"`
64         Order              []string               `json:"order"`
65         Distinct           bool                   `json:"distinct"`
66         Count              string                 `json:"count"`
67         IncludeTrash       bool                   `json:"include_trash"`
68         IncludeOldVersions bool                   `json:"include_old_versions"`
69 }
70
71 type CreateOptions struct {
72         ClusterID        string                 `json:"cluster_id"`
73         EnsureUniqueName bool                   `json:"ensure_unique_name"`
74         Select           []string               `json:"select"`
75         Attrs            map[string]interface{} `json:"attrs"`
76 }
77
78 type UpdateOptions struct {
79         UUID  string                 `json:"uuid"`
80         Attrs map[string]interface{} `json:"attrs"`
81 }
82
83 type DeleteOptions struct {
84         UUID string `json:"uuid"`
85 }
86
87 type LoginOptions struct {
88         ReturnTo string `json:"return_to"`        // On success, redirect to this target with api_token=xxx query param
89         Remote   string `json:"remote,omitempty"` // Salt token for remote Cluster ID
90         Code     string `json:"code,omitempty"`   // OAuth2 callback code
91         State    string `json:"state,omitempty"`  // OAuth2 callback state
92 }
93
94 type API interface {
95         ConfigGet(ctx context.Context) (json.RawMessage, error)
96         Login(ctx context.Context, options LoginOptions) (LoginResponse, error)
97         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
98         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
99         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
100         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
101         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
102         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
103         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
104         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
105         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
106         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
107         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
108         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
109         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
110         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
111         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
112         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
113         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
114         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
115         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
116         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
117         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
118         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
119 }