Repository navigation
Expand file tree
/
Copy pathenvs.go
More file actions
63 lines (51 loc) · 1.27 KB
/
Copy pathenvs.go
File metadata and controls
63 lines (51 loc) · 1.27 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
package controller
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/railwayapp/cli/entity"
"github.com/railwayapp/cli/ui"
)
func (c *Controller) GetEnvs(ctx context.Context) (*entity.Envs, error) {
// Get envs through production token if it exists
if c.cfg.RailwayProductionToken != "" {
envs, err := c.gtwy.GetEnvsWithProjectToken(ctx)
if err != nil {
return nil, err
}
return envs, err
}
projectCfg, err := c.cfg.GetProjectConfigs()
if err != nil {
return nil, err
}
if val, ok := projectCfg.LockedEnvsNames[projectCfg.Environment]; ok && val {
fmt.Println(ui.Bold(ui.RedText("Protected Environment Detected!").String()))
ui.PromptConfirm("Press Enter to Confirm Action")
}
return c.gtwy.GetEnvs(ctx, &entity.GetEnvsRequest{
ProjectID: projectCfg.Project,
EnvironmentID: projectCfg.Environment,
})
}
func (c *Controller) SaveEnvsToFile(ctx context.Context) error {
envs, err := c.GetEnvs(ctx)
if err != nil {
return err
}
err = c.cfg.CreatePathIfNotExist(c.cfg.RailwayEnvFilePath)
if err != nil {
return err
}
encoded, err := json.MarshalIndent(envs, "", " ")
if err != nil {
return err
}
err = ioutil.WriteFile(c.cfg.RailwayEnvFilePath, encoded, os.ModePerm)
if err != nil {
return err
}
return nil
}