-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_variables.go
41 lines (33 loc) · 1.22 KB
/
env_variables.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
package api
import (
"context"
"encoding/json"
"fmt"
"gopkg.in/nullstone-io/go-api-client.v0/response"
"gopkg.in/nullstone-io/go-api-client.v0/types"
"net/http"
)
type EnvVariables struct {
Client *Client
}
func (ev EnvVariables) basePath(stackId, blockId, envId int64) string {
return fmt.Sprintf("/orgs/%s/stacks/%d/blocks/%d/envs/%d/env-variables", ev.Client.Config.OrgName, stackId, blockId, envId)
}
func (ev EnvVariables) envVarPath(stackId, blockId, envId int64, key string) string {
return fmt.Sprintf("/orgs/%s/stacks/%d/blocks/%d/envs/%d/env-variables/%s", ev.Client.Config.OrgName, stackId, blockId, envId, key)
}
func (ev EnvVariables) Create(ctx context.Context, stackId, blockId, envId int64, input []types.EnvVariableInput) error {
raw, _ := json.Marshal(input)
res, err := ev.Client.Do(ctx, http.MethodPost, ev.basePath(stackId, blockId, envId), nil, nil, json.RawMessage(raw))
if err != nil {
return err
}
return response.Verify(res)
}
func (ev EnvVariables) Destroy(ctx context.Context, stackId, blockId, envId int64, key string) error {
res, err := ev.Client.Do(ctx, http.MethodDelete, ev.envVarPath(stackId, blockId, envId, key), nil, nil, nil)
if err != nil {
return err
}
return response.Verify(res)
}