-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satellite/wasm: support restricting full access grants to paths
Change-Id: Id6d4fa41db068d32e7c0d542d9d8805fba927fc6
- Loading branch information
Showing
7 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (C) 2020 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package consolewasm | ||
|
||
import ( | ||
"strings" | ||
|
||
"storj.io/common/grant" | ||
) | ||
|
||
// RestrictGrant restricts an access grant with the permissions and paths and returns a new access grant. | ||
func RestrictGrant(accessGrant string, paths []string, permission Permission) (string, error) { | ||
access, err := grant.ParseAccess(accessGrant) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
prefixes := make([]grant.SharePrefix, 0, len(paths)) | ||
for _, path := range paths { | ||
parts := strings.SplitN(path, "/", 2) | ||
prefix := grant.SharePrefix{Bucket: parts[0]} | ||
if len(parts) > 1 { | ||
prefix.Prefix = parts[1] | ||
} | ||
prefixes = append(prefixes, prefix) | ||
} | ||
|
||
restricted, err := access.Restrict(grant.Permission(permission), prefixes...) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return restricted.Serialize() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters