Skip to content

Commit

Permalink
Add api version set option
Browse files Browse the repository at this point in the history
  • Loading branch information
oleewere committed May 4, 2019
1 parent 8c12241 commit 15062fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 5 additions & 4 deletions cm/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,29 +94,30 @@ func GetConnectionProfileEntryId(id string) string {
}

// RegisterNewCMEntry create new CM server registry entry in cmctl database
func RegisterNewCMEntry(id string, hostname string, port int, protocol string, username string, password string, useGateway bool) {
func RegisterNewCMEntry(id string, hostname string, port int, protocol string, username string, password string, useGateway bool, apiVersion int) {
checkId := GetCMEntryId(id)
if len(checkId) > 0 {
alreadyExistMsg := fmt.Sprintf("Registry with id '%s' is already defined as a registry entry", checkId)
fmt.Println(alreadyExistMsg)
os.Exit(1)
}
cmServerEntries := ListCMRegistryEntries()
newCmServerEntry := CMServer{Name: id, Hostname: hostname, Port: port, Protocol: protocol, Username: username, Password: password, Active: true, UseGateway: useGateway}
newCmServerEntry := CMServer{Name: id, Hostname: hostname, Port: port, Protocol: protocol, Username: username,
Password: password, Active: true, UseGateway: useGateway, ApiVersion: apiVersion}
cmServerEntries = append(cmServerEntries, newCmServerEntry)
WriteCMServerEntries(cmServerEntries)
}

// UpdateCMEntry update CM server registry entry in cmctl database
func UpdateCMEntry(id string, hostname string, port int, protocol string, username string, password string, useGateway bool, connectionProfile string) {
func UpdateCMEntry(id string, hostname string, port int, protocol string, username string, password string, useGateway bool, apiVersion int, connectionProfile string) {
checkId := GetCMEntryId(id)
if len(checkId) == 0 {
notExistMsg := fmt.Sprintf("Registry with id '%s' does not exist in CM server registry DB.", checkId)
fmt.Println(notExistMsg)
os.Exit(1)
}
updatedCmServerEntry := CMServer{Name: id, Hostname: hostname, Port: port, Protocol: protocol, Username: username, Password: password,
Active: true, UseGateway: useGateway, ConnectionProfile: connectionProfile}
Active: true, UseGateway: useGateway, ApiVersion: apiVersion, ConnectionProfile: connectionProfile}

cmServers := ListCMRegistryEntries()
newCmServers := make([]CMServer, 0)
Expand Down
1 change: 1 addition & 0 deletions cm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type CMServer struct {
Active bool `json:"active"`
ConnectionProfile string `json:"profile"`
UseGateway bool `json:"gateway"`
ApiVersion int `json:"version"`
}

// ConnectionProfile represents ssh/connection descriptions which is used to communicate with CM server and agents
Expand Down
25 changes: 23 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var Version string
// GitRevString that will be generated during the build as a constant - represents git revision value
var GitRevString string

// DefaultApiVersion number that is used as api versions in REST api requests e.g. (32): api/v32/..
const DefaultApiVersion = 32

func main() {
app := cli.NewApp()
app.Name = "cmctl"
Expand Down Expand Up @@ -86,9 +89,17 @@ func main() {
username := strings.ToLower(cm.GetStringFlag(c.String("username"), "admin", "Enter CM user"))
password := cm.GetPassword(c.String("password"), "Enter CM user password")

apiVersion := cm.GetStringFlag(c.String("verion"), strconv.Itoa(DefaultApiVersion), "Enter CM API version")
apiVersionNum, err := strconv.Atoi(apiVersion)

if err != nil {
fmt.Println(err)
os.Exit(1)
}

cm.DeactiveAllCMRegistry()
cm.RegisterNewCMEntry(name, host, port, protocol,
username, password, useGateway)
username, password, useGateway, apiVersionNum)
fmt.Println("New CM server entry has been created: " + name)
return nil
},
Expand All @@ -100,6 +111,7 @@ func main() {
cli.StringFlag{Name: "protocol", Usage: "Protocol for CM REST API: http/https"},
cli.StringFlag{Name: "username", Usage: "User name for CM server"},
cli.StringFlag{Name: "password", Usage: "Password for CM user"},
cli.StringFlag{Name: "version", Usage: "CM Api Version"},
},
}

Expand Down Expand Up @@ -147,8 +159,16 @@ func main() {
username := strings.ToLower(cm.GetStringFlag(c.String("username"), existingCmServer.Username, "Enter CM user"))
password := cm.GetPassword(c.String("password"), "Enter CM user password")

apiVersion := cm.GetStringFlag(c.String("verion"), strconv.Itoa(DefaultApiVersion), "Enter CM API version")
apiVersionNum, err := strconv.Atoi(apiVersion)

if err != nil {
fmt.Println(err)
os.Exit(1)
}

cm.UpdateCMEntry(cmServerName, host, port, protocol,
username, password, useGateway, existingCmServer.ConnectionProfile)
username, password, useGateway, apiVersionNum, existingCmServer.ConnectionProfile)
fmt.Println("CM server entry has been updated: " + cmServerName)
return nil
},
Expand All @@ -159,6 +179,7 @@ func main() {
cli.StringFlag{Name: "protocol", Usage: "Protocol for CM REST API: http/https"},
cli.StringFlag{Name: "username", Usage: "User name for CM server"},
cli.StringFlag{Name: "password", Usage: "Password for CM user"},
cli.StringFlag{Name: "version", Usage: "CM Api Version"},
},
}

Expand Down

0 comments on commit 15062fd

Please sign in to comment.