This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathregistries.go
More file actions
60 lines (51 loc) · 1.87 KB
/
registries.go
File metadata and controls
60 lines (51 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package coder
import (
"context"
"net/http"
"net/url"
"time"
)
// Registry defines an image registry configuration.
type Registry struct {
ID string `json:"id"`
OrganizationID string `json:"organization_id"`
FriendlyName string `json:"friendly_name"`
Registry string `json:"registry"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Registries fetches all registries in an organization.
func (c *DefaultClient) Registries(ctx context.Context, orgID string) ([]Registry, error) {
var (
r []Registry
query = url.Values{}
)
query.Set("org", orgID)
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/registries", nil, &r, withQueryParams(query)); err != nil {
return nil, err
}
return r, nil
}
// RegistryByID fetches a registry resource by its ID.
func (c *DefaultClient) RegistryByID(ctx context.Context, registryID string) (*Registry, error) {
var r Registry
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/registries/"+registryID, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// UpdateRegistryReq defines the requests parameters for a partial update of a registry resource.
type UpdateRegistryReq struct {
Registry *string `json:"registry"`
FriendlyName *string `json:"friendly_name"`
Username *string `json:"username"`
Password *string `json:"password"`
}
// UpdateRegistry applies a partial update to a registry resource.
func (c *DefaultClient) UpdateRegistry(ctx context.Context, registryID string, req UpdateRegistryReq) error {
return c.requestBody(ctx, http.MethodPatch, "/api/v0/registries/"+registryID, req, nil)
}
// DeleteRegistry deletes a registry resource by its ID.
func (c *DefaultClient) DeleteRegistry(ctx context.Context, registryID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/v0/registries/"+registryID, nil, nil)
}