Skip to content

Commit

Permalink
Revert "Merge branch 'assurity-master'"
Browse files Browse the repository at this point in the history
This reverts commit 07cf523, reversing
changes made to a4252bf.
  • Loading branch information
vito committed Aug 11, 2017
1 parent 377cf04 commit 5869ecf
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 156 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,3 @@ _testmain.go
/test.json
/*.tar.gz
/built*

# IDE
*.iml
.idea
.idea/**/*
*.swp
**/build

# OSX
**/.DS_Store
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Cloud Foundry deployment.
* `space`: *Required.* The space to push the application to.
* `skip_cert_check`: *Optional.* Check the validity of the CF SSL cert.
Defaults to `false`.
* `command_environment_variables`: *Optional.* Environment variables set on the `cf` CLI process.
See [cf-cli](https://docs.cloudfoundry.org/cf-cli/cf-help.html#environment-variables)
Note: `CF_COLOR` is set to `true` by default.

## Behaviour

Expand Down Expand Up @@ -70,8 +67,4 @@ resources:
organization: ORG
space: SPACE
skip_cert_check: false
command_environment_variables:
CF_COLOR: true
CF_DIAL_TIMEOUT: 15
CF_TRACE: true
```
6 changes: 3 additions & 3 deletions check/cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
var _ = Describe("Check", func() {
It("outputs an empty JSON array so that it satisfies the resource interface", func() {
bin, err := Build("github.com/concourse/cf-resource/check/cmd/check")
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

cmd := exec.Command(bin)
session, err := Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

Eventually(session).Should(Exit(0))
Expect(session.Out).To(Say(`\[\]`))
Ω(session.Out).Should(Say(`\[\]`))
})
})
14 changes: 7 additions & 7 deletions in/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ var _ = Describe("In", func() {

JustBeforeEach(func() {
binPath, err := gexec.Build("github.com/concourse/cf-resource/in/cmd/in")
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

tmpDir, err = ioutil.TempDir("", "cf_resource_in")

stdin := &bytes.Buffer{}
err = json.NewEncoder(stdin).Encode(request)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

cmd := exec.Command(binPath, tmpDir)
cmd.Stdin = stdin
Expand All @@ -43,17 +43,17 @@ var _ = Describe("In", func() {
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))

err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())
})

AfterEach(func() {
err := os.RemoveAll(tmpDir)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())
})

Context("when a version is given to the executable", func() {
Expand All @@ -74,7 +74,7 @@ var _ = Describe("In", func() {
})

It("outputs that version", func() {
Expect(response.Version.Timestamp).To(BeTemporally("~", request.Version.Timestamp, time.Second))
Ω(response.Version.Timestamp).Should(BeTemporally("~", request.Version.Timestamp, time.Second))
})
})

Expand All @@ -93,7 +93,7 @@ var _ = Describe("In", func() {
})

It("generates a 'fake' current version", func() {
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
Ω(response.Version.Timestamp).Should(BeTemporally("~", time.Now(), time.Second))
})
})
})
13 changes: 6 additions & 7 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package resource
import "time"

type Source struct {
API string `json:"api"`
Username string `json:"username"`
Password string `json:"password"`
Organization string `json:"organization"`
Space string `json:"space"`
SkipCertCheck bool `json:"skip_cert_check"`
CommandEnvironmentVariables map[string]interface{} `json:"command_environment_variables"`
API string `json:"api"`
Username string `json:"username"`
Password string `json:"password"`
Organization string `json:"organization"`
Space string `json:"space"`
SkipCertCheck bool `json:"skip_cert_check"`
}

type Version struct {
Expand Down
4 changes: 1 addition & 3 deletions out/assets/cf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ echo $(basename $0) $*
echo
echo $PWD
echo
# env order needs to be predictable for testing as `gbytes.Say`
# in `integration_test` fast forwards through buffer contents
env | sort
env
17 changes: 4 additions & 13 deletions out/cloud_foundry.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package out

import (
"fmt"
"os"
"os/exec"
)
Expand All @@ -12,13 +11,10 @@ type PAAS interface {
PushApp(manifest string, path string, currentAppName string) error
}

type CloudFoundry struct {
ConfiguredEnvironment map[string]interface{}
OsEnvironment []string
}
type CloudFoundry struct{}

func NewCloudFoundry(configuredEnvironment map[string]interface{}, osEnvironment []string) *CloudFoundry {
return &CloudFoundry{configuredEnvironment, osEnvironment}
func NewCloudFoundry() *CloudFoundry {
return &CloudFoundry{}
}

func (cf *CloudFoundry) Login(api string, username string, password string, insecure bool) error {
Expand Down Expand Up @@ -82,12 +78,7 @@ func (cf *CloudFoundry) cf(args ...string) *exec.Cmd {
cmd := exec.Command("cf", args...)
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr

environment := cf.OsEnvironment
for k, v := range cf.ConfiguredEnvironment {
environment = append(environment, fmt.Sprintf("%s=%v", k, v))
}
cmd.Env = environment
cmd.Env = append(os.Environ(), "CF_COLOR=true")

return cmd
}
16 changes: 3 additions & 13 deletions out/cmd/out/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func main() {
os.Exit(1)
}

cloudFoundry := out.NewCloudFoundry()
command := out.NewCommand(cloudFoundry)

var request out.Request
if err := json.NewDecoder(os.Stdin).Decode(&request); err != nil {
fatal("reading request from stdin", err)
Expand Down Expand Up @@ -48,11 +51,6 @@ func main() {
request.Params.Path = pathFiles[0]
}

env := makeMap(request.Source.CommandEnvironmentVariables)
env["CF_COLOR"] = true
cloudFoundry := out.NewCloudFoundry(env, os.Environ())
command := out.NewCommand(cloudFoundry)

response, err := command.Run(request)
if err != nil {
fatal("running command", err)
Expand All @@ -67,11 +65,3 @@ func fatal(message string, err error) {
fmt.Fprintf(os.Stderr, "error %s: %s\n", message, err)
os.Exit(1)
}

func makeMap(m map[string]interface{}) map[string]interface{} {
if m != nil {
return m
} else {
return make(map[string]interface{})
}
}
2 changes: 1 addition & 1 deletion out/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (command *Command) setEnvironmentVariables(request Request) error {
}

err = manifest.Save(request.Params.ManifestPath)
if err != nil {
if (err != nil) {
return err
}

Expand Down
68 changes: 34 additions & 34 deletions out/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,45 @@ var _ = Describe("Out Command", func() {
Describe("running the command", func() {
It("pushes an application into cloud foundry", func() {
response, err := command.Run(request)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
Expect(response.Metadata[0]).To(Equal(
Ω(response.Version.Timestamp).Should(BeTemporally("~", time.Now(), time.Second))
Ω(response.Metadata[0]).Should(Equal(
resource.MetadataPair{
Name: "organization",
Value: "secret",
},
))
Expect(response.Metadata[1]).To(Equal(
Ω(response.Metadata[1]).Should(Equal(
resource.MetadataPair{
Name: "space",
Value: "volcano-base",
},
))

By("logging in")
Expect(cloudFoundry.LoginCallCount()).To(Equal(1))
Ω(cloudFoundry.LoginCallCount()).Should(Equal(1))

api, username, password, insecure := cloudFoundry.LoginArgsForCall(0)
Expect(api).To(Equal("https://api.run.pivotal.io"))
Expect(username).To(Equal("awesome@example.com"))
Expect(password).To(Equal("hunter2"))
Expect(insecure).To(Equal(false))
Ω(api).Should(Equal("https://api.run.pivotal.io"))
Ω(username).Should(Equal("awesome@example.com"))
Ω(password).Should(Equal("hunter2"))
Ω(insecure).Should(Equal(false))

By("targetting the organization and space")
Expect(cloudFoundry.TargetCallCount()).To(Equal(1))
Ω(cloudFoundry.TargetCallCount()).Should(Equal(1))

org, space := cloudFoundry.TargetArgsForCall(0)
Expect(org).To(Equal("secret"))
Expect(space).To(Equal("volcano-base"))
Ω(org).Should(Equal("secret"))
Ω(space).Should(Equal("volcano-base"))

By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))
Ω(cloudFoundry.PushAppCallCount()).Should(Equal(1))

manifest, path, currentAppName := cloudFoundry.PushAppArgsForCall(0)
Expect(manifest).To(Equal("assets/manifest.yml"))
Expect(path).To(Equal(""))
Expect(currentAppName).To(Equal(""))
Ω(manifest).Should(Equal("assets/manifest.yml"))
Ω(path).Should(Equal(""))
Ω(currentAppName).Should(Equal(""))
})

Describe("handling any errors", func() {
Expand All @@ -95,21 +95,21 @@ var _ = Describe("Out Command", func() {
cloudFoundry.LoginReturns(expectedError)

_, err := command.Run(request)
Expect(err).To(MatchError(expectedError))
Ω(err).Should(MatchError(expectedError))
})

It("from targetting an org and space", func() {
cloudFoundry.TargetReturns(expectedError)

_, err := command.Run(request)
Expect(err).To(MatchError(expectedError))
Ω(err).Should(MatchError(expectedError))
})

It("from pushing the application", func() {
cloudFoundry.PushAppReturns(expectedError)

_, err := command.Run(request)
Expect(err).To(MatchError(expectedError))
Ω(err).Should(MatchError(expectedError))
})
})

Expand All @@ -119,11 +119,11 @@ var _ = Describe("Out Command", func() {

BeforeEach(func() {
sourceFile, err := os.Open("assets/manifest.yml")
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())
defer sourceFile.Close()

tempFile, err = ioutil.TempFile("assets", "command_test.yml_")
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())
defer tempFile.Close()

_, err = io.Copy(tempFile, sourceFile)
Expand Down Expand Up @@ -152,24 +152,24 @@ var _ = Describe("Out Command", func() {
})

It("does not raise an error", func() {
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())
})

It("writes the variables into the manifest", func() {
manifest, _ := out.NewManifest(request.Params.ManifestPath)

Expect(manifest.EnvironmentVariables()["COMMAND_TEST_A"]).To(Equal("command_test_a"))
Expect(manifest.EnvironmentVariables()["COMMAND_TEST_B"]).To(Equal("command_test_b"))
Ω(manifest.EnvironmentVariables()["COMMAND_TEST_A"]).Should(Equal("command_test_a"))
Ω(manifest.EnvironmentVariables()["COMMAND_TEST_B"]).Should(Equal("command_test_b"))
})
})

Context("no environment variables provided", func() {
It("doesn't set the environment variables", func() {
manifest, err := out.NewManifest(request.Params.ManifestPath)
Expect(err).NotTo(HaveOccurred())
Expect(manifest.EnvironmentVariables()).To(HaveLen(2))
Expect(manifest.EnvironmentVariables()).To(HaveKeyWithValue("MANIFEST_A", "manifest_a"))
Expect(manifest.EnvironmentVariables()).To(HaveKeyWithValue("MANIFEST_B", "manifest_b"))
Ω(err).ShouldNot(HaveOccurred())
Ω(manifest.EnvironmentVariables()).Should(HaveLen(2))
Ω(manifest.EnvironmentVariables()).Should(HaveKeyWithValue("MANIFEST_A", "manifest_a"))
Ω(manifest.EnvironmentVariables()).Should(HaveKeyWithValue("MANIFEST_B", "manifest_b"))
})
})

Expand All @@ -189,13 +189,13 @@ var _ = Describe("Out Command", func() {
}

_, err := command.Run(request)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

By("logging in")
Expect(cloudFoundry.LoginCallCount()).To(Equal(1))
Ω(cloudFoundry.LoginCallCount()).Should(Equal(1))

_, _, _, insecure := cloudFoundry.LoginArgsForCall(0)
Expect(insecure).To(Equal(true))
Ω(insecure).Should(Equal(true))
})

It("lets people do a zero downtime deploy", func() {
Expand All @@ -214,13 +214,13 @@ var _ = Describe("Out Command", func() {
}

_, err := command.Run(request)
Expect(err).NotTo(HaveOccurred())
Ω(err).ShouldNot(HaveOccurred())

By("pushing the app")
Expect(cloudFoundry.PushAppCallCount()).To(Equal(1))
Ω(cloudFoundry.PushAppCallCount()).Should(Equal(1))

_, _, currentAppName := cloudFoundry.PushAppArgsForCall(0)
Expect(currentAppName).To(Equal("cool-app-name"))
Ω(currentAppName).Should(Equal("cool-app-name"))
})
})
})
Loading

0 comments on commit 5869ecf

Please sign in to comment.