Skip to content

Commit

Permalink
fix(cmd): update workflow sharing commands after rebase (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonadoni committed Aug 29, 2024
1 parent d3f6494 commit 14593d9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 40 deletions.
22 changes: 9 additions & 13 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -53,8 +55,7 @@ values to the ` + "``--shared-by``" + ` and ` + "``--shared-with``" + ` command-
- ` + "``--shared-with nobody``" + `: list your unshared workflows exclusively.
- ` + "``--shared-with [email protected],[email protected]``" + `: list workflows
shared with either [email protected] or [email protected]
- ` + "``--shared-with [email protected]``" + `: list workflows shared with [email protected]
Examples:
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/secrets_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down
6 changes: 0 additions & 6 deletions cmd/secrets_add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
},
Expand All @@ -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")),
},
Expand All @@ -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")),
},
Expand Down
13 changes: 5 additions & 8 deletions cmd/share_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/share_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/share_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down
8 changes: 1 addition & 7 deletions cmd/share_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ func (o *shareStatusOptions) run(cmd *cobra.Command) error {
parsedFormatFilters,
o.jsonOutput,
)
if err != nil {
return err
}

return nil
return err

Check warning on line 111 in cmd/share_status.go

View check run for this annotation

Codecov / codecov/patch

cmd/share_status.go#L104-L111

Added lines #L104 - L111 were not covered by tests
}

func displayShareStatusPayload(
Expand All @@ -134,8 +130,6 @@ func displayShareStatusPayload(
case "valid_until":
if share.ValidUntil != nil {
value = *share.ValidUntil

Check warning on line 132 in cmd/share_status.go

View check run for this annotation

Codecov / codecov/patch

cmd/share_status.go#L127-L132

Added lines #L127 - L132 were not covered by tests
} else {
value = "-"
}
}

Expand Down
8 changes: 5 additions & 3 deletions testdata/inputs/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -53,7 +54,8 @@
"user": "user",
"session_status": "created",
"session_type": "jupyter",
"session_uri": "/session2uri"
"session_uri": "/session2uri",
"shared_with": ["shared_with_email"]
}
]
}
}

0 comments on commit 14593d9

Please sign in to comment.