forked from vmware-archive/fly
/
set_pipeline.go
51 lines (42 loc) · 1.93 KB
/
set_pipeline.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
package commands
import (
"github.com/concourse/atc"
"github.com/concourse/atc/web"
"github.com/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/fly/commands/internal/setpipelinehelpers"
"github.com/concourse/fly/rc"
"github.com/concourse/fly/template"
"github.com/tedsuo/rata"
)
type SetPipelineCommand struct {
Pipeline string `short:"p" long:"pipeline" required:"true" description:"Pipeline to configure"`
Config atc.PathFlag `short:"c" long:"config" required:"true" description:"Pipeline configuration file"`
Var []flaghelpers.VariablePairFlag `short:"v" long:"var" value-name:"[SECRET=KEY]" description:"Variable flag that can be used for filling in template values in configuration"`
VarsFrom []atc.PathFlag `short:"l" long:"load-vars-from" description:"Variable flag that can be used for filling in template values in configuration from a YAML file"`
SkipInteractive bool `short:"n" long:"non-interactive" description:"Skips interactions, uses default values"`
}
func (command *SetPipelineCommand) Execute(args []string) error {
configPath := command.Config
templateVariablesFiles := command.VarsFrom
pipelineName := command.Pipeline
templateVariables := template.Variables{}
for _, v := range command.Var {
templateVariables[v.Name] = v.Value
}
target, err := rc.LoadTarget(Fly.Target)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
webRequestGenerator := rata.NewRequestGenerator(target.Client().URL(), web.Routes)
atcConfig := setpipelinehelpers.ATCConfig{
Team: target.Team(),
PipelineName: pipelineName,
WebRequestGenerator: webRequestGenerator,
SkipInteraction: command.SkipInteractive,
}
return atcConfig.Set(configPath, templateVariables, templateVariablesFiles)
}