diff --git a/cmd/list.go b/cmd/list.go index 10daa6a..11f1829 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -9,6 +9,7 @@ under the terms of the MIT License; see LICENSE file for more details. package cmd import ( + "errors" "fmt" "reanahub/reana-client-go/client" "reanahub/reana-client-go/client/operations" @@ -18,6 +19,7 @@ import ( "reanahub/reana-client-go/pkg/filterer" "reanahub/reana-client-go/pkg/formatter" "reanahub/reana-client-go/pkg/workflows" + "strings" "github.com/go-gota/gota/dataframe" "github.com/go-gota/gota/series" @@ -53,8 +55,7 @@ values to the ` + "``--shared-by``" + ` and ` + "``--shared-with``" + ` command- - ` + "``--shared-with nobody``" + `: list your unshared workflows exclusively. - - ` + "``--shared-with bob@cern.ch,cecile@cern.ch``" + `: list workflows - shared with either bob@cern.ch or cecile@cern.ch + - ` + "``--shared-with bob@cern.ch``" + `: list workflows shared with bob@cern.ch Examples: @@ -161,12 +162,12 @@ In case a workflow is in progress, its duration as of now will be shown.`, f.Int64Var(&o.page, "page", 1, "Results page number (to be used with --size).") f.Int64Var(&o.size, "size", 0, "Number of results per page (to be used with --page).") f.BoolVar(&o.shared, "shared", false, "List all shared (owned and unowned) workflows.") - f.StringVar(&o.shared_by, "shared-by", "", "List workflows shared by the specified user(s).") + f.StringVar(&o.shared_by, "shared-by", "", "List workflows shared by the specified user.") f.StringVar( &o.shared_with, "shared-with", "", - "List workflows shared with the specified user(s).", + "List workflows shared with the specified user.", ) // Remove -h shorthand cmd.PersistentFlags().BoolP("help", "", false, "Help for list") @@ -180,14 +181,7 @@ In case a workflow is in progress, its duration as of now will be shown.`, func (o *listOptions) run(cmd *cobra.Command) error { if o.shared_by != "" && o.shared_with != "" { - displayer.DisplayMessage( - "Please provide either --shared-by or --shared-with, not both.", - displayer.Error, - false, - cmd.OutOrStdout(), - ) - - return nil + return errors.New("please provide either --shared-by or --shared-with, not both") } var runType string @@ -335,7 +329,9 @@ func displayListPayload( case "shared_by": value = workflow.OwnerEmail case "shared_with": - value = workflow.SharedWith + if len(workflow.SharedWith) > 0 { + value = strings.Join(workflow.SharedWith, ", ") + } } colSeries.Append(value) diff --git a/cmd/list_test.go b/cmd/list_test.go index bf22f13..d0bcd61 100644 --- a/cmd/list_test.go +++ b/cmd/list_test.go @@ -305,8 +305,9 @@ func TestList(t *testing.T) { "invalid: shared with and shared by in the same command": { args: []string{"--shared-by", "anybody", "--shared-with", "anybody"}, expected: []string{ - "Please provide either --shared-by or --shared-with, not both", + "please provide either --shared-by or --shared-with, not both", }, + wantError: true, }, } diff --git a/cmd/secrets_add.go b/cmd/secrets_add.go index 28fa4c4..1df393e 100644 --- a/cmd/secrets_add.go +++ b/cmd/secrets_add.go @@ -128,7 +128,6 @@ For literal strings use "SECRET_NAME=VALUE" format`, encodedValue := base64.StdEncoding.EncodeToString([]byte(value)) secretNames = append(secretNames, key) secrets[key] = operations.AddSecretsParamsBodyAnon{ - Name: key, Type: "env", Value: encodedValue, } @@ -146,7 +145,6 @@ For literal strings use "SECRET_NAME=VALUE" format`, fileName := filepath.Base(filePath) secretNames = append(secretNames, fileName) secrets[fileName] = operations.AddSecretsParamsBodyAnon{ - Name: fileName, Type: "file", Value: encodedData, } diff --git a/cmd/secrets_add_test.go b/cmd/secrets_add_test.go index 8a68150..34b6fd9 100644 --- a/cmd/secrets_add_test.go +++ b/cmd/secrets_add_test.go @@ -114,7 +114,6 @@ func TestParseSecrets(t *testing.T) { envSecrets: []string{"PASSWORD=password"}, secrets: map[string]operations.AddSecretsParamsBodyAnon{ "PASSWORD": { - Name: "PASSWORD", Type: "env", Value: base64.StdEncoding.EncodeToString([]byte("password")), }, @@ -125,7 +124,6 @@ func TestParseSecrets(t *testing.T) { fileSecrets: []string{piFile}, secrets: map[string]operations.AddSecretsParamsBodyAnon{ "pi.txt": { - Name: "pi.txt", Type: "file", Value: base64.StdEncoding.EncodeToString([]byte("3.14")), }, @@ -137,22 +135,18 @@ func TestParseSecrets(t *testing.T) { fileSecrets: []string{emptyFile, piFile}, secrets: map[string]operations.AddSecretsParamsBodyAnon{ "PASSWORD": { - Name: "PASSWORD", Type: "env", Value: base64.StdEncoding.EncodeToString([]byte("password")), }, "USER": { - Name: "USER", Type: "env", Value: base64.StdEncoding.EncodeToString([]byte("reanauser")), }, "empty.txt": { - Name: "empty.txt", Type: "file", Value: "", }, "pi.txt": { - Name: "pi.txt", Type: "file", Value: base64.StdEncoding.EncodeToString([]byte("3.14")), }, diff --git a/cmd/share_add.go b/cmd/share_add.go index 4d83238..0caba81 100644 --- a/cmd/share_add.go +++ b/cmd/share_add.go @@ -88,13 +88,10 @@ func (o *shareAddOptions) run(cmd *cobra.Command) error { shareAddParams := operations.NewShareWorkflowParams() shareAddParams.SetAccessToken(&o.token) shareAddParams.SetWorkflowIDOrName(o.workflow) - if o.message != "" { - shareAddParams.SetMessage(&o.message) - } - - if o.validUntil != "" { - shareAddParams.SetValidUntil(&o.validUntil) - } + shareAddParams.SetShareDetails(operations.ShareWorkflowBody{ + Message: o.message, + ValidUntil: o.validUntil, + }) api, err := client.ApiClient() if err != nil { @@ -107,7 +104,7 @@ func (o *shareAddOptions) run(cmd *cobra.Command) error { for _, user := range o.users { log.Infof("Sharing workflow %s with user %s", o.workflow, user) - shareAddParams.SetUserEmailToShareWith(user) + shareAddParams.ShareDetails.UserEmailToShareWith = &user _, err := api.Operations.ShareWorkflow(shareAddParams) if err != nil { diff --git a/cmd/share_remove.go b/cmd/share_remove.go index cc8bb41..9cfc51d 100644 --- a/cmd/share_remove.go +++ b/cmd/share_remove.go @@ -12,6 +12,7 @@ import ( "fmt" "reanahub/reana-client-go/client" "reanahub/reana-client-go/client/operations" + "reanahub/reana-client-go/pkg/config" "reanahub/reana-client-go/pkg/displayer" "reanahub/reana-client-go/pkg/errorhandler" "strings" @@ -113,6 +114,7 @@ func (o *shareRemoveOptions) run(cmd *cobra.Command) error { for _, err := range shareErrors { displayer.DisplayMessage(err, displayer.Error, false, cmd.OutOrStdout()) } + return config.EmptyError } return nil diff --git a/cmd/share_remove_test.go b/cmd/share_remove_test.go index bccf176..54dc638 100644 --- a/cmd/share_remove_test.go +++ b/cmd/share_remove_test.go @@ -44,6 +44,7 @@ func TestShareRemove(t *testing.T) { expected: []string{ "REANA_WORKON is set to invalid, but that workflow does not exist.", }, + wantError: true, }, } diff --git a/cmd/share_status.go b/cmd/share_status.go index 92b5c2f..cff5f03 100644 --- a/cmd/share_status.go +++ b/cmd/share_status.go @@ -108,11 +108,7 @@ func (o *shareStatusOptions) run(cmd *cobra.Command) error { parsedFormatFilters, o.jsonOutput, ) - if err != nil { - return err - } - - return nil + return err } func displayShareStatusPayload( @@ -134,8 +130,6 @@ func displayShareStatusPayload( case "valid_until": if share.ValidUntil != nil { value = *share.ValidUntil - } else { - value = "-" } } diff --git a/testdata/inputs/list.json b/testdata/inputs/list.json index 2735495..783a792 100644 --- a/testdata/inputs/list.json +++ b/testdata/inputs/list.json @@ -26,7 +26,8 @@ "user": "user", "session_status": "created", "session_type": "jupyter", - "session_uri": "/session1uri" + "session_uri": "/session1uri", + "shared_with": [] }, { "created": "2022-08-10T17:14:12", @@ -53,7 +54,8 @@ "user": "user", "session_status": "created", "session_type": "jupyter", - "session_uri": "/session2uri" + "session_uri": "/session2uri", + "shared_with": ["shared_with_email"] } ] -} \ No newline at end of file +}