Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commands/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ func nonNestedError(errorMessage string) error {
}

func actionParseError(cmd *cobra.Command, args []string, err error) error {
whisk.Debug(whisk.DbgError, "parseAction(%s, %s) error: %s\n", cmd, args, err)
whisk.Debug(whisk.DbgError, "parseAction(%s, %s) error: %s\n", cmd.Name(), args, err)

errMsg := wski18n.T(
"Invalid argument(s). {{.required}}",
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func actionGetError(entityName string, fetchCode bool, err error) error {
func handleInvocationError(err error, entityName string) error {
whisk.Debug(
whisk.DbgError,
"Client.Actions.Invoke(%s, %t) error: %s\n",
"Client.Actions.Invoke(%s) error: %s\n",
entityName,
err)

Expand Down
10 changes: 5 additions & 5 deletions commands/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ var apiCreateCmd = &cobra.Command{
}
api, qname, err = parseApi(cmd, args)
if err != nil {
whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd, args, err)
whisk.Debug(whisk.DbgError, "parseApi(%s, %s) error: %s\n", cmd.Name(), args, err)
errMsg := wski18n.T("Unable to parse api command arguments: {{.err}}",
map[string]interface{}{"err": err})
whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL,
Expand Down Expand Up @@ -653,7 +653,7 @@ func genFilteredList(resultApi *whisk.RetApi, apiPath string, apiVerb string) []
actionName = "/" + opv.XOpenWhisk.Namespace + "/" + opv.XOpenWhisk.ActionName
}
orderInfo = AssignListInfo(actionName, op, apiName, basePath, path, baseUrl+path)
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s %s\n", orderInfo.RelPath)
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s\n", orderInfo.RelPath)
orderInfoArr = append(orderInfoArr, orderInfo)
}
}
Expand Down Expand Up @@ -692,7 +692,7 @@ func genFilteredRow(resultApi *whisk.RetApi, apiPath string, apiVerb string, max
}
orderInfo = AssignRowInfo(actionName[0:min(len(actionName), maxActionNameSize)], op, apiName[0:min(len(apiName), maxApiNameSize)], basePath, path, baseUrl+path)
orderInfo.FmtString = fmtString
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s %s\n", orderInfo.RelPath)
whisk.Debug(whisk.DbgInfo, "Appening to orderInfoArr: %s\n", orderInfo.RelPath)
orderInfoArr = append(orderInfoArr, orderInfo)
}
}
Expand Down Expand Up @@ -987,15 +987,15 @@ func parseSwaggerApi(configfile string, namespace string) (*whisk.Api, error) {
}

if swaggerObj.BasePath == "" || swaggerObj.SwaggerName == "" || swaggerObj.Info == nil || swaggerObj.Paths == nil {
whisk.Debug(whisk.DbgError, "Swagger file is invalid.\n", configfile, err)
whisk.Debug(whisk.DbgError, "Swagger file is invalid.\n")
errMsg := wski18n.T("Swagger file is invalid (missing basePath, info, paths, or swagger fields)")
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
return nil, whiskErr
}

if _, ok := isValidBasepath(swaggerObj.BasePath); !ok {
whisk.Debug(whisk.DbgError, "Swagger file basePath is invalid.\n", configfile, err)
whisk.Debug(whisk.DbgError, "Swagger file basePath is invalid.\n")
errMsg := wski18n.T("Swagger file basePath must start with a leading slash (/)")
whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL,
whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE)
Expand Down
2 changes: 1 addition & 1 deletion commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func SetupClientConfig(cmd *cobra.Command, args []string) error {

// Determine if the parent command will require the API host to be set
apiHostRequired := (cmd.Parent().Name() == "property" && cmd.Name() == "get" && (Flags.property.auth ||
Flags.property.cert || Flags.property.key || Flags.property.apihost || Flags.property.namespace ||
Flags.property.cert || Flags.property.key || Flags.property.apihost ||
Flags.property.apiversion || Flags.property.cliversion)) ||
(cmd.Parent().Name() == "property" && cmd.Name() == "set" && (len(Flags.property.apihostSet) > 0 ||
len(Flags.property.apiversionSet) > 0 || len(Flags.Global.Auth) > 0)) ||
Expand Down
104 changes: 25 additions & 79 deletions commands/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,38 +145,6 @@ var propertySetCmd = &cobra.Command{
map[string]interface{}{"ok": color.GreenString("ok:"), "version": boldString(apiVersion)}))
}

if namespace := Flags.property.namespaceSet; len(namespace) > 0 {
namespaces, _, err := Client.Namespaces.List()
if err != nil {
whisk.Debug(whisk.DbgError, "Client.Namespaces.List() failed: %s\n", err)
errStr := fmt.Sprintf(
wski18n.T("Authenticated user does not have namespace '{{.name}}'; set command failed: {{.err}}",
map[string]interface{}{"name": namespace, "err": err}))
werr = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
} else {
whisk.Debug(whisk.DbgInfo, "Validating namespace '%s' is in user namespace list %#v\n", namespace, namespaces)
var validNamespace bool
for _, ns := range namespaces {
if ns.Name == namespace {
whisk.Debug(whisk.DbgInfo, "Namespace '%s' is valid\n", namespace)
validNamespace = true
}
}
if !validNamespace {
whisk.Debug(whisk.DbgError, "Namespace '%s' is not in the list of entitled namespaces\n", namespace)
errStr := fmt.Sprintf(
wski18n.T("Namespace '{{.name}}' is not in the list of entitled namespaces",
map[string]interface{}{"name": namespace}))
werr = whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
} else {
props["NAMESPACE"] = namespace
okMsg += fmt.Sprintf(
wski18n.T("{{.ok}} whisk namespace set to {{.name}}\n",
map[string]interface{}{"ok": color.GreenString("ok:"), "name": boldString(namespace)}))
}
}
}

err = WriteProps(Properties.PropsFile, props)
if err != nil {
whisk.Debug(whisk.DbgError, "writeProps(%s, %#v) failed: %s\n", Properties.PropsFile, props, err)
Expand Down Expand Up @@ -236,21 +204,6 @@ var propertyUnsetCmd = &cobra.Command{
map[string]interface{}{"ok": color.GreenString("ok:")}))
}

if Flags.property.namespace {
delete(props, "NAMESPACE")
okMsg += fmt.Sprintf(
wski18n.T("{{.ok}} whisk namespace unset",
map[string]interface{}{"ok": color.GreenString("ok:")}))
if len(DefaultNamespace) > 0 {
okMsg += fmt.Sprintf(
wski18n.T("; the default value of {{.default}} will be used.\n",
map[string]interface{}{"default": boldString(DefaultNamespace)}))
} else {
okMsg += fmt.Sprint(
wski18n.T("; there is no default value that can be used.\n"))
}
}

if Flags.property.apihost {
delete(props, "APIHOST")
okMsg += fmt.Sprintf(
Expand Down Expand Up @@ -305,8 +258,8 @@ var propertyGetCmd = &cobra.Command{
case "raw":
outputFormat = "raw"
break
//case "json": For future implementation
//case "yaml": For future implementation
//case "json": For future implementation
//case "yaml": For future implementation
default:
errStr := fmt.Sprintf(
wski18n.T("Supported output format are std|raw"))
Expand All @@ -323,6 +276,7 @@ var propertyGetCmd = &cobra.Command{
Flags.property.apihost || Flags.property.apibuildno) {
Flags.property.all = true
}

if Flags.property.all {
// Currently with all only standard output format is supported.
if outputFormat != "std" {
Expand All @@ -332,14 +286,23 @@ var propertyGetCmd = &cobra.Command{
return werr
}

fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAPIHost), boldString(Properties.APIHost))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAuth), boldString(Properties.Auth))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayNamespace), boldString(getNamespace()))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayCert), boldString(Properties.Cert))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayKey), boldString(Properties.Key))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAuth), boldString(Properties.Auth))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayAPIHost), boldString(Properties.APIHost))
fmt.Fprintf(color.Output, "%s\t%s\n", wski18n.T(propDisplayAPIVersion), boldString(Properties.APIVersion))
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(propDisplayNamespace), boldString(Properties.Namespace))
fmt.Fprintf(color.Output, "%s\t%s\n", wski18n.T(propDisplayCLIVersion), boldString(Properties.CLIVersion))
} else {
if Flags.property.apihost {
printProperty(Properties.APIHost, propDisplayAPIHost, outputFormat)
}
if Flags.property.auth {
printProperty(Properties.Auth, propDisplayAuth, outputFormat)
}
if Flags.property.namespace {
printProperty(getNamespace(), propDisplayNamespace, outputFormat)
}
if Flags.property.cert {
printProperty(Properties.Cert, propDisplayCert, outputFormat)
}
Expand All @@ -349,18 +312,9 @@ var propertyGetCmd = &cobra.Command{
if Flags.property.cliversion {
printProperty(Properties.CLIVersion, propDisplayCLIVersion, outputFormat, "%s\t%s\n")
}
if Flags.property.apihost {
printProperty(Properties.APIHost, propDisplayAPIHost, outputFormat)
}
if Flags.property.auth {
printProperty(Properties.Auth, propDisplayAuth, outputFormat)
}
if Flags.property.apiversion {
printProperty(Properties.APIVersion, propDisplayAPIVersion, outputFormat, "%s\t%s\n")
}
if Flags.property.namespace {
printProperty(Properties.Namespace, propDisplayNamespace, outputFormat)
}
}

if Flags.property.all || Flags.property.apibuild || Flags.property.apibuildno {
Expand Down Expand Up @@ -418,15 +372,12 @@ func init() {
propertySetCmd.Flags().StringVar(&Flags.Global.Key, "key", "", wski18n.T(propDisplayKey))
propertySetCmd.Flags().StringVar(&Flags.property.apihostSet, "apihost", "", wski18n.T("whisk API `HOST`"))
propertySetCmd.Flags().StringVar(&Flags.property.apiversionSet, "apiversion", "", wski18n.T("whisk API `VERSION`"))
propertySetCmd.Flags().StringVar(&Flags.property.namespaceSet, "namespace", "", wski18n.T("whisk `NAMESPACE`"))

propertyUnsetCmd.Flags().BoolVar(&Flags.property.cert, "cert", false, wski18n.T(propDisplayCert))
propertyUnsetCmd.Flags().BoolVar(&Flags.property.key, "key", false, wski18n.T(propDisplayKey))
propertyUnsetCmd.Flags().BoolVar(&Flags.property.auth, "auth", false, wski18n.T("authorization key"))
propertyUnsetCmd.Flags().BoolVar(&Flags.property.apihost, "apihost", false, wski18n.T(propDisplayAPIHost))
propertyUnsetCmd.Flags().BoolVar(&Flags.property.apiversion, "apiversion", false, wski18n.T(propDisplayAPIVersion))
propertyUnsetCmd.Flags().BoolVar(&Flags.property.namespace, "namespace", false, wski18n.T(propDisplayNamespace))

}

func SetDefaultProperties() {
Expand Down Expand Up @@ -527,14 +478,6 @@ func loadProperties() error {
Properties.APIHost = apiHost
}

if namespace, hasProp := props["NAMESPACE"]; hasProp && len(namespace) > 0 {
Properties.Namespace = namespace
}

if namespace := os.Getenv("WHISK_NAMESPACE"); len(namespace) > 0 {
Properties.Namespace = namespace
}

return nil
}

Expand All @@ -561,13 +504,6 @@ func parseConfigFlags(cmd *cobra.Command, args []string) error {
}
}

if namespace := Flags.property.namespaceSet; len(namespace) > 0 {
Properties.Namespace = namespace
if Client != nil {
Client.Config.Namespace = namespace
}
}

if apiVersion := Flags.Global.Apiversion; len(apiVersion) > 0 {
Properties.APIVersion = apiVersion
if Client != nil {
Expand Down Expand Up @@ -619,3 +555,13 @@ func printProperty(propertyName string, displayText string, formatType string, f
fmt.Fprintf(color.Output, "%s\t\t%s\n", wski18n.T(displayText), boldString(propertyName))
}
}

func getNamespace() string {
var namespaces, _, err = Client.Namespaces.List()
whisk.Debug(whisk.DbgError, "Client.Namespaces.List() failed: %s\n", err)
if err != nil {
return "_"
} else {
return namespaces[0].Name
}
}
2 changes: 1 addition & 1 deletion commands/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var sdkInstallCmd = &cobra.Command{
} else {
err = WskCmd.GenBashCompletionFile(BASH_AUTOCOMPLETE_FILENAME)
if err != nil {
whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: \n", BASH_AUTOCOMPLETE_FILENAME, err)
whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: %s\n", BASH_AUTOCOMPLETE_FILENAME, err)
errStr := wski18n.T("Unable to generate '{{.name}}': {{.err}}",
map[string]interface{}{"name": BASH_AUTOCOMPLETE_FILENAME, "err": err})
werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
Expand Down
2 changes: 1 addition & 1 deletion commands/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func createOrUpdate(Client *whisk.Client, fqn *QualifiedName, trigger *whisk.Tri
_, _, err := Client.Triggers.Insert(trigger, overwrite)

if err != nil {
whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v, %s) failed: %s\n", trigger, overwrite, err)
whisk.Debug(whisk.DbgError, "Client.Triggers.Insert(%+v, %t) failed: %s\n", trigger, overwrite, err)
var errStr string
if !overwrite {
errStr = wski18n.T("Unable to create trigger '{{.name}}': {{.err}}",
Expand Down
2 changes: 1 addition & 1 deletion commands/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func getParameters(params []string, keyValueFormat bool, annotation bool) interf

parameters, err = getJSONFromStrings(params, keyValueFormat)
if err != nil {
whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, %s) failed: %s\n", params, keyValueFormat, err)
whisk.Debug(whisk.DbgError, "getJSONFromStrings(%#v, %t) failed: %s\n", params, keyValueFormat, err)
var errStr string

if !annotation {
Expand Down
11 changes: 2 additions & 9 deletions tests/src/integration/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestShowAPIVersion(t *testing.T) {
// Test case to verify the default namespace _.
func TestDefaultNamespace(t *testing.T) {
common.CreateFile(tmpProp)
common.WriteFile(tmpProp, []string{"NAMESPACE="})
common.WriteFile(tmpProp, []string{"APIHOST=xyz"})

os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")
Expand All @@ -101,7 +101,7 @@ func TestValidateDefaultProperties(t *testing.T) {
os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")

stdout, err := wsk.RunCommand("property", "unset", "--auth", "--apihost", "--apiversion", "--namespace")
stdout, err := wsk.RunCommand("property", "unset", "--auth", "--apihost", "--apiversion")
assert.Equal(t, nil, err, "The command property unset failed to run.")
outputString := string(stdout)
assert.Contains(t, outputString, "ok: whisk auth unset",
Expand All @@ -110,8 +110,6 @@ func TestValidateDefaultProperties(t *testing.T) {
"The output of the command does not contain \"ok: whisk API host unset\".")
assert.Contains(t, outputString, "ok: whisk API version unset",
"The output of the command does not contain \"ok: whisk API version unset\".")
assert.Contains(t, outputString, "ok: whisk namespace unset",
"The output of the command does not contain \"ok: whisk namespace unset\".")

stdout, err = wsk.RunCommand("property", "get", "--auth")
assert.Equal(t, nil, err, "The command property get --auth failed to run.")
Expand All @@ -123,11 +121,6 @@ func TestValidateDefaultProperties(t *testing.T) {
assert.Equal(t, common.PropDisplayAPIHost, common.RemoveRedundentSpaces(string(stdout)),
"The output of the command does not equal to "+common.PropDisplayAPIHost)

stdout, err = wsk.RunCommand("property", "get", "--namespace")
assert.Equal(t, nil, err, "The command property get --namespace failed to run.")
assert.Equal(t, common.PropDisplayNamespace+" _", common.RemoveRedundentSpaces(string(stdout)),
"The output of the command does not equal to "+common.PropDisplayNamespace+" _")

common.DeleteFile(tmpProp)
}

Expand Down
17 changes: 5 additions & 12 deletions tests/src/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package tests
import (
"fmt"
"os"
"strings"
"testing"

"github.com/apache/incubator-openwhisk-cli/tests/src/integration/common"
Expand Down Expand Up @@ -331,29 +330,23 @@ func initInvalidArgs() {
var wsk *common.Wsk = common.NewWsk()
var tmpProp = common.GetRepoPath() + "/wskprops.tmp"

// Test case to set apihost, auth, and namespace.
// Test case to set apihost and auth.
func TestSetAPIHostAuthNamespace(t *testing.T) {
common.CreateFile(tmpProp)
common.WriteFile(tmpProp, []string{})

os.Setenv("WSK_CONFIG_FILE", tmpProp)
assert.Equal(t, os.Getenv("WSK_CONFIG_FILE"), tmpProp, "The environment variable WSK_CONFIG_FILE has not been set.")

namespace, _ := wsk.ListNamespaces()
namespaces := strings.Split(strings.TrimSpace(string(namespace)), "\n")
expectedNamespace := string(namespaces[len(namespaces)-1])
fmt.Println(wsk.Wskprops.APIHost)
if wsk.Wskprops.APIHost != "" && wsk.Wskprops.AuthKey != "" {
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost,
"--auth", wsk.Wskprops.AuthKey, "--namespace", expectedNamespace)
stdout, err := wsk.RunCommand("property", "set", "--apihost", wsk.Wskprops.APIHost, "--auth", wsk.Wskprops.AuthKey)
ouputString := string(stdout)
assert.Equal(t, nil, err, "The command property set --apihost --auth --namespace failed to run.")
assert.Equal(t, nil, err, "The command property set --apihost --auth failed to run.")
assert.Contains(t, ouputString, "ok: whisk auth set. Run 'wsk property get --auth' to see the new value.",
"The output of the command property set --apihost --auth --namespace does not contain \"whisk auth set\".")
"The output of the command property set --apihost --auth does not contain \"whisk auth set\".")
assert.Contains(t, ouputString, "ok: whisk API host set to "+wsk.Wskprops.APIHost,
"The output of the command property set --apihost --auth --namespace does not contain \"whisk API host set\".")
assert.Contains(t, ouputString, "ok: whisk namespace set to "+expectedNamespace,
"The output of the command property set --apihost --auth --namespace does not contain \"whisk namespace set\".")
"The output of the command property set --apihost --auth does not contain \"whisk API host set\".")
}
common.DeleteFile(tmpProp)
}
Expand Down
Loading