-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathcommand.go
103 lines (86 loc) · 1.86 KB
/
command.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
package out
import (
"time"
"os"
"github.com/concourse/cf-resource"
)
const CfDockerPassword = "CF_DOCKER_PASSWORD"
type Command struct {
paas PAAS
}
func NewCommand(paas PAAS) *Command {
return &Command{
paas: paas,
}
}
func (command *Command) Run(request Request) (Response, error) {
err := command.paas.Login(
request.Source.API,
request.Source.Username,
request.Source.Password,
request.Source.ClientID,
request.Source.ClientSecret,
request.Source.SkipCertCheck,
)
if err != nil {
return Response{}, err
}
err = command.paas.Target(
request.Source.Organization,
request.Source.Space,
)
if err != nil {
return Response{}, err
}
if err := command.setEnvironmentVariables(request); err != nil {
return Response{}, err
}
if request.Params.DockerPassword != "" {
os.Setenv(CfDockerPassword, request.Params.DockerPassword)
}
err = command.paas.PushApp(
request.Params.ManifestPath,
request.Params.Path,
request.Params.CurrentAppName,
request.Params.Vars,
request.Params.VarsFiles,
request.Params.DockerUsername,
request.Params.ShowAppLog,
request.Params.NoStart,
)
if err != nil {
return Response{}, err
}
return Response{
Version: resource.Version{
Timestamp: time.Now(),
},
Metadata: []resource.MetadataPair{
{
Name: "organization",
Value: request.Source.Organization,
},
{
Name: "space",
Value: request.Source.Space,
},
},
}, nil
}
func (command *Command) setEnvironmentVariables(request Request) error {
if len(request.Params.EnvironmentVariables) == 0 {
return nil
}
manifest, err := NewManifest(request.Params.ManifestPath)
if err != nil {
return err
}
for key, value := range request.Params.EnvironmentVariables {
manifest.AddEnvironmentVariable(key, value)
}
err = manifest.Save(request.Params.ManifestPath)
if err != nil {
return err
}
return nil
}