diff --git a/README.md b/README.md index 757ffd4..a427a51 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,10 @@ Must be non-nil and non-empty. The structure of the `pipeline` object is as foll be unpaused after the creation. If it is set to `true`, the command `unpause-pipeline` will be executed for the specific pipeline. + - `exposed`: *Optional.* Boolean specifying if the pipeline should + be exposed after the creation. If it is set to `true`, the command + `expose-pipeline` will be executed for the specific pipeline. + ### dynamic Resource configuration as above for Check, with the following job configuration: diff --git a/concourse/types.go b/concourse/types.go index ee5e429..00d8341 100644 --- a/concourse/types.go +++ b/concourse/types.go @@ -57,6 +57,7 @@ type Pipeline struct { Vars map[string]interface{} `json:"vars" yaml:"vars"` TeamName string `json:"team" yaml:"team"` Unpaused bool `json:"unpaused" yaml:"unpaused"` + Exposed bool `json:"exposed" yaml:"exposed"` } type OutResponse struct { diff --git a/fly/fly.go b/fly/fly.go index a19a335..661696e 100644 --- a/fly/fly.go +++ b/fly/fly.go @@ -21,6 +21,7 @@ type Command interface { SetPipeline(pipelineName string, configFilepath string, varsFilepaths []string, vars map[string]interface{}) ([]byte, error) DestroyPipeline(pipelineName string) ([]byte, error) UnpausePipeline(pipelineName string) ([]byte, error) + ExposePipeline(pipelineName string) ([]byte, error) } type command struct { @@ -151,6 +152,13 @@ func (f command) DestroyPipeline(pipelineName string) ([]byte, error) { ) } +func (f command) ExposePipeline(pipelineName string) ([]byte, error) { + return f.run( + "expose-pipeline", + "-p", pipelineName, + ) +} + func (f command) run(args ...string) ([]byte, error) { if f.target == "" { return nil, fmt.Errorf("target cannot be empty in command.run") diff --git a/fly/fly_test.go b/fly/fly_test.go index 54f616e..afc8caa 100644 --- a/fly/fly_test.go +++ b/fly/fly_test.go @@ -353,4 +353,28 @@ echo '[{"name":"abc"},{"name":"def"}]' Expect(string(output)).To(Equal(expectedOutput)) }) }) + + Describe("ExposePipeline", func() { + var ( + pipelineName string + ) + + BeforeEach(func() { + pipelineName = "some-pipeline" + }) + + It("returns output without error", func() { + output, err := flyCommand.ExposePipeline(pipelineName) + Expect(err).NotTo(HaveOccurred()) + + expectedOutput := fmt.Sprintf( + "%s %s %s %s %s\n", + "-t", target, + "expose-pipeline", + "-p", pipelineName, + ) + + Expect(string(output)).To(Equal(expectedOutput)) + }) + }) }) diff --git a/fly/flyfakes/fake_command.go b/fly/flyfakes/fake_command.go index 0491676..3d69b3a 100644 --- a/fly/flyfakes/fake_command.go +++ b/fly/flyfakes/fake_command.go @@ -21,6 +21,19 @@ type FakeCommand struct { result1 []byte result2 error } + ExposePipelineStub func(string) ([]byte, error) + exposePipelineMutex sync.RWMutex + exposePipelineArgsForCall []struct { + arg1 string + } + exposePipelineReturns struct { + result1 []byte + result2 error + } + exposePipelineReturnsOnCall map[int]struct { + result1 []byte + result2 error + } GetPipelineStub func(string) ([]byte, error) getPipelineMutex sync.RWMutex getPipelineArgsForCall []struct { @@ -159,6 +172,69 @@ func (fake *FakeCommand) DestroyPipelineReturnsOnCall(i int, result1 []byte, res }{result1, result2} } +func (fake *FakeCommand) ExposePipeline(arg1 string) ([]byte, error) { + fake.exposePipelineMutex.Lock() + ret, specificReturn := fake.exposePipelineReturnsOnCall[len(fake.exposePipelineArgsForCall)] + fake.exposePipelineArgsForCall = append(fake.exposePipelineArgsForCall, struct { + arg1 string + }{arg1}) + fake.recordInvocation("ExposePipeline", []interface{}{arg1}) + fake.exposePipelineMutex.Unlock() + if fake.ExposePipelineStub != nil { + return fake.ExposePipelineStub(arg1) + } + if specificReturn { + return ret.result1, ret.result2 + } + fakeReturns := fake.exposePipelineReturns + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeCommand) ExposePipelineCallCount() int { + fake.exposePipelineMutex.RLock() + defer fake.exposePipelineMutex.RUnlock() + return len(fake.exposePipelineArgsForCall) +} + +func (fake *FakeCommand) ExposePipelineCalls(stub func(string) ([]byte, error)) { + fake.exposePipelineMutex.Lock() + defer fake.exposePipelineMutex.Unlock() + fake.ExposePipelineStub = stub +} + +func (fake *FakeCommand) ExposePipelineArgsForCall(i int) string { + fake.exposePipelineMutex.RLock() + defer fake.exposePipelineMutex.RUnlock() + argsForCall := fake.exposePipelineArgsForCall[i] + return argsForCall.arg1 +} + +func (fake *FakeCommand) ExposePipelineReturns(result1 []byte, result2 error) { + fake.exposePipelineMutex.Lock() + defer fake.exposePipelineMutex.Unlock() + fake.ExposePipelineStub = nil + fake.exposePipelineReturns = struct { + result1 []byte + result2 error + }{result1, result2} +} + +func (fake *FakeCommand) ExposePipelineReturnsOnCall(i int, result1 []byte, result2 error) { + fake.exposePipelineMutex.Lock() + defer fake.exposePipelineMutex.Unlock() + fake.ExposePipelineStub = nil + if fake.exposePipelineReturnsOnCall == nil { + fake.exposePipelineReturnsOnCall = make(map[int]struct { + result1 []byte + result2 error + }) + } + fake.exposePipelineReturnsOnCall[i] = struct { + result1 []byte + result2 error + }{result1, result2} +} + func (fake *FakeCommand) GetPipeline(arg1 string) ([]byte, error) { fake.getPipelineMutex.Lock() ret, specificReturn := fake.getPipelineReturnsOnCall[len(fake.getPipelineArgsForCall)] @@ -483,6 +559,8 @@ func (fake *FakeCommand) Invocations() map[string][][]interface{} { defer fake.invocationsMutex.RUnlock() fake.destroyPipelineMutex.RLock() defer fake.destroyPipelineMutex.RUnlock() + fake.exposePipelineMutex.RLock() + defer fake.exposePipelineMutex.RUnlock() fake.getPipelineMutex.RLock() defer fake.getPipelineMutex.RUnlock() fake.loginMutex.RLock() diff --git a/out/command.go b/out/command.go index 6fda352..bf1d4ed 100644 --- a/out/command.go +++ b/out/command.go @@ -89,6 +89,13 @@ func (c *Command) Run(input concourse.OutRequest) (concourse.OutResponse, error) return concourse.OutResponse{}, err } + if p.Exposed { + _, err = c.flyCommand.ExposePipeline(p.Name) + if err != nil { + return concourse.OutResponse{}, err + } + } + if p.Unpaused { _, err = c.flyCommand.UnpausePipeline(p.Name) if err != nil { diff --git a/out/command_test.go b/out/command_test.go index ad1716f..85e6e2c 100644 --- a/out/command_test.go +++ b/out/command_test.go @@ -91,6 +91,7 @@ pipeline3: foo ConfigFile: "pipeline_2.yml", TeamName: teamName, Unpaused: true, + Exposed: true, }, { Name: apiPipelines[2], @@ -193,11 +194,12 @@ pipeline3: foo Expect(varsFilepaths[1]).To(Equal(filepath.Join(sourcesDir, p.VarsFiles[1]))) } - // the second pipeline has Unpaused set to true + // the second pipeline has Unpaused and Exposed set to true if i == 1 { name := fakeFlyCommand.UnpausePipelineArgsForCall(0) Expect(name).To(Equal(p.Name)) Expect(fakeFlyCommand.UnpausePipelineCallCount()).To(Equal(1)) + Expect(fakeFlyCommand.ExposePipelineCallCount()).To(Equal(1)) } // the third pipeline has vars