forked from railwayapp/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.go
81 lines (70 loc) · 2.08 KB
/
environment.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
package gateway
import (
"context"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/errors"
)
func (g *Gateway) CreateEnvironment(ctx context.Context, req *entity.CreateEnvironmentRequest) (*entity.Environment, error) {
gqlReq, err := g.NewRequestWithAuth(`
mutation($name: String!, $projectId: String!) {
createEnvironment(name: $name, projectId: $projectId) {
id
name
}
}
`)
if err != nil {
return nil, err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("name", req.Name)
var resp struct {
Environment *entity.Environment `json:"createEnvironment,omitempty"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return nil, errors.CreateEnvironmentFailed
}
return resp.Environment, nil
}
func (g *Gateway) CreateEphemeralEnvironment(ctx context.Context, req *entity.CreateEphemeralEnvironmentRequest) (*entity.Environment, error) {
gqlReq, err := g.NewRequestWithAuth(`
mutation($name: String!, $projectId: String!, $baseEnvironmentId: String!) {
createEphemeralEnvironment(name: $name, projectId: $projectId, baseEnvironmentId: $baseEnvironmentId) {
id
name
}
}
`)
if err != nil {
return nil, err
}
gqlReq.Var("projectId", req.ProjectID)
gqlReq.Var("name", req.Name)
gqlReq.Var("baseEnvironmentId", req.BaseEnvironmentID)
var resp struct {
Environment *entity.Environment `json:"createEphemeralEnvironment,omitempty"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return nil, errors.CreateEnvironmentFailed
}
return resp.Environment, nil
}
func (g *Gateway) DeleteEnvironment(ctx context.Context, req *entity.DeleteEnvironmentRequest) error {
gqlReq, err := g.NewRequestWithAuth(`
mutation($environmentId: String!, $projectId: String!) {
deleteEnvironment(environmentId: $environmentId, projectId: $projectId)
}
`)
if err != nil {
return err
}
gqlReq.Var("environmentId", req.EnvironmentId)
gqlReq.Var("projectId", req.ProjectID)
var resp struct {
Created bool `json:"createEnvironment,omitempty"`
}
if err := gqlReq.Run(ctx, &resp); err != nil {
return errors.CreateEnvironmentFailed
}
return nil
}