X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7bf5f28cec1ff7be1e66925c3815c253989f9eb1..74e4c93a1f333352914314b3a53172a0164a20e9:/services/keep-web/anonymous.go diff --git a/services/keep-web/anonymous.go b/services/keep-web/anonymous.go index 85ea1c6933..15a98c2f36 100644 --- a/services/keep-web/anonymous.go +++ b/services/keep-web/anonymous.go @@ -3,22 +3,33 @@ package main import ( "flag" "fmt" + "os" + "strconv" ) var anonymousTokens tokenSet type tokenSet []string -func (ts *tokenSet) Set(t string) error { - *ts = append(*ts, t) - return nil +func (ts *tokenSet) Set(s string) error { + v, err := strconv.ParseBool(s) + if v && len(*ts) == 0 { + *ts = append(*ts, os.Getenv("ARVADOS_API_TOKEN")) + } else if !v { + *ts = (*ts)[:0] + } + return err } func (ts *tokenSet) String() string { - return fmt.Sprintf("%+v", (*ts)[:]) + return fmt.Sprintf("%v", len(*ts) > 0) +} + +func (ts *tokenSet) IsBoolFlag() bool { + return true } func init() { - flag.Var(&anonymousTokens, "anonymous-token", - "API token to try when none of the tokens provided in an HTTP request succeed in reading the desired collection. If this flag is used more than once, each token will be attempted in turn until one works.") + flag.Var(&anonymousTokens, "allow-anonymous", + "Serve public data to anonymous clients. Try the token supplied in the ARVADOS_API_TOKEN environment variable when none of the tokens provided in an HTTP request succeed in reading the desired collection.") }