Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #69 from vania-pooh/master
Browse files Browse the repository at this point in the history
Flag to explicitly enabled only authenticated access
  • Loading branch information
vania-pooh authored Jan 7, 2024
2 parents 7f3f77b + cd27f5d commit 62c757d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
10 changes: 8 additions & 2 deletions docs/cli-flags.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
== CLI Flags

The following flags are supported by ```ggr-ui``` command:
```
----
-authenticated-access-only
Show statistics about all hosts only when credentials are provided
-grace-period duration
graceful shutdown period (default 5m0s)
-guests-allowed
Allow guest (unauthenticated) users to access the grid
-guests-quota string
Which quota file to use for guests (default "guest")
-limit int
simultaneous http requests (default 10)
-listen string
Expand All @@ -16,4 +22,4 @@ The following flags are supported by ```ggr-ui``` command:
request timeout (default 30s)
-version
Show version and exit
```
----
19 changes: 17 additions & 2 deletions ggr-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func status(w http.ResponseWriter, r *http.Request) {
lock.RLock()
defer lock.RUnlock()
user, remote := info(r)
quota, ok := hosts[user]
quota, ok := userHosts(user)
if !ok {
log.Printf("[STATUS] [Unknown quota user: %s] [%s]", user, remote)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
Expand Down Expand Up @@ -127,6 +127,21 @@ func status(w http.ResponseWriter, r *http.Request) {
}
}

func userHosts(user string) (map[string]*config.Host, bool) {
if authenticatedAccessOnly {
quota, ok := hosts[user]
return quota, ok
}

ret := make(map[string]*config.Host)
for _, quota := range hosts {
for sum, host := range quota {
ret[sum] = host
}
}
return ret, true
}

func (cur Status) Add(sum string, m map[string]interface{}) {
for k, v := range m {
switch v.(type) {
Expand Down Expand Up @@ -171,7 +186,7 @@ func proxyWS(p string) func(wsconn *websocket.Conn) {
}
sum := path[head:tail]
lock.RLock()
quota, ok := hosts[user]
quota, ok := userHosts(user)
lock.RUnlock()
if !ok {
log.Printf("[WEBSOCKET] [Unknown quota user: %s] [%s]", user, remote)
Expand Down
18 changes: 10 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ var (
)

var (
listen string
timeout time.Duration
responseTime time.Duration
limit int
quotaDir string
gracePeriod time.Duration
guestAccessAllowed bool
guestUserName string
listen string
timeout time.Duration
responseTime time.Duration
limit int
quotaDir string
gracePeriod time.Duration
authenticatedAccessOnly bool
guestAccessAllowed bool
guestUserName string

version bool
gitRevision = "HEAD"
Expand Down Expand Up @@ -81,6 +82,7 @@ func configure() error {
}

func init() {
flag.BoolVar(&authenticatedAccessOnly, "authenticated-access-only", false, "Show statistics about all hosts only when credentials are provided")
flag.BoolVar(&guestAccessAllowed, "guests-allowed", false, "Allow guest (unauthenticated) users to access the grid")
flag.StringVar(&guestUserName, "guests-quota", "guest", "Which quota file to use for guests")
flag.StringVar(&listen, "listen", ":8888", "host and port to listen to")
Expand Down

0 comments on commit 62c757d

Please sign in to comment.