-
Notifications
You must be signed in to change notification settings - Fork 2
/
artifact.go
98 lines (79 loc) · 2.2 KB
/
artifact.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package client
import (
"bytes"
"encoding/json"
"fmt"
)
//
func (c *Client) CacheArtifact(image_url string) error {
path := "artifacts"
r := &struct {
URL string `json:"url"`
}{
URL: image_url,
}
req, err := json.Marshal(r)
if err != nil {
return fmt.Errorf("Unable to marshal data: %v", err)
}
err = c.doRequestJSON(path, "POST", *bytes.NewBuffer(req), nil)
return err
}
type Artifact struct {
UUID string
Type string `json:"artifact_type"`
State string
SourceURL string `json:"source_url"`
Version int
MaxVersions int `json:"max_versions"`
MostRecentIndex int `json:"index"`
Blobs map[int]Blob
}
func (c *Client) GetArtifact(uuid string) (Artifact, error) {
var artifact Artifact
path := "artifacts/" + uuid
err := c.doRequestJSON(path, "GET", bytes.Buffer{}, &artifact)
return artifact, err
}
func (c *Client) GetArtifacts(node string) ([]Artifact, error) {
var artifacts []Artifact
path := "artifacts"
r := &struct {
Node string `json:"node"`
}{
Node: node,
}
req, err := json.Marshal(r)
if err != nil {
return []Artifact{}, fmt.Errorf("Unable to marshal data: %v", err)
}
err = c.doRequestJSON(path, "GET", *bytes.NewBuffer(req), &artifacts)
return artifacts, err
}
func (c *Client) GetArtifactEvents(uuid string) ([]Event, error) {
var events []Event
path := "artifacts/" + uuid + "/events"
err := c.doRequestJSON(path, "GET", bytes.Buffer{}, &events)
return events, err
}
func (c *Client) GetArtifactVersions(uuid string) ([]Blob, error) {
var blobs []Blob
path := "artifacts/" + uuid + "/versions"
err := c.doRequestJSON(path, "GET", bytes.Buffer{}, &blobs)
return blobs, err
}
/***
Missing API calls
def set_artifact_max_versions(self, artifact_uuid, max_versions):
r = self._request_url('POST',
'/artifacts/' + artifact_uuid + '/versions',
data={'max_versions': max_versions})
return r.json()
def delete_artifact(self, artifact_uuid):
r = self._request_url('DELETE', '/artifacts/' + artifact_uuid)
return r.json()
def delete_artifact_version(self, artifact_uuid, version_id):
r = self._request_url('DELETE', '/artifacts/' + artifact_uuid +
'/versions/' + str(version_id))
return r.json()
***/