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 pathtags.go
More file actions
72 lines (62 loc) · 2.32 KB
/
tags.go
File metadata and controls
72 lines (62 loc) · 2.32 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
61
62
63
64
65
66
67
68
69
70
71
72
package coder
import (
"context"
"net/http"
"time"
)
// ImageTag is a Docker image tag.
type ImageTag struct {
ImageID string `json:"image_id" table:"-"`
Tag string `json:"tag" table:"Tag"`
LatestHash string `json:"latest_hash" table:"-"`
HashLastUpdatedAt time.Time `json:"hash_last_updated_at" table:"-"`
OSRelease *OSRelease `json:"os_release" table:"OS"`
Workspaces []*Workspace `json:"workspaces" table:"-"`
UpdatedAt time.Time `json:"updated_at" table:"UpdatedAt"`
CreatedAt time.Time `json:"created_at" table:"-"`
}
func (i ImageTag) String() string {
return i.Tag
}
// OSRelease is the marshalled /etc/os-release file.
type OSRelease struct {
ID string `json:"id"`
PrettyName string `json:"pretty_name"`
HomeURL string `json:"home_url"`
}
func (o OSRelease) String() string {
return o.PrettyName
}
// CreateImageTagReq defines the request parameters for creating a new image tag.
type CreateImageTagReq struct {
Tag string `json:"tag"`
Default bool `json:"default"`
}
// CreateImageTag creates a new image tag resource.
func (c *DefaultClient) CreateImageTag(ctx context.Context, imageID string, req CreateImageTagReq) (*ImageTag, error) {
var tag ImageTag
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/images/"+imageID+"/tags", req, tag); err != nil {
return nil, err
}
return &tag, nil
}
// DeleteImageTag deletes an image tag resource.
func (c *DefaultClient) DeleteImageTag(ctx context.Context, imageID, tag string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/v0/images/"+imageID+"/tags/"+tag, nil, nil)
}
// ImageTags fetch all image tags.
func (c *DefaultClient) ImageTags(ctx context.Context, imageID string) ([]ImageTag, error) {
var tags []ImageTag
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags", nil, &tags); err != nil {
return nil, err
}
return tags, nil
}
// ImageTagByID fetch an image tag by ID.
func (c *DefaultClient) ImageTagByID(ctx context.Context, imageID, tagID string) (*ImageTag, error) {
var tag ImageTag
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
return nil, err
}
return &tag, nil
}