Add 'build/' from commit '555b039609a3c8700c27767c255fdfe00eb42063'
[arvados.git] / services / keep-web / anonymous.go
index bfc716f2b2b865d9a12577bcca41812e7252f4e9..15a98c2f361ef62f2ddfd313da5d5402ea718c56 100644 (file)
@@ -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. Multiple anonymous tokens can be provided by using this flag 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.")
 }