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

Create function to define valid set of scopes for each resource #5558

Open
wants to merge 9 commits into
base: llb-normalized-grants
Choose a base branch
from

Conversation

dkanney
Copy link
Collaborator

@dkanney dkanney commented Feb 20, 2025

No description provided.

@dkanney dkanney requested review from elimt and bosorawis February 20, 2025 23:11
@dkanney dkanney self-assigned this Feb 20, 2025
@dkanney dkanney requested a review from a team as a code owner February 20, 2025 23:11
@@ -38,3 +44,20 @@ var Map = map[string]Type{
Org.String(): Org,
Project.String(): Project,
}

// AllowedIn returns the set of Scopes a known Resource type is allowed in.
func AllowedIn(ctx context.Context, r resource.Type) ([]Type, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe we wanted this to live under the resource package as a resource.Type method:

Copy link
Member

Choose a reason for hiding this comment

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

There are also some other methods in the resource package that are not methods on resource.Type. We wanted to update those as well. These methods: Parent, HasChildTypes & TopLevelType

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agh, I forgot >.< sorry -- added: a4bafe1

Copy link
Member

@elimt elimt Feb 26, 2025

Choose a reason for hiding this comment

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

Do you plan on moving AllowedIn to boundary/internal/types/resource/resource.go? That is where we wanted this to live so resources can just check which scopes they are allowed in with resource.AllowedIn. Not under the scope

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If AllowedIn() lived in resource package, we'd have to declare a new scope domain type in the resource package. I didn't like the idea of declaring redundant types (ScopeType and Scope), hence this function living in the scope package.

scope indirectly imports the resource package as well, so we can't import scope.Type into the resource package

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

I just remembered something, there's a comment in internal/types/resource/resource.go that talks about the places that need to be updated when a new resource type is added. Do we want to add something there to mention the new AllowedIn function?

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

LGTM, I think golangci-lint has a bad cache again, don't worry about those errors.

…ceType`

This allows us to call scope.AllowedIn() in one place vs in each implementation of `validScopeTypes`
@dkanney dkanney force-pushed the dkanney-define-valid-set-of-scopes-for-each-resource branch from ef5ae30 to b46ccd7 Compare February 24, 2025 20:17
@@ -142,22 +143,22 @@ var Map = map[string]Type{

// Parent returns the parent type for a given type; if there is no parent, it
// returns the incoming type
func Parent(in Type) Type {
switch in {
func (r Type) Parent() Type {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will also need to update the test in resource_test.go to update all the function signature changes in here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated: 25fd85d

@dkanney dkanney force-pushed the dkanney-define-valid-set-of-scopes-for-each-resource branch from b46ccd7 to ed329f3 Compare February 26, 2025 14:31
@@ -38,3 +44,20 @@ var Map = map[string]Type{
Org.String(): Org,
Project.String(): Project,
}

// AllowedIn returns the set of Scopes a known Resource type is allowed in.
func AllowedIn(ctx context.Context, r resource.Type) ([]Type, error) {
Copy link
Member

@elimt elimt Feb 26, 2025

Choose a reason for hiding this comment

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

Do you plan on moving AllowedIn to boundary/internal/types/resource/resource.go? That is where we wanted this to live so resources can just check which scopes they are allowed in with resource.AllowedIn. Not under the scope

@@ -57,8 +57,8 @@ func (a *authAccount) VetForWrite(ctx context.Context, r db.Reader, opType db.Op
return nil
}

func (a *authAccount) validScopeTypes() []scope.Type {
return []scope.Type{scope.Global, scope.Org}
func (a *authAccount) getResourceType() resource.Type {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we had to update this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Technically no -- I previously had validScopeTypes() return scope.AllowedIn(<some resource type>). I'm fine with either change - can revert if that change would be easier to understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants