-
Notifications
You must be signed in to change notification settings - Fork 53
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
Added validator for folder permissions #1824
base: main
Are you sure you want to change the base?
Conversation
if !strings.HasPrefix(b.Config().Workspace.ResourcePath, rootPath) && | ||
!libraries.IsVolumesPath(b.Config().Workspace.ResourcePath) { | ||
paths = append(paths, b.Config().Workspace.ResourcePath) | ||
} |
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.
With the logic expanded like this, it can be a loop on the different paths.
for i, p := range paths { | ||
g.Go(func() error { | ||
diags, err, _ := syncGroup.Do(p, func() (any, error) { | ||
diags := checkFolderPermission(ctx, b, p) |
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.
These paths are different by design so there won't be reuse at this level. I figured you could initialize the sync group here and pass it to checkFolderPermissions
. Then inside of getClosestExistingObject
, you can use syncGroup.Do()
to make sure you're only doing a single call for any given path at any level.
Those calls will be done multiple times in the current approach.
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.
On second thought, this will apply only to cases where the different paths are not a child of the root. This should be infrequent enough that we can skip caching altogether.
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidateFolderPermissions(t *testing.T) { |
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.
Please add suffix to capture the intent; I believe it is to test what happens if the root path doesn't exist yet.
require.Empty(t, diags) | ||
} | ||
|
||
func TestValidateFolderPermissionsDifferentCount(t *testing.T) { |
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.
This is no longer about a different count.
require.Equal(t, diag.Warning, diags[1].Severity) | ||
} | ||
|
||
func TestNoRootFolder(t *testing.T) { |
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.
Missing prefix: TestValidateFolderPermissions
if perm.UserName != "" { | ||
sb.WriteString(fmt.Sprintf("- level: %s\n user_name: %s\n", perm.Level, perm.UserName)) | ||
continue | ||
} |
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.
Shouldn't this use p.String()
defined in permission.go
?
} | ||
|
||
return fmt.Sprintf("level: %s", p.Level) | ||
} |
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.
Also see comment below; if this is not used it can be removed.
Co-authored-by: Pieter Noordhuis <[email protected]>
Co-authored-by: Pieter Noordhuis <[email protected]>
Changes
This validator checks permissions defined in top-level bundle config and permissions set in workspace and raises the warning if they don't match
Tests