From 3ea8ebf8aa5bf7f45335c008afd49da6d83d425a Mon Sep 17 00:00:00 2001 From: Ed Cook Date: Wed, 13 May 2020 16:50:48 +0100 Subject: [PATCH] Add support for using om client credentials - `om` uses client credentials over username/password if both are set, `hammer om` does not do anything to avoid this behaviour --- README.md | 8 +++++ environment/config.go | 36 +++++++++++-------- environment/config_test.go | 14 ++++---- environment/fixtures/lemon.json | 2 ++ environment/fixtures/lemon.yaml | 2 ++ .../fixtures/claim_manatee_response.json | 2 ++ integration/fixtures/om_script.sh | 2 +- integration/fixtures/om_script_json.sh | 2 +- integration/om_command_test.go | 2 +- om/runner.go | 16 ++++++--- om/runner_test.go | 18 ++++++---- 11 files changed, 69 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 01d5da0..2258646 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ In order to run the `hammer` tool against a given environment you need to have a "name": "ENVIRONMENT-NAME", "ops_manager": { "url": "OPSMAN-URL", + "client_id": "OPSMAN-CLIENT-ID", + "client_secret": "OPSMAN-CLIENT-SECRET", "username": "OPSMAN-USERNAME", "password": "OPSMAN-PASSWORD" }, @@ -41,6 +43,8 @@ Or the equivalent in yaml: ```yaml name: ENVIRONMENT-NAME ops_manager: + client_id: OPSMAN-CLIENT-ID + client_secret: OPSMAN-CLIENT-SECRET password: OPSMAN-PASSWORD url: OPSMAN-URL username: OPSMAN-USERNAME @@ -56,6 +60,10 @@ This file can then be passed into the tool via `hammer -t path-to-env-config 0 { omCommandLines = []string{ - fmt.Sprintf(`om -t '%s' -k -u '%s' -p '%s' %s`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password, quoteArgs(omArgs)), + fmt.Sprintf(`OM_CLIENT_ID='%s' OM_CLIENT_SECRET='%s' OM_USERNAME='%s' OM_PASSWORD='%s' om -t '%s' -k %s`, + data.OpsManager.ClientID, + data.OpsManager.ClientSecret, + data.OpsManager.Username, + data.OpsManager.Password, + data.OpsManager.URL.String(), + quoteArgs(omArgs)), } omPrereqs = []string{"om"} } else { omCommandLines = []string{ - fmt.Sprintf(`echo "export OM_TARGET=%s"`, data.OpsManager.URL.String()), - fmt.Sprintf(`echo "export OM_USERNAME=%s"`, data.OpsManager.Username), - fmt.Sprintf(`echo "export OM_PASSWORD=%s"`, data.OpsManager.Password), + fmt.Sprintf(`echo "export OM_TARGET='%s'"`, data.OpsManager.URL.String()), + fmt.Sprintf(`echo "export OM_CLIENT_ID='%s'"`, data.OpsManager.ClientID), + fmt.Sprintf(`echo "export OM_CLIENT_SECRET='%s'"`, data.OpsManager.ClientSecret), + fmt.Sprintf(`echo "export OM_USERNAME='%s'"`, data.OpsManager.Username), + fmt.Sprintf(`echo "export OM_PASSWORD='%s'"`, data.OpsManager.Password), } } diff --git a/om/runner_test.go b/om/runner_test.go index 179f18d..298ee3c 100644 --- a/om/runner_test.go +++ b/om/runner_test.go @@ -39,9 +39,11 @@ var _ = Describe("om runner", func() { url, _ := url.Parse("https://www.test-url.io") data = environment.Config{ OpsManager: environment.OpsManager{ - URL: *url, - Username: "username", - Password: "password", + URL: *url, + Username: "username", + Password: "password", + ClientID: "client_id", + ClientSecret: "client_secret", }, } @@ -64,9 +66,11 @@ var _ = Describe("om runner", func() { lines, prereqs, _ := scriptRunner.RunScriptArgsForCall(0) Expect(lines).To(Equal([]string{ - `echo "export OM_TARGET=https://www.test-url.io"`, - `echo "export OM_USERNAME=username"`, - `echo "export OM_PASSWORD=password"`, + `echo "export OM_TARGET='https://www.test-url.io'"`, + `echo "export OM_CLIENT_ID='client_id'"`, + `echo "export OM_CLIENT_SECRET='client_secret'"`, + `echo "export OM_USERNAME='username'"`, + `echo "export OM_PASSWORD='password'"`, })) Expect(prereqs).To(HaveLen(0)) }) @@ -86,7 +90,7 @@ var _ = Describe("om runner", func() { lines, prereqs, _ := scriptRunner.RunScriptArgsForCall(0) Expect(lines).To(Equal([]string{ - `om -t 'https://www.test-url.io' -k -u 'username' -p 'password' 'arg1' 'arg2' 'arg3'`, + `OM_CLIENT_ID='client_id' OM_CLIENT_SECRET='client_secret' OM_USERNAME='username' OM_PASSWORD='password' om -t 'https://www.test-url.io' -k 'arg1' 'arg2' 'arg3'`, })) Expect(prereqs).To(ConsistOf("om")) })