Skip to content

Commit

Permalink
make sb target more usable, remove debug message
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Hartz committed Sep 5, 2017
1 parent 7466ca6 commit 2177c3b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
4 changes: 1 addition & 3 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ resources:
source:
branch: master
paths: []
uri: [email protected]:phartz/service-broker-cli.git
username: {{git-username}}
password: {{git-password}}
uri: https://github.com/phartz/service-broker-cli.git
- name: sync-resource
type: rsync-resource
source:
Expand Down
5 changes: 3 additions & 2 deletions sbcli/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ func Target(cmd *Commandline) {
fmt.Println("User: %s", c.Username)
}
} else {
sb := NewSBClient(&Credentials{Host: cmd.Options[0]})
host := CleanTargetURI(cmd.Options[0])
sb := NewSBClient(&Credentials{Host: host})
err := sb.TestConnection()
CheckErr(err)

c.Host = cmd.Options[0]
c.Host = host
c.Password = ""
c.Username = ""
c.save()
Expand Down
18 changes: 18 additions & 0 deletions sbcli/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"log"
"os"
"os/user"
"regexp"
"strings"

"golang.org/x/crypto/ssh/terminal"
)
Expand All @@ -27,6 +29,22 @@ func getPassword(prompt string) (password string, err error) {
return
}

func CleanTargetURI(uri string) string {
// check port
re := regexp.MustCompile(`:\d+\z`)
if re.FindString(uri) == "" {
uri = fmt.Sprintf("%s:3000", uri)
}

// check scheme, if no scheme was given, expect https
re = regexp.MustCompile(`\A(http://)|(https://)`)
if re.FindString(strings.ToLower(uri)) == "" {
uri = fmt.Sprintf("http://%s", uri)
}

return uri
}

func getUserHome() string {
usr, err := user.Current()
CheckErr(err)
Expand Down
3 changes: 0 additions & 3 deletions sbcli/servicecalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sbcli

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -223,8 +222,6 @@ func CreateService(cmd *Commandline) {
data.Parameters = getJSONFromCustom(cmd.Custom)
}

payloadBytes, err := json.Marshal(data)
fmt.Printf(string(payloadBytes))
err = sb.Provision(&data, cmd.Options[2])
CheckErr(err)

Expand Down
16 changes: 16 additions & 0 deletions tests/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tests

import (
"testing"

"github.com/phartz/service-broker-cli/sbcli"
)

func TestCleanTargetUIR(t *testing.T) {
AssertEqual(t, sbcli.CleanTargetURI("10.0.0.1"), "http://10.0.0.1:3000", "")
AssertEqual(t, sbcli.CleanTargetURI("10.0.0.1:3000"), "http://10.0.0.1:3000", "")
AssertEqual(t, sbcli.CleanTargetURI("https://10.0.0.1"), "https://10.0.0.1:3000", "")
AssertEqual(t, sbcli.CleanTargetURI("http://10.0.0.1"), "http://10.0.0.1:3000", "")
AssertEqual(t, sbcli.CleanTargetURI("https://10.0.0.1:3001"), "https://10.0.0.1:3001", "")
AssertEqual(t, sbcli.CleanTargetURI("HTTP://10.0.0.1:3001"), "HTTP://10.0.0.1:3001", "")
}

0 comments on commit 2177c3b

Please sign in to comment.