Add 'tools/arvbox/' from commit 'd3d368758db1f4a9fa5b89f77b5ee61d68ef5b72'
[arvados.git] / services / keep-web / anonymous.go
1 package main
2
3 import (
4         "flag"
5         "fmt"
6         "os"
7         "strconv"
8 )
9
10 var anonymousTokens tokenSet
11
12 type tokenSet []string
13
14 func (ts *tokenSet) Set(s string) error {
15         v, err := strconv.ParseBool(s)
16         if v && len(*ts) == 0 {
17                 *ts = append(*ts, os.Getenv("ARVADOS_API_TOKEN"))
18         } else if !v {
19                 *ts = (*ts)[:0]
20         }
21         return err
22 }
23
24 func (ts *tokenSet) String() string {
25         return fmt.Sprintf("%v", len(*ts) > 0)
26 }
27
28 func (ts *tokenSet) IsBoolFlag() bool {
29         return true
30 }
31
32 func init() {
33         flag.Var(&anonymousTokens, "allow-anonymous",
34                 "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.")
35 }