-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): hosts are now configured through API
Hosts are no longer provided in config but they are provided through the api BREAKING CHANGE: config no longer accepts hosts
- Loading branch information
Showing
7 changed files
with
160 additions
and
241 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gnur/tobab" | ||
matcher "github.com/ryanuber/go-glob" | ||
) | ||
|
||
func hasAccess(user, host string, cfg tobab.Config) bool { | ||
h, ok := cfg.Hosts[host] | ||
if !ok { | ||
return false | ||
} | ||
|
||
if h.Public { | ||
return true | ||
} else if user == "" { | ||
return false | ||
} | ||
|
||
for _, g := range cfg.Globs { | ||
if matcher.Glob(g.Matcher, user) { | ||
if contains(h.AllowedGlobs, g.Name) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} | ||
func allowAdmin(user string, adminGlobs []tobab.Glob) bool { | ||
|
||
func contains(s []string, e string) bool { | ||
for _, a := range s { | ||
if strings.EqualFold(a, e) { | ||
for _, g := range adminGlobs { | ||
if g.Match(user) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func allowAdmin(user string, cfg tobab.Config) bool { | ||
|
||
for _, globName := range cfg.AdminGlobs { | ||
for _, g := range cfg.Globs { | ||
if g.Name != globName { | ||
continue | ||
} | ||
if matcher.Glob(g.Matcher, user) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.