Skip to content

Commit

Permalink
Handle namespace API listing on the client.
Browse files Browse the repository at this point in the history
Replaces call to GET /namespace/_ with calls to GET /namespace/_/[actions, triggers, rules, packages]
  • Loading branch information
rabbah committed Jan 9, 2018
1 parent 0fb150b commit 7028a85
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions commands/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,28 @@ var namespaceGetCmd = &cobra.Command{
}
}

namespace, _, err := Client.Namespaces.Get(qualifiedName.GetNamespace())

if err != nil {
whisk.Debug(whisk.DbgError, "Client.Namespaces.Get(%s) error: %s\n", getClientNamespace(), err)
errStr := wski18n.T("Unable to obtain the list of entities for namespace '{{.namespace}}': {{.err}}",
map[string]interface{}{"namespace": getClientNamespace(), "err": err})
errHandler := func(err error, kind string) error {
whisk.Debug(whisk.DbgError, "Client.%s.Get(%s) error: %s\n", getClientNamespace(), kind, err)
errStr := wski18n.T("Unable to obtain the list of %s for namespace '{{.namespace}}': {{.err}}",
kind, map[string]interface{}{"namespace": getClientNamespace(), "err": err})
werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_NETWORK,
whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return werr
}

fmt.Fprintf(color.Output, wski18n.T("Entities in namespace: {{.namespace}}\n",
map[string]interface{}{"namespace": boldString(getClientNamespace())}))
sortByName := Flags.common.nameSort
printList(namespace.Contents.Packages, sortByName)
printList(namespace.Contents.Actions, sortByName)
printList(namespace.Contents.Triggers, sortByName)
//No errors, lets attempt to retrieve the status of each rule #312
for index, rule := range namespace.Contents.Rules {
actions, _, err := Client.Actions.List("", &whisk.ActionListOptions{ Skip: 0, Limit: 0 })
if err != nil { return errHandler(err, "Actions") }

packages, _, err := Client.Packages.List(&whisk.PackageListOptions{ Skip: 0, Limit: 0 })
if err != nil { return errHandler(err, "Packages") }

triggers, _, err := Client.Triggers.List(&whisk.TriggerListOptions{ Skip: 0, Limit: 0 })
if err != nil { return errHandler(err, "Triggers") }

rules, _, err := Client.Rules.List(&whisk.RuleListOptions{ Skip: 0, Limit: 0 })
if err != nil { return errHandler(err, "Rules") }
//No errors, lets attempt to retrieve the status of each rule
for index, rule := range rules {
ruleStatus, _, err := Client.Rules.Get(rule.Name)
if err != nil {
errStr := wski18n.T("Unable to get status of rule '{{.name}}': {{.err}}",
Expand All @@ -113,9 +116,16 @@ var namespaceGetCmd = &cobra.Command{
werr := whisk.MakeWskErrorFromWskError(errors.New(errStr), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
return werr
}
namespace.Contents.Rules[index].Status = ruleStatus.Status
rules[index].Status = ruleStatus.Status
}
printList(namespace.Contents.Rules, sortByName)

fmt.Fprintf(color.Output, wski18n.T("Entities in namespace: {{.namespace}}\n",
map[string]interface{}{"namespace": boldString(getClientNamespace())}))
sortByName := Flags.common.nameSort
printList(packages, sortByName)
printList(actions, sortByName)
printList(triggers, sortByName)
printList(rules, sortByName)

return nil
},
Expand Down

0 comments on commit 7028a85

Please sign in to comment.