Skip to content
Permalink
Browse files
This closes #31
  • Loading branch information
ahgittin committed Nov 3, 2016
2 parents 807e3cd + 3163afa commit b36e6c65207be84a5e8be11fde9aa102504dade9
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 37 deletions.
@@ -89,7 +89,7 @@ func GetPolicy(network *net.Network, policyId string) (models.CatalogItemSummary
}

func GetPolicyWithVersion(network *net.Network, policyId, version string) (models.CatalogItemSummary, error) {
url := fmt.Sprintf("/v1/catalog/policies/%s/%s", policyId)
url := fmt.Sprintf("/v1/catalog/policies/%s/%s", policyId, version)
var catalogItem models.CatalogItemSummary
body, err := network.SendGetRequest(url)
if err != nil {
@@ -148,9 +148,9 @@ func DeleteLocationWithVersion(network *net.Network, locationId, version string)
return string(body), nil
}

func Policies(network *net.Network) ([]models.CatalogPolicySummary, error) {
func Policies(network *net.Network) ([]models.CatalogItemSummary, error) {
url := "/v1/catalog/policies?allVersions"
var policies []models.CatalogPolicySummary
var policies []models.CatalogItemSummary
body, err := network.SendGetRequest(url)
if err != nil {
return policies, err
@@ -159,9 +159,9 @@ func Policies(network *net.Network) ([]models.CatalogPolicySummary, error) {
return policies, err
}

func Locations(network *net.Network) ([]models.CatalogLocationSummary, error) {
func Locations(network *net.Network) ([]models.CatalogItemSummary, error) {
url := "/v1/catalog/locations?allVersions=true"
var catalogLocations []models.CatalogLocationSummary
var catalogLocations []models.CatalogItemSummary
body, err := network.SendGetRequest(url)
if err != nil {
return catalogLocations, err
@@ -190,9 +190,20 @@ func Reset(network *net.Network) (string, error) {
return string(body), nil
}

func GetLocationWithVersion(network *net.Network, locationId, version string) (models.CatalogLocationSummary, error) {
func GetLocation(network *net.Network, locationId string) (models.CatalogItemSummary, error) {
url := fmt.Sprintf("/v1/catalog/locations/%s", locationId)
var catalogLocation models.CatalogItemSummary
body, err := network.SendGetRequest(url)
if err != nil {
return catalogLocation, err
}
err = json.Unmarshal(body, &catalogLocation)
return catalogLocation, err
}

func GetLocationWithVersion(network *net.Network, locationId, version string) (models.CatalogItemSummary, error) {
url := fmt.Sprintf("/v1/catalog/locations/%s/%s", locationId, version)
var catalogLocation models.CatalogLocationSummary
var catalogLocation models.CatalogItemSummary
body, err := network.SendGetRequest(url)
if err != nil {
return catalogLocation, err
@@ -232,13 +243,3 @@ func Catalog(network *net.Network) ([]models.CatalogItemSummary, error) {
return applications, err
}

func GetLocation(network *net.Network, locationId string) (models.CatalogLocationSummary, error) {
url := fmt.Sprintf("/v1/catalog/locations/%s", locationId)
var catalogLocation models.CatalogLocationSummary
body, err := network.SendGetRequest(url)
if err != nil {
return catalogLocation, err
}
err = json.Unmarshal(body, &catalogLocation)
return catalogLocation, err
}
@@ -56,6 +56,10 @@ func NewApp(baseName string, cmdRunner command_runner.Runner, metadatas ...comma
Name: "skipSslChecks",
Usage: "Skip verification of server's certificate chain and hostname (for use with self-signed certs)",
},
cli.StringFlag{
Name: "json, j",
Usage: "Render value as json with json path selector as described at https://github.com/NodePrime/jsonpath. (Experimental, not supported on all commands at present) ",
},
}

app.Commands = []cli.Command{}
@@ -109,7 +109,7 @@ func (cmd *CatalogList) listLocations(c *cli.Context) ([]models.IdentityDetails,
}
result := make([]models.IdentityDetails, len(locations))
for i, location := range locations {
result[i] = location.CatalogItemSummary.IdentityDetails
result[i] = location.IdentityDetails
}
return result, nil
}
@@ -0,0 +1,148 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 (
"github.com/apache/brooklyn-client/cli/api/catalog"
"github.com/apache/brooklyn-client/cli/command_metadata"
"github.com/apache/brooklyn-client/cli/error_handler"
"github.com/apache/brooklyn-client/cli/net"
"github.com/apache/brooklyn-client/cli/scope"
"github.com/urfave/cli"
"github.com/apache/brooklyn-client/cli/models"
"errors"
"strings"
)

type CatalogShow struct {
network *net.Network
}

func NewCatalogShow(network *net.Network) (cmd *CatalogShow) {
cmd = new(CatalogShow)
cmd.network = network
return
}

const showCommandName = "show"

func (cmd *CatalogShow) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: showCommandName,
Description: "Show a catalog item",
Usage: "BROOKLYN_NAME catalog " + showCommandName + " " + catalogItemTypesUsage + " ITEM",
}
}

func (cmd *CatalogShow) Run(scope scope.Scope, c *cli.Context) {
if err := net.VerifyLoginURL(cmd.network); err != nil {
error_handler.ErrorExit(err)
}
err := cmd.show(c)
if nil != err {
error_handler.ErrorExit(err)
}
}

func (cmd *CatalogShow) show(c *cli.Context) (error) {
if len(c.Args()) != 2 {
return errors.New(c.App.Name + " " + showCommandName + catalogItemTypesUsage + " ITEM[:VERSION]")
}
catalogType, err := GetCatalogType(c)
if err != nil {
return err
}
item := c.Args().Get(1)
var version string
if strings.Contains(item, ":") {
itemVersion := strings.Split(item, ":")
item = itemVersion[0]
version = itemVersion[1]
}
switch catalogType {
case ApplicationsItemType:
return cmd.showCatalogApplication(c, item, version)
case EntitiesItemType:
return cmd.showCatalogEntity(c, item, version)
case LocationsItemType:
return cmd.showCatalogLocation(c, item, version)
case PoliciesItemType:
return cmd.showPolicy(c, item, version)
}
return errors.New("Unrecognised argument")
}

func (cmd *CatalogShow) showPolicy(c *cli.Context, item string, version string) (error) {
var summary models.CatalogItemSummary
var err error
if version == "" {
summary, err = catalog.GetPolicy(cmd.network, item)
} else {
summary, err = catalog.GetPolicyWithVersion(cmd.network, item, version)
}
if err != nil {
return err
}

return summary.Display(c)
}

func (cmd *CatalogShow) showCatalogLocation(c *cli.Context, item string, version string) (error) {
var summary models.CatalogItemSummary
var err error
if version == "" {
summary, err = catalog.GetLocation(cmd.network, item)
} else {
summary, err = catalog.GetLocationWithVersion(cmd.network, item, version)
}
if err != nil {
return err
}
return summary.Display(c)
}

func (cmd *CatalogShow) showCatalogEntity(c *cli.Context, item string, version string) (error) {
var summary models.CatalogEntitySummary
var err error
if version == "" {
summary, err = catalog.GetEntity(cmd.network, item)
} else {
summary, err = catalog.GetEntityWithVersion(cmd.network, item, version)
}
if err != nil {
return err
}
return summary.Display(c)
}

func (cmd *CatalogShow) showCatalogApplication(c *cli.Context, item string, version string) (error) {
var summary models.CatalogEntitySummary
var err error
if version == "" {
summary, err = catalog.GetApplication(cmd.network, item)
} else {
summary, err = catalog.GetApplicationWithVersion(cmd.network, item, version)
}
if err != nil {
return err
}

return summary.Display(c)

}
@@ -39,23 +39,26 @@ func NewCatalog(network *net.Network) (cmd *Catalog) {
cmd = new(Catalog)
cmd.network = network
cmd.catalogCommands = map[string]command.Command {
ShowCatalogCommand: NewCatalogShow(cmd.network),
ListCatalogCommand: NewCatalogList(cmd.network),
AddCatalogCommand: NewCatalogAdd(cmd.network),
DeleteCatalogCommand: NewDeleteCatalogItem(cmd.network),
}
return
}

const ShowCatalogCommand = "show"
const ListCatalogCommand = "list"
const AddCatalogCommand = "add"
const DeleteCatalogCommand = "delete"

var catalogCommands = []string{
ShowCatalogCommand,
ListCatalogCommand,
AddCatalogCommand,
DeleteCatalogCommand,
}
var catalogCommandsUsage = "list TYPE | add FILE/URL | delete TYPE ID:VERSION"
var catalogCommandsUsage = "list TYPE | add FILE/URL | delete TYPE ID:VERSION | show ITEM"

type CatalogItemType int
const (
@@ -96,6 +99,7 @@ func (cmd *Catalog) Metadata() command_metadata.CommandMetadata {
Usage: "BROOKLYN_NAME catalog (" + catalogCommandsUsage + ")",
Flags: []cli.Flag{},
Operands: []command_metadata.CommandMetadata{
cmd.SubCommand(ShowCatalogCommand).Metadata(),
cmd.SubCommand(ListCatalogCommand).Metadata(),
cmd.SubCommand(AddCatalogCommand).Metadata(),
cmd.SubCommand(DeleteCatalogCommand).Metadata(),

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,7 @@
package: github.com/apache/brooklyn-client
import:
- package: github.com/urfave/cli
- package: github.com/NodePrime/jsonpath/cli/jsonpath
- package: golang.org/x/crypto
subpackages:
- ssh/terminal

0 comments on commit b36e6c6

Please sign in to comment.