Skip to content

Commit

Permalink
shared/entity: Export (entity.Type).RequiresProject method.
Browse files Browse the repository at this point in the history
This is required for checking if a project=<project-name> argument
is required when adding a permission to a group.

Signed-off-by: Mark Laing <[email protected]>
  • Loading branch information
markylaing committed Feb 27, 2024
1 parent 4505203 commit ac50d77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions shared/entity/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func (t Type) Validate() error {
return nil
}

// requiresProject returns true if an entity of the Type can only exist within the context of a project. Operations and
// RequiresProject returns true if an entity of the Type can only exist within the context of a project. Operations and
// warnings may still be project specific but it is not an absolute requirement.
func (t Type) requiresProject() (bool, error) {
func (t Type) RequiresProject() (bool, error) {
err := t.Validate()
if err != nil {
return false, err
Expand Down Expand Up @@ -180,7 +180,7 @@ func (t Type) nRequiredPathArguments() (int, error) {
//
// Warning: All arguments to this function will be URL encoded. They must not be URL encoded before calling this method.
func (t Type) URL(projectName string, location string, pathArguments ...string) (*api.URL, error) {
requiresProject, err := t.requiresProject()
requiresProject, err := t.RequiresProject()
if err != nil {
return nil, fmt.Errorf("Failed to check if entity type %q is project specific: %w", t, err)
}
Expand Down Expand Up @@ -347,7 +347,7 @@ entityTypeLoop:
return "", "", "", nil, fmt.Errorf("Failed to match entity URL %q", u.String())
}

requiresProject, _ := entityType.requiresProject()
requiresProject, _ := entityType.RequiresProject()
projectName = ""
if requiresProject {
projectName = u.Query().Get("project")
Expand Down
2 changes: 1 addition & 1 deletion shared/entity/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestURL(t *testing.T) {

assert.Equal(t, tt.expectedErr, actualErr)

requiresProject, err := actualEntityType.requiresProject()
requiresProject, err := actualEntityType.RequiresProject()
assert.NoError(t, err)
if u.Query().Get("project") != "" || !requiresProject {
// Assert that we can convert back to the same value.
Expand Down

0 comments on commit ac50d77

Please sign in to comment.