-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes to jimmctl auth relation list
#1220
Changes from 2 commits
91a690b
8240162
5a90332
d9e2b53
3f0c0b8
09ba675
cfdd6d5
9d3e4ed
bae9a7f
45602ea
73ed66d
deb676a
97b0cfb
bf4fa43
fd4638d
0e588b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ Examples: | |
returns the list of relations, where target object | ||
matches the specified one | ||
|
||
jimmctl auth relation list --target <target_object> --relation <relation | ||
jimmctl auth relation list --target <target_object> --relation <relation> | ||
returns the list of relations, where target object | ||
and relation match the specified ones | ||
` | ||
|
@@ -544,7 +544,7 @@ func (c *listRelationsCommand) Run(ctxt *cmd.Context) error { | |
Tuple: c.tuple, | ||
PageSize: defaultPageSize, | ||
} | ||
result, err := fetchRelations(client, params, "") | ||
result, err := fetchRelations(client, params) | ||
if err != nil { | ||
return errors.E(err) | ||
} | ||
|
@@ -557,13 +557,14 @@ func (c *listRelationsCommand) Run(ctxt *cmd.Context) error { | |
return nil | ||
} | ||
|
||
func fetchRelations(client *api.Client, params apiparams.ListRelationshipTuplesRequest, continuationToken string) (*apiparams.ListRelationshipTuplesResponse, error) { | ||
func fetchRelations(client *api.Client, params apiparams.ListRelationshipTuplesRequest) (*apiparams.ListRelationshipTuplesResponse, error) { | ||
response, err := client.ListRelationshipTuples(¶ms) | ||
if err != nil { | ||
return nil, errors.E(err) | ||
} | ||
if response.ContinuationToken != "" { | ||
response1, err := fetchRelations(client, params, response.ContinuationToken) | ||
params.ContinuationToken = response.ContinuationToken | ||
response1, err := fetchRelations(client, params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (suggestion) Now that you're fixing this, can you please also refactor it and get rid of the recursive calls to We have done this kind of loop before. You can just replicate it. |
||
if err != nil { | ||
return nil, errors.E(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (suggestion) Can you please add an error message to this, like: return nil, errors.E(err, "failed to fetch list of relationship tuples") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'd caution against this because it would hide the underlying error. JIMM's error package is very poor in that it doesn't provide a clean way of masking or surfacing the underlying error. So here I think the best thing to do would be
We'll need to improve it in the future but for now consider where you want to mask errors and where you want to present them to the user. |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,20 +347,10 @@ func (s *relationSuite) TestListRelations(c *gc.C) { | |
// alice is superuser | ||
bClient := jimmtest.NewUserSessionLogin(c, "alice") | ||
|
||
groups := []string{"group-1", "group-2", "group-3"} | ||
for _, group := range groups { | ||
_, err := cmdtesting.RunCommand(c, cmd.NewAddGroupCommandForTesting(s.ClientStore(), bClient), group) | ||
c.Assert(err, gc.IsNil) | ||
} | ||
|
||
relations := []apiparams.RelationshipTuple{{ | ||
Object: "user-" + env.users[0].Name, | ||
Relation: "member", | ||
TargetObject: "group-group-1", | ||
}, { | ||
Object: "user-" + env.users[1].Name, | ||
Relation: "member", | ||
TargetObject: "group-group-2", | ||
}, { | ||
Object: "group-group-2#member", | ||
Relation: "member", | ||
|
@@ -378,11 +368,38 @@ func (s *relationSuite) TestListRelations(c *gc.C) { | |
Relation: "administrator", | ||
TargetObject: "applicationoffer-" + env.controllers[0].Name + ":" + env.applicationOffers[0].Model.OwnerIdentityName + "/" + env.applicationOffers[0].Model.Name + "." + env.applicationOffers[0].Name, | ||
}} | ||
|
||
tabularOutput := `Object Relation Target Object | ||
user-admin administrator controller-jimm | ||
[email protected] administrator controller-jimm | ||
[email protected] member group-group-1 | ||
group-group-2#member member group-group-3 | ||
group-group-3#member administrator controller-test-controller-1 | ||
group-group-1#member administrator model-test-controller-1:[email protected]/test-model-1 | ||
[email protected] administrator applicationoffer-test-controller-1:[email protected]/test-model-1.testoffer1` | ||
|
||
for i := 0; i < cmd.DefaultPageSize+1; i++ { | ||
kian99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
groupName := fmt.Sprintf("group-%d", i) | ||
_, err := cmdtesting.RunCommand(c, cmd.NewAddGroupCommandForTesting(s.ClientStore(), bClient), groupName) | ||
c.Assert(err, gc.IsNil) | ||
|
||
tabularOutput += fmt.Sprintf("\[email protected] member group-%-72s", groupName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How come the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The output has whitespace after each line to match the length of the longest row. 72 is a hard-coded diff between the length of this string without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe leave a comment to that effect, if someone were to add a new relation that increases/remove a relation and decreases the longest row, that will be annoying to debug. |
||
relations = append(relations, apiparams.RelationshipTuple{ | ||
Object: "user-" + env.users[1].Name, | ||
Relation: "member", | ||
TargetObject: "group-" + groupName, | ||
}) | ||
} | ||
|
||
for _, relation := range relations { | ||
_, err := cmdtesting.RunCommand(c, cmd.NewAddRelationCommandForTesting(s.ClientStore(), bClient), relation.Object, relation.Relation, relation.TargetObject) | ||
c.Assert(err, gc.IsNil) | ||
} | ||
|
||
context, err := cmdtesting.RunCommand(c, cmd.NewListRelationsCommandForTesting(s.ClientStore(), bClient), "--format", "tabular") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(cmdtesting.Stdout(context), gc.Equals, tabularOutput) | ||
|
||
expectedJSONData, err := json.Marshal(append( | ||
[]apiparams.RelationshipTuple{{ | ||
Object: "user-admin", | ||
|
@@ -396,6 +413,10 @@ func (s *relationSuite) TestListRelations(c *gc.C) { | |
relations..., | ||
)) | ||
c.Assert(err, gc.IsNil) | ||
context, err = cmdtesting.RunCommand(c, cmd.NewListRelationsCommandForTesting(s.ClientStore(), bClient), "--format", "json") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(strings.TrimRight(cmdtesting.Stdout(context), "\n"), gc.Equals, string(expectedJSONData)) | ||
|
||
expectedYAMLData, err := yaml.Marshal(append( | ||
[]apiparams.RelationshipTuple{{ | ||
Object: "user-admin", | ||
|
@@ -409,30 +430,9 @@ func (s *relationSuite) TestListRelations(c *gc.C) { | |
relations..., | ||
)) | ||
c.Assert(err, gc.IsNil) | ||
|
||
context, err := cmdtesting.RunCommand(c, cmd.NewListRelationsCommandForTesting(s.ClientStore(), bClient), "--format", "json") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(strings.TrimRight(cmdtesting.Stdout(context), "\n"), gc.Equals, string(expectedJSONData)) | ||
|
||
context, err = cmdtesting.RunCommand(c, cmd.NewListRelationsCommandForTesting(s.ClientStore(), bClient)) | ||
c.Assert(err, gc.IsNil) | ||
c.Assert(cmdtesting.Stdout(context), gc.Equals, string(expectedYAMLData)) | ||
|
||
context, err = cmdtesting.RunCommand(c, cmd.NewListRelationsCommandForTesting(s.ClientStore(), bClient), "--format", "tabular") | ||
c.Assert(err, gc.IsNil) | ||
c.Assert( | ||
cmdtesting.Stdout(context), | ||
gc.Equals, | ||
`Object Relation Target Object | ||
user-admin administrator controller-jimm | ||
[email protected] administrator controller-jimm | ||
[email protected] member group-group-1 | ||
[email protected] member group-group-2 | ||
group-group-2#member member group-group-3 | ||
group-group-3#member administrator controller-test-controller-1 | ||
group-group-1#member administrator model-test-controller-1:[email protected]/test-model-1 | ||
[email protected] administrator applicationoffer-test-controller-1:[email protected]/test-model-1.testoffer1`, | ||
) | ||
} | ||
|
||
// TODO: remove boilerplate of env setup and use initialiseEnvironment | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I checked there are still a few more instances that point to
sysdeps
. Can you please update them as well?