/
functions.go
344 lines (281 loc) · 11 KB
/
functions.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package appwrite
import (
"strings"
)
// Functions service
type Functions struct {
client Client
}
func NewFunctions(clt Client) *Functions {
return &Functions{
client: clt,
}
}
// List get a list of all the project's functions. You can use the query
// params to filter your results.
func (srv *Functions) List(Queries []interface{}, Search string) (*ClientResponse, error) {
path := "/functions"
params := map[string]interface{}{
"queries": Queries,
"search": Search,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// Create create a new function. You can pass a list of
// [permissions](/docs/permissions) to allow different project users or team
// with access to execute the function using the client API.
func (srv *Functions) Create(FunctionId string, Name string, Execute []interface{}, Runtime string, Events []interface{}, Schedule string, Timeout int, Enabled bool) (*ClientResponse, error) {
path := "/functions"
params := map[string]interface{}{
"functionId": FunctionId,
"name": Name,
"execute": Execute,
"runtime": Runtime,
"events": Events,
"schedule": Schedule,
"timeout": Timeout,
"enabled": Enabled,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// ListRuntimes get a list of all runtimes that are currently active on your
// instance.
func (srv *Functions) ListRuntimes() (*ClientResponse, error) {
path := "/functions/runtimes"
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// Get get a function by its unique ID.
func (srv *Functions) Get(FunctionId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// Update update function by its unique ID.
func (srv *Functions) Update(FunctionId string, Name string, Execute []interface{}, Events []interface{}, Schedule string, Timeout int, Enabled bool) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}")
params := map[string]interface{}{
"name": Name,
"execute": Execute,
"events": Events,
"schedule": Schedule,
"timeout": Timeout,
"enabled": Enabled,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PUT", path, headers, params)
}
// Delete delete a function by its unique ID.
func (srv *Functions) Delete(FunctionId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("DELETE", path, headers, params)
}
// ListDeployments get a list of all the project's code deployments. You can
// use the query params to filter your results.
func (srv *Functions) ListDeployments(FunctionId string, Queries []interface{}, Search string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/deployments")
params := map[string]interface{}{
"queries": Queries,
"search": Search,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// CreateDeployment create a new function code deployment. Use this endpoint
// to upload a new version of your code function. To execute your newly
// uploaded code, you'll need to update the function's deployment to use your
// new deployment UID.
//
// This endpoint accepts a tar.gz file compressed with your code. Make sure to
// include any dependencies your code has within the compressed file. You can
// learn more about code packaging in the [Appwrite Cloud Functions
// tutorial](/docs/functions).
//
// Use the "command" param to set the entry point used to execute your code.
func (srv *Functions) CreateDeployment(FunctionId string, Entrypoint string, Code string, Activate bool) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/deployments")
params := map[string]interface{}{
"entrypoint": Entrypoint,
"code": Code,
"activate": Activate,
}
headers := map[string]interface{}{
"content-type": "multipart/form-data",
}
return srv.client.Call("POST", path, headers, params)
}
// GetDeployment get a code deployment by its unique ID.
func (srv *Functions) GetDeployment(FunctionId string, DeploymentId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// UpdateDeployment update the function code deployment ID using the unique
// function ID. Use this endpoint to switch the code deployment that should be
// executed by the execution endpoint.
func (srv *Functions) UpdateDeployment(FunctionId string, DeploymentId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PATCH", path, headers, params)
}
// DeleteDeployment delete a code deployment by its unique ID.
func (srv *Functions) DeleteDeployment(FunctionId string, DeploymentId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("DELETE", path, headers, params)
}
// CreateBuild
func (srv *Functions) CreateBuild(FunctionId string, DeploymentId string, BuildId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId, "{buildId}", BuildId)
path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// ListExecutions get a list of all the current user function execution logs.
// You can use the query params to filter your results.
func (srv *Functions) ListExecutions(FunctionId string, Queries []interface{}, Search string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/executions")
params := map[string]interface{}{
"queries": Queries,
"search": Search,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// CreateExecution trigger a function execution. The returned object will
// return you the current execution status. You can ping the `Get Execution`
// endpoint to get updates on the current execution status. Once this endpoint
// is called, your function execution process will start asynchronously.
func (srv *Functions) CreateExecution(FunctionId string, Data string, Async bool) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/executions")
params := map[string]interface{}{
"data": Data,
"async": Async,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// GetExecution get a function execution log by its unique ID.
func (srv *Functions) GetExecution(FunctionId string, ExecutionId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{executionId}", ExecutionId)
path := r.Replace("/functions/{functionId}/executions/{executionId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// ListVariables get a list of all variables of a specific function.
func (srv *Functions) ListVariables(FunctionId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/variables")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// CreateVariable create a new function variable. These variables can be
// accessed within function in the `env` object under the request variable.
func (srv *Functions) CreateVariable(FunctionId string, Key string, Value string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId)
path := r.Replace("/functions/{functionId}/variables")
params := map[string]interface{}{
"key": Key,
"value": Value,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("POST", path, headers, params)
}
// GetVariable get a variable by its unique ID.
func (srv *Functions) GetVariable(FunctionId string, VariableId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId)
path := r.Replace("/functions/{functionId}/variables/{variableId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("GET", path, headers, params)
}
// UpdateVariable update variable by its unique ID.
func (srv *Functions) UpdateVariable(FunctionId string, VariableId string, Key string, Value string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId)
path := r.Replace("/functions/{functionId}/variables/{variableId}")
params := map[string]interface{}{
"key": Key,
"value": Value,
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("PUT", path, headers, params)
}
// DeleteVariable delete a variable by its unique ID.
func (srv *Functions) DeleteVariable(FunctionId string, VariableId string) (*ClientResponse, error) {
r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId)
path := r.Replace("/functions/{functionId}/variables/{variableId}")
params := map[string]interface{}{
}
headers := map[string]interface{}{
"content-type": "application/json",
}
return srv.client.Call("DELETE", path, headers, params)
}