forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvs.go
More file actions
88 lines (73 loc) · 2.28 KB
/
Copy pathenvs.go
File metadata and controls
88 lines (73 loc) · 2.28 KB
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
package gateway
import (
"context"
"github.com/railwayapp/cli/entity"
)
func (g *Gateway) GetEnvs(ctx context.Context, req *entity.GetEnvsRequest) (*entity.Envs, error) {
gqlReq, err := g.NewRequestWithAuth(`
query ($projectId: String!, $environmentId: String!, $serviceId: String) {
decryptedVariablesForService(projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId)
}
`)
if err != nil {
return nil, err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("environmentId", req.EnvironmentID)
if req.ServiceID != "" {
gqlReq.Var("serviceId", req.ServiceID)
}
var resp struct {
Envs *entity.Envs `json:"decryptedVariablesForService"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return nil, err
}
return resp.Envs, nil
}
func (g *Gateway) UpsertVariablesFromObject(ctx context.Context, req *entity.UpdateEnvsRequest) error {
gqlReq, err := g.NewRequestWithAuth(`
mutation($projectId: String!, $environmentId: String!, $pluginId: String, $serviceId: String, $variables: Json!) {
upsertVariablesFromObject(projectId: $projectId, environmentId: $environmentId, pluginId: $pluginId, serviceId: $serviceId, variables: $variables)
}
`)
if err != nil {
return err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("environmentId", req.EnvironmentID)
if req.PluginID != "" {
gqlReq.Var("pluginId", req.PluginID)
}
if req.ServiceID != "" {
gqlReq.Var("serviceId", req.ServiceID)
}
gqlReq.Var("variables", req.Envs)
if err := gqlReq.Run(ctx, nil); err != nil {
return err
}
return nil
}
func (g *Gateway) DeleteVariable(ctx context.Context, req *entity.DeleteVariableRequest) error {
gqlReq, err := g.NewRequestWithAuth(`
mutation($projectId: String!, $environmentId: String!, $pluginId: String, $serviceId: String, $name: String!) {
deleteVariable(projectId: $projectId, environmentId: $environmentId, pluginId: $pluginId, serviceId: $serviceId, name: $name)
}
`)
if err != nil {
return err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("environmentId", req.EnvironmentID)
gqlReq.Var("name", req.Name)
if req.PluginID != "" {
gqlReq.Var("pluginId", req.PluginID)
}
if req.ServiceID != "" {
gqlReq.Var("serviceId", req.ServiceID)
}
if err := gqlReq.Run(ctx, nil); err != nil {
return err
}
return nil
}