-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And disallow remote reads and reads of directories above the working directory by default.
- Loading branch information
Showing
9 changed files
with
150 additions
and
4 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
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,51 @@ | ||
package runn | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
type scopes struct { | ||
readParent bool | ||
readRemote bool | ||
mu sync.RWMutex | ||
} | ||
|
||
const ( | ||
ScopeAllowReadParent = "read:parent" | ||
ScopeAllowReadRemote = "read:remote" | ||
ScopeDenyReadParent = "!read:parent" | ||
ScopeDenyReadRemote = "!read:remote" | ||
) | ||
|
||
var ErrInvalidScope = errors.New("invalid scope") | ||
|
||
var globalScopes = &scopes{ | ||
readParent: false, | ||
readRemote: false, | ||
} | ||
|
||
func setScopes(scopes ...string) error { | ||
globalScopes.mu.Lock() | ||
defer globalScopes.mu.Unlock() | ||
for _, s := range scopes { | ||
splitted := strings.Split(strings.TrimSpace(s), ",") | ||
for _, ss := range splitted { | ||
switch ss { | ||
case ScopeAllowReadParent: | ||
globalScopes.readParent = true | ||
case ScopeAllowReadRemote: | ||
globalScopes.readRemote = true | ||
case ScopeDenyReadParent: | ||
globalScopes.readParent = false | ||
case ScopeDenyReadRemote: | ||
globalScopes.readRemote = false | ||
case "": | ||
default: | ||
return ErrInvalidScope | ||
} | ||
} | ||
} | ||
return nil | ||
} |