From b78b373b07ccbaf9442db132afcd0c51ab9c353b Mon Sep 17 00:00:00 2001 From: astoycos Date: Thu, 19 Mar 2020 15:44:04 -0400 Subject: [PATCH] Add ability to Login to cluster and Update Readme --- README.md | 4 +++- cmd/main-setup.go | 26 ++++++++++++++++++++++---- go.mod | 1 + go.sum | 1 + 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6363f18..1f38367 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,10 @@ An functioning openshift 4.X cluster is required for this CLI's usage [Download a release](https://github.com/redhat-iot/iot-dev/releases), move the executable to your `$PATH`, and simply run the following command to get started ``` -IoTCLI setup --user= --password= +IoTCLI setup ``` +It will prompt the user for their Openshift cluster credentials + ## Setting up IoT Cloud Native Messaging The user can chose to utilize Enmasse or Kafka for the middleware messaging layer diff --git a/cmd/main-setup.go b/cmd/main-setup.go index 43ef43d..7a33c63 100644 --- a/cmd/main-setup.go +++ b/cmd/main-setup.go @@ -25,7 +25,8 @@ import ( "compress/gzip" "path/filepath" "log" - //"os/exec" + "os/exec" + "golang.org/x/crypto/ssh/terminal" ) @@ -120,9 +121,6 @@ func Untar(dst string, r io.Reader) error { func setup() { downloadPkg("oc.tar.gz", ocUrl) downloadPkg("enmasse.tgz",enmasseUrl) - - //Download Jq? For deleteing resources with locked finalizers - ocContent, err := os.Open("oc.tar.gz") if err != nil { @@ -144,6 +142,26 @@ func setup() { os.Remove("oc.tar.gz") os.Remove("enmasse.tgz") + + //Login to OC + fmt.Print("Enter Openshift Username: ") + var user string + fmt.Scanln(&user) + + fmt.Print("Enter Openshift Password: ") + password, err := terminal.ReadPassword(0) + if err != nil{ + log.Fatal(err) + } + + fmt.Println() + + cmd := exec.Command("bash", "-c", "echo " + user + " " + string(password) + "| ./oc login") + cmd.Stdout = os.Stdout + err = cmd.Run() + if(err != nil){ + log.Fatal(err) + } } // setupCmd represents the setup command diff --git a/go.mod b/go.mod index f9fe3e3..271f83a 100644 --- a/go.mod +++ b/go.mod @@ -6,4 +6,5 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/spf13/cobra v0.0.6 github.com/spf13/viper v1.6.2 + golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 ) diff --git a/go.sum b/go.sum index 625a01f..d66e416 100644 --- a/go.sum +++ b/go.sum @@ -119,6 +119,7 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=