/
variables.go
111 lines (90 loc) · 2.68 KB
/
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
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
package variables
import (
"context"
"go.uber.org/zap"
"github.com/aziontech/azion-cli/pkg/logger"
"github.com/aziontech/azion-cli/utils"
)
func (c *Client) List(ctx context.Context) ([]Response, error) {
logger.Debug("List Environment Variables")
resp, httpResp, err := c.apiClient.VariablesAPI.ApiVariablesList(ctx).Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while listing variables", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
var result []Response
for i := range resp {
result = append(result, &resp[i])
}
return result, nil
}
func (c *Client) Delete(ctx context.Context, id string) error {
logger.Debug("Delete Environment Variable")
req := c.apiClient.VariablesAPI.ApiVariablesDestroy(ctx, id)
httpResp, err := req.Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while deleting a variables", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return err
}
}
return utils.ErrorPerStatusCode(httpResp, err)
}
return nil
}
func (c *Client) Update(ctx context.Context, req *Request) (Response, error) {
logger.Debug("Update Environment Variable")
request := c.apiClient.VariablesAPI.ApiVariablesUpdate(ctx, req.Uuid).VariableCreate(req.VariableCreate)
resp, httpResp, err := request.Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while updating a variables", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
return resp, nil
}
func (c *Client) Get(ctx context.Context, id string) (Response, error) {
logger.Debug("Get Environment Variable")
req := c.apiClient.VariablesAPI.ApiVariablesRetrieve(ctx, id)
resp, httpResp, err := req.Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while getting a variables", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
return resp, nil
}
func (c *Client) Create(ctx context.Context, strReq Request) (Response, error) {
logger.Debug("Create Environment Variable")
resp, httpResp, err := c.apiClient.VariablesAPI.ApiVariablesCreate(ctx).
VariableCreate(strReq.VariableCreate).Execute()
if err != nil {
if httpResp != nil {
logger.Debug("Error while creating a variables", zap.Error(err))
err := utils.LogAndRewindBody(httpResp)
if err != nil {
return nil, err
}
}
return nil, utils.ErrorPerStatusCode(httpResp, err)
}
return resp, nil
}