14287: Merge branch 'master'
[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 "context"
8
9 type APIEndpoint struct {
10         Method string
11         Path   string
12         // "new attributes" key for create/update requests
13         AttrsKey string
14 }
15
16 var (
17         EndpointCollectionCreate              = APIEndpoint{"POST", "arvados/v1/collections", "collection"}
18         EndpointCollectionUpdate              = APIEndpoint{"PATCH", "arvados/v1/collections/:uuid", "collection"}
19         EndpointCollectionGet                 = APIEndpoint{"GET", "arvados/v1/collections/:uuid", ""}
20         EndpointCollectionList                = APIEndpoint{"GET", "arvados/v1/collections", ""}
21         EndpointCollectionProvenance          = APIEndpoint{"GET", "arvados/v1/collections/:uuid/provenance", ""}
22         EndpointCollectionUsedBy              = APIEndpoint{"GET", "arvados/v1/collections/:uuid/used_by", ""}
23         EndpointCollectionDelete              = APIEndpoint{"DELETE", "arvados/v1/collections/:uuid", ""}
24         EndpointCollectionTrash               = APIEndpoint{"POST", "arvados/v1/collections/:uuid/trash", ""}
25         EndpointCollectionUntrash             = APIEndpoint{"POST", "arvados/v1/collections/:uuid/untrash", ""}
26         EndpointSpecimenCreate                = APIEndpoint{"POST", "arvados/v1/specimens", "specimen"}
27         EndpointSpecimenUpdate                = APIEndpoint{"PATCH", "arvados/v1/specimens/:uuid", "specimen"}
28         EndpointSpecimenGet                   = APIEndpoint{"GET", "arvados/v1/specimens/:uuid", ""}
29         EndpointSpecimenList                  = APIEndpoint{"GET", "arvados/v1/specimens", ""}
30         EndpointSpecimenDelete                = APIEndpoint{"DELETE", "arvados/v1/specimens/:uuid", ""}
31         EndpointContainerCreate               = APIEndpoint{"POST", "arvados/v1/containers", "container"}
32         EndpointContainerUpdate               = APIEndpoint{"PATCH", "arvados/v1/containers/:uuid", "container"}
33         EndpointContainerGet                  = APIEndpoint{"GET", "arvados/v1/containers/:uuid", ""}
34         EndpointContainerList                 = APIEndpoint{"GET", "arvados/v1/containers", ""}
35         EndpointContainerDelete               = APIEndpoint{"DELETE", "arvados/v1/containers/:uuid", ""}
36         EndpointContainerLock                 = APIEndpoint{"POST", "arvados/v1/containers/:uuid/lock", ""}
37         EndpointContainerUnlock               = APIEndpoint{"POST", "arvados/v1/containers/:uuid/unlock", ""}
38         EndpointAPIClientAuthorizationCurrent = APIEndpoint{"GET", "arvados/v1/api_client_authorizations/current", ""}
39 )
40
41 type GetOptions struct {
42         UUID         string   `json:"uuid"`
43         Select       []string `json:"select"`
44         IncludeTrash bool     `json:"include_trash"`
45 }
46
47 type UntrashOptions struct {
48         UUID             string `json:"uuid"`
49         EnsureUniqueName bool   `json:"ensure_unique_name"`
50 }
51
52 type ListOptions struct {
53         ClusterID          string                 `json:"cluster_id"`
54         Select             []string               `json:"select"`
55         Filters            []Filter               `json:"filters"`
56         Where              map[string]interface{} `json:"where"`
57         Limit              int                    `json:"limit"`
58         Offset             int                    `json:"offset"`
59         Order              []string               `json:"order"`
60         Distinct           bool                   `json:"distinct"`
61         Count              string                 `json:"count"`
62         IncludeTrash       bool                   `json:"include_trash"`
63         IncludeOldVersions bool                   `json:"include_old_versions"`
64 }
65
66 type CreateOptions struct {
67         ClusterID        string                 `json:"cluster_id"`
68         EnsureUniqueName bool                   `json:"ensure_unique_name"`
69         Select           []string               `json:"select"`
70         Attrs            map[string]interface{} `json:"attrs"`
71 }
72
73 type UpdateOptions struct {
74         UUID  string                 `json:"uuid"`
75         Attrs map[string]interface{} `json:"attrs"`
76 }
77
78 type DeleteOptions struct {
79         UUID string `json:"uuid"`
80 }
81
82 type API interface {
83         CollectionCreate(ctx context.Context, options CreateOptions) (Collection, error)
84         CollectionUpdate(ctx context.Context, options UpdateOptions) (Collection, error)
85         CollectionGet(ctx context.Context, options GetOptions) (Collection, error)
86         CollectionList(ctx context.Context, options ListOptions) (CollectionList, error)
87         CollectionProvenance(ctx context.Context, options GetOptions) (map[string]interface{}, error)
88         CollectionUsedBy(ctx context.Context, options GetOptions) (map[string]interface{}, error)
89         CollectionDelete(ctx context.Context, options DeleteOptions) (Collection, error)
90         CollectionTrash(ctx context.Context, options DeleteOptions) (Collection, error)
91         CollectionUntrash(ctx context.Context, options UntrashOptions) (Collection, error)
92         ContainerCreate(ctx context.Context, options CreateOptions) (Container, error)
93         ContainerUpdate(ctx context.Context, options UpdateOptions) (Container, error)
94         ContainerGet(ctx context.Context, options GetOptions) (Container, error)
95         ContainerList(ctx context.Context, options ListOptions) (ContainerList, error)
96         ContainerDelete(ctx context.Context, options DeleteOptions) (Container, error)
97         ContainerLock(ctx context.Context, options GetOptions) (Container, error)
98         ContainerUnlock(ctx context.Context, options GetOptions) (Container, error)
99         SpecimenCreate(ctx context.Context, options CreateOptions) (Specimen, error)
100         SpecimenUpdate(ctx context.Context, options UpdateOptions) (Specimen, error)
101         SpecimenGet(ctx context.Context, options GetOptions) (Specimen, error)
102         SpecimenList(ctx context.Context, options ListOptions) (SpecimenList, error)
103         SpecimenDelete(ctx context.Context, options DeleteOptions) (Specimen, error)
104         APIClientAuthorizationCurrent(ctx context.Context, options GetOptions) (APIClientAuthorization, error)
105 }