-
Notifications
You must be signed in to change notification settings - Fork 250
/
tcpurgecache.go
239 lines (223 loc) · 7.18 KB
/
tcpurgecache.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// The following code is AUTO-GENERATED. Please DO NOT edit.
// To update this generated code, run `go generate` in the
// clients/client-go/codegenerator/model subdirectory of the
// taskcluster git repository.
// This package was generated from the reference schema of
// the PurgeCache service, which is also published here:
//
// * ${TASKCLUSTER_ROOT_URL}/references/purge-cache/v1/api.json
//
// where ${TASKCLUSTER_ROOT_URL} points to the root URL of
// your taskcluster deployment.
// The purge-cache service is responsible for tracking cache-purge requests.
//
// User create purge requests for specific caches on specific workers, and
// these requests are timestamped. Workers consult the service before
// starting a new task, and purge any caches older than the timestamp.
//
// See:
//
// # How to use this package
//
// First create a PurgeCache object:
//
// purgeCache := tcpurgecache.New(nil)
//
// and then call one or more of purgeCache's methods, e.g.:
//
// err := purgeCache.Ping(.....)
//
// handling any errors...
//
// if err != nil {
// // handle error...
// }
//
// # Taskcluster Schema
//
// The source code of this go package was auto-generated from the API definition at
// <rootUrl>/references/purge-cache/v1/api.json together with the input and output schemas it references,
package tcpurgecache
import (
"net/url"
"time"
tcclient "github.com/taskcluster/taskcluster/v61/clients/client-go"
)
type PurgeCache tcclient.Client
// New returns a PurgeCache client, configured to run against production. Pass in
// nil credentials to create a client without authentication. The
// returned client is mutable, so returned settings can be altered.
//
// purgeCache := tcpurgecache.New(
// nil, // client without authentication
// "http://localhost:1234/my/taskcluster", // taskcluster hosted at this root URL on local machine
// )
// err := purgeCache.Ping(.....) // for example, call the Ping(.....) API endpoint (described further down)...
// if err != nil {
// // handle errors...
// }
func New(credentials *tcclient.Credentials, rootURL string) *PurgeCache {
return &PurgeCache{
Credentials: credentials,
RootURL: rootURL,
ServiceName: "purge-cache",
APIVersion: "v1",
Authenticate: credentials != nil,
}
}
// NewFromEnv returns a *PurgeCache configured from environment variables.
//
// The root URL is taken from TASKCLUSTER_PROXY_URL if set to a non-empty
// string, otherwise from TASKCLUSTER_ROOT_URL if set, otherwise the empty
// string.
//
// The credentials are taken from environment variables:
//
// TASKCLUSTER_CLIENT_ID
// TASKCLUSTER_ACCESS_TOKEN
// TASKCLUSTER_CERTIFICATE
//
// If TASKCLUSTER_CLIENT_ID is empty/unset, authentication will be
// disabled.
func NewFromEnv() *PurgeCache {
c := tcclient.CredentialsFromEnvVars()
rootURL := tcclient.RootURLFromEnvVars()
return &PurgeCache{
Credentials: c,
RootURL: rootURL,
ServiceName: "purge-cache",
APIVersion: "v1",
Authenticate: c.ClientID != "",
}
}
// Respond without doing anything.
// This endpoint is used to check that the service is up.
//
// See #ping
func (purgeCache *PurgeCache) Ping() error {
cd := tcclient.Client(*purgeCache)
_, _, err := (&cd).APICall(nil, "GET", "/ping", nil, nil)
return err
}
// Respond without doing anything.
// This endpoint is used to check that the service is up.
//
// See #lbheartbeat
func (purgeCache *PurgeCache) Lbheartbeat() error {
cd := tcclient.Client(*purgeCache)
_, _, err := (&cd).APICall(nil, "GET", "/__lbheartbeat__", nil, nil)
return err
}
// Respond with the JSON version object.
// https://github.com/mozilla-services/Dockerflow/blob/main/docs/version_object.md
//
// See #version
func (purgeCache *PurgeCache) Version() error {
cd := tcclient.Client(*purgeCache)
_, _, err := (&cd).APICall(nil, "GET", "/__version__", nil, nil)
return err
}
// Publish a request to purge caches named `cacheName` with
// on `workerPoolId` workers.
//
// If such a request already exists, its `before` timestamp is updated to
// the current time.
//
// Required scopes:
//
// purge-cache:<workerPoolId>:<cacheName>
//
// See #purgeCache
func (purgeCache *PurgeCache) PurgeCache(workerPoolId string, payload *PurgeCacheRequest) error {
cd := tcclient.Client(*purgeCache)
_, _, err := (&cd).APICall(payload, "POST", "/purge-cache/"+url.QueryEscape(workerPoolId), nil, nil)
return err
}
// View all active purge requests.
//
// This is useful mostly for administors to view
// the set of open purge requests. It should not
// be used by workers. They should use the purgeRequests
// endpoint that is specific to their workerType and
// provisionerId.
//
// Required scopes:
//
// purge-cache:all-purge-requests
//
// See #allPurgeRequests
func (purgeCache *PurgeCache) AllPurgeRequests(continuationToken, limit string) (*OpenAllPurgeRequestsList, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*purgeCache)
responseObject, _, err := (&cd).APICall(nil, "GET", "/purge-cache/list", new(OpenAllPurgeRequestsList), v)
return responseObject.(*OpenAllPurgeRequestsList), err
}
// Returns a signed URL for AllPurgeRequests, valid for the specified duration.
//
// Required scopes:
//
// purge-cache:all-purge-requests
//
// See AllPurgeRequests for more details.
func (purgeCache *PurgeCache) AllPurgeRequests_SignedURL(continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*purgeCache)
return (&cd).SignedURL("/purge-cache/list", v, duration)
}
// List the caches for this `workerPoolId` that should to be
// purged if they are from before the time given in the response.
//
// This is intended to be used by workers to determine which caches to purge.
//
// Required scopes:
//
// purge-cache:purge-requests::<workerPoolId>
//
// See #purgeRequests
func (purgeCache *PurgeCache) PurgeRequests(workerPoolId, since string) (*OpenPurgeRequestList, error) {
v := url.Values{}
if since != "" {
v.Add("since", since)
}
cd := tcclient.Client(*purgeCache)
responseObject, _, err := (&cd).APICall(nil, "GET", "/purge-cache/"+url.QueryEscape(workerPoolId), new(OpenPurgeRequestList), v)
return responseObject.(*OpenPurgeRequestList), err
}
// Returns a signed URL for PurgeRequests, valid for the specified duration.
//
// Required scopes:
//
// purge-cache:purge-requests::<workerPoolId>
//
// See PurgeRequests for more details.
func (purgeCache *PurgeCache) PurgeRequests_SignedURL(workerPoolId, since string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if since != "" {
v.Add("since", since)
}
cd := tcclient.Client(*purgeCache)
return (&cd).SignedURL("/purge-cache/"+url.QueryEscape(workerPoolId), v, duration)
}
// Respond with a service heartbeat.
//
// This endpoint is used to check on backing services this service
// depends on.
//
// See #heartbeat
func (purgeCache *PurgeCache) Heartbeat() error {
cd := tcclient.Client(*purgeCache)
_, _, err := (&cd).APICall(nil, "GET", "/__heartbeat__", nil, nil)
return err
}