Skip to content
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

CSS-9830 patch group entitlements #1318

Merged

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Aug 15, 2024

Description

This PR builds on #1315, either view the last commit here or wait for the previous PR to land before reviewing.

This PR implements PatchGroupEntitlements to update the relations (i.e. entitlements) for a group. The most notable part of this PR is the integration test. To actually list relationship tuples, a resource needs to exist in JIMM's database. In the test I've opted to use a model as the resource to relate a group to.

In order to create a model in an integration test we would call jimm's AddModel() method but because the Rebac-admin test suite does not spin up a Juju controller this is not possible. So instead I've opted to use the testing functionality used in internal/jimm where a YAML defined string is parsed and used to create database resources. This is very convenient because creating a model requires that all the following database entries also exist controller/cloud/cloud-credentials.

The final hurdle to cater for the above is figuring out how to pass a GoCheck.C object into the existing methods for parsing and applying the yaml environment which currently accepts a QuickTest object. I've switched out the qt struct in favor of our Tester interface which both Gocheck and Quicktest implement.

Completes CSS-9830

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

@kian99 kian99 requested a review from a team as a code owner August 15, 2024 14:54
@kian99 kian99 changed the title Css 9830 patch group entitlements CSS-9830 patch group entitlements Aug 15, 2024
@kian99 kian99 force-pushed the CSS-9830-patch-group-entitlements branch from cd1e25d to f145d67 Compare August 22, 2024 08:53
pkulik0
pkulik0 previously approved these changes Aug 22, 2024
ale8k
ale8k previously approved these changes Aug 22, 2024
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm bar the slice of errs

I think a custom error type (which is capable of having a slice of errs inside) to be used in all rebac_admin methods where multiple errors can be returned.

Let's do that plz, and then handler can cast err into that type and extract them into an error DTO.

internal/rebac_admin/groups_integration_test.go Outdated Show resolved Hide resolved
}, Op: resources.GroupEntitlementsPatchItemOpAdd},
}
_, err = groupSvc.PatchGroupEntitlements(ctx, newUUID.String(), operationsWithInvalidTag)
c.Assert(err, qt.ErrorMatches, `\"invalidType-foo\" is not a valid tag\n\"invalidType2-foo1\" is not a valid tag`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like us appending errors and sending them back in a line with \n, it feels weird... What if we wanted a clear response and formatted in json array? I'm guessing this service will be run in a handler and then perhaps it can format the error based on \n but idk... Perhaps a custom error type which can be cast by the caller to get a nice slice of errs out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a struct that we can adapt in the future to do different things. Right now I don't know that we have a format for returning a list of errors. When that is defined we can modify the struct. Let me know what you think.

alesstimec
alesstimec previously approved these changes Aug 23, 2024
@@ -117,8 +117,10 @@ func (c *comboToken) MarshalToken() (string, error) {
func (c *comboToken) UnmarshalToken(token string) error {
out, err := base64.StdEncoding.DecodeString(token)
if err != nil {
return fmt.Errorf("marshal entitlement token: %w", err)
return fmt.Errorf("unmarshal entitlement token: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: failed to decode the entitlement token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go with "failed to decode token"


return json.Unmarshal(out, c)
if err := json.Unmarshal(out, c); err != nil {
return fmt.Errorf("failed to unmarshal combo token: %w", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: failed to unmarshal the entitlement token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to put "entitlement" in the error string because someone coming to this function later might be confused why we're saying entitlement token when the struct is called comboToken. So I'll just tweak the message to "failed to unmarshal token"

internal/rebac_admin/groups.go Outdated Show resolved Hide resolved
@kian99 kian99 dismissed stale reviews from alesstimec, ale8k, and pkulik0 via 747374b August 23, 2024 08:09

import "errors"

// MultiErr handles cases where multiple errors need to be collected.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty I think this is nicer

@@ -0,0 +1,26 @@
package utils
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also.. should this perhaps live in our errors package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the copyright in a follow-up.
I think it should live here for now because this is specifically for how the rebac-handlers deals with multiple errors.

@kian99 kian99 merged commit adb7aea into canonical:feature-rebac-admin Aug 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants