-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pks-login command to Hammer (#6)
* Add pks-login command to Hammer * Requires the API for PKS (configurable in OpsManager) to be in Env file * Remove parseUrl and inline parsing of urls and ip * Run go mod tidy
- Loading branch information
Showing
19 changed files
with
477 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright (C) 2019-Present Pivotal Software, Inc. All rights reserved. | ||
This program and the accompanying materials are made available under the terms of the under the Apache License, Version 2.0 (the "License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package commands | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type PKSLoginCommand struct { | ||
TargetConfig string `short:"t" long:"target" env:"TARGET_ENVIRONMENT_CONFIG" hidden:"true"` | ||
File bool `short:"f" long:"file" description:"write a script file but do not run it"` | ||
|
||
Env EnvReader | ||
UI UI | ||
PKSLoginRunner ToolRunner | ||
} | ||
|
||
func (c *PKSLoginCommand) Execute(args []string) error { | ||
data, err := c.Env.Read(c.TargetConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
c.UI.DisplayText(fmt.Sprintf("Logging in to PKS at: %s\n", data.OpsManager.URL.String())) | ||
|
||
return c.PKSLoginRunner.Run(data, c.File) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
Copyright (C) 2019-Present Pivotal Software, Inc. All rights reserved. | ||
This program and the accompanying materials are made available under the terms of the under the Apache License, Version 2.0 (the "License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package commands_test | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
fakes "github.com/pivotal/hammer/commands/commandsfakes" | ||
"github.com/pivotal/hammer/environment" | ||
|
||
. "github.com/pivotal/hammer/commands" | ||
) | ||
|
||
var _ = Describe("pks login command", func() { | ||
var ( | ||
err error | ||
command *PKSLoginCommand | ||
|
||
envReader *fakes.FakeEnvReader | ||
ui *fakes.FakeUI | ||
pksLoginRunner *fakes.FakeToolRunner | ||
commandArgs []string | ||
) | ||
|
||
BeforeEach(func() { | ||
envReader = new(fakes.FakeEnvReader) | ||
ui = new(fakes.FakeUI) | ||
pksLoginRunner = new(fakes.FakeToolRunner) | ||
commandArgs = []string{"arg1", "arg2"} | ||
|
||
command = &PKSLoginCommand{ | ||
Env: envReader, | ||
UI: ui, | ||
PKSLoginRunner: pksLoginRunner, | ||
File: true, | ||
} | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
err = command.Execute(commandArgs) | ||
}) | ||
|
||
When("retrieving the environment config errors", func() { | ||
BeforeEach(func() { | ||
envReader.ReadReturns(environment.Config{}, fmt.Errorf("env-reader-error")) | ||
}) | ||
|
||
It("doesn't attempt to run the pks login tool", func() { | ||
Expect(pksLoginRunner.RunCallCount()).To(Equal(0)) | ||
}) | ||
|
||
It("propagates the error", func() { | ||
Expect(err).To(MatchError("env-reader-error")) | ||
}) | ||
}) | ||
|
||
When("retrieving the environment config is successful", func() { | ||
BeforeEach(func() { | ||
url, _ := url.Parse("www.test-pks.io") | ||
envReader.ReadReturns(environment.Config{OpsManager: environment.OpsManager{URL: *url}}, nil) | ||
}) | ||
|
||
It("displays that the pks is being logged into", func() { | ||
Expect(ui.DisplayTextCallCount()).To(Equal(1)) | ||
Expect(ui.DisplayTextArgsForCall(0)).To(Equal("Logging in to PKS at: www.test-pks.io\n")) | ||
}) | ||
|
||
It("runs the pks login tool using the retrieved environment config", func() { | ||
Expect(pksLoginRunner.RunCallCount()).To(Equal(1)) | ||
|
||
environmentConfig, _, _ := pksLoginRunner.RunArgsForCall(0) | ||
|
||
expectedURL, _ := url.Parse("www.test-pks.io") | ||
Expect(environmentConfig).To(BeEquivalentTo(environment.Config{OpsManager: environment.OpsManager{URL: *expectedURL}})) | ||
}) | ||
|
||
When("run with the file flag set", func() { | ||
BeforeEach(func() { | ||
command.File = true | ||
}) | ||
|
||
It("runs the pks login tool in dry run mode", func() { | ||
Expect(pksLoginRunner.RunCallCount()).To(Equal(1)) | ||
|
||
_, dryRun, _ := pksLoginRunner.RunArgsForCall(0) | ||
Expect(dryRun).To(BeTrue()) | ||
}) | ||
}) | ||
|
||
When("run with the file flag unset", func() { | ||
BeforeEach(func() { | ||
command.File = false | ||
}) | ||
|
||
It("runs the pks login tool in non-dry run mode", func() { | ||
Expect(pksLoginRunner.RunCallCount()).To(Equal(1)) | ||
|
||
_, dryRun, _ := pksLoginRunner.RunArgsForCall(0) | ||
Expect(dryRun).To(BeFalse()) | ||
}) | ||
}) | ||
|
||
It("runs the pks login tool with no additional args", func() { | ||
Expect(pksLoginRunner.RunCallCount()).To(Equal(1)) | ||
|
||
_, _, args := pksLoginRunner.RunArgsForCall(0) | ||
Expect(args).To(BeEmpty()) | ||
}) | ||
|
||
When("running the pks login tool is successful", func() { | ||
BeforeEach(func() { | ||
pksLoginRunner.RunReturns(nil) | ||
}) | ||
|
||
It("doesn't error", func() { | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
}) | ||
|
||
When("running the pks login tool errors", func() { | ||
BeforeEach(func() { | ||
pksLoginRunner.RunReturns(fmt.Errorf("pks-login-runnner-error")) | ||
}) | ||
|
||
It("propagates the error", func() { | ||
Expect(err).To(MatchError("pks-login-runnner-error")) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
prods="$(om -t https://pcf.manatee.cf-app.com -k -u pivotalcf -p fakePassword curl -s -p /api/v0/staged/products)" | ||
guid="$(echo "$prods" | jq -r '.[] | select(.type == "pivotal-container-service") | .guid')" | ||
creds="$(om -t https://pcf.manatee.cf-app.com -k -u pivotalcf -p fakePassword curl -s -p /api/v0/deployed/products/"$guid"/credentials/.properties.uaa_admin_password)" | ||
pass="$(echo "$creds" | jq -r .credential.value.secret)" | ||
pks login -a https://api.pks.manatee.cf-app.com -u admin -p "$pass" --skip-ssl-validation |
Oops, something went wrong.