// SetupAuth sets the client's authMode. It tries from the environment first if we're on android or in dev mode, and then from the client configuration. func (c *Client) SetupAuth() error { // env var takes precedence, but only if we're in dev mode or on android. // Too risky otherwise. if android.OnAndroid() || os.Getenv("CAMLI_DEV_CAMLI_ROOT") != "" { authMode, err := auth.FromEnv() if err == nil { c.authMode = authMode return nil } if err != auth.ErrNoAuth { return fmt.Errorf("Could not set up auth from env var CAMLI_AUTH: %v", err) } } if c.server == "" { return fmt.Errorf("No server defined for this client: can not set up auth.") } authConf := serverAuth(c.server) if authConf == "" { c.authErr = fmt.Errorf("could not find auth key for server %q in config, defaulting to no auth", c.server) c.authMode = auth.None{} return nil } var err error c.authMode, err = auth.FromConfig(authConf) return err }
func (c *Client) SetupAuthFromConfig(conf jsonconfig.Obj) (err error) { value, ok := conf["auth"] authString := "" if ok { authString, ok = value.(string) c.authMode, err = auth.FromConfig(authString) } else { c.authMode, err = auth.FromEnv() } return err }
// SetupAuth sets the client's authMode from the client // configuration file or from the environment. func (c *Client) SetupAuth() error { if flagServer != "" { // If using an explicit blobserver, don't use auth // configured from the config file, so we don't send // our password to a friend's blobserver. var err error c.authMode, err = auth.FromEnv() if err == auth.ErrNoAuth { log.Printf("Using explicit --server parameter; not using config file auth, and no auth mode set in environment") } return err } configOnce.Do(parseConfig) var err error if config == nil || config.auth == "" { c.authMode, err = auth.FromEnv() } else { c.authMode, err = auth.FromConfig(config.auth) } return err }
func main() { flag.Parse() _, err := auth.FromEnv() if err != nil { log.Fatal(err) } ws := webserver.New() ws.HandleFunc("/", handleRoot) ws.HandleFunc("/camli/sig/", handleCamliSig) ws.Serve() }
// SetupAuthFromConfig sets the Client's authMode using the "auth" key in conf // if found, or the environment otherwise. func (c *Client) SetupAuthFromConfig(conf jsonconfig.Obj) error { // TODO(mpl): leaving this one alone for now because it's used by remote as well. // See about converting/removing it later. var err error value, ok := conf["auth"] authString := "" if ok { authString, ok = value.(string) c.authMode, err = auth.FromConfig(authString) } else { c.authMode, err = auth.FromEnv() } return err }
// SetupAuth sets the client's authMode. It tries from the environment first if we're on android or in dev mode, and then from the client configuration. func (c *Client) SetupAuth() error { if c.paramsOnly { if c.authMode != nil { if _, ok := c.authMode.(*auth.None); !ok { return nil } } return errors.New("client: paramsOnly set; auth should not be configured from config or env vars.") } // env var takes precedence, but only if we're in dev mode or on android. // Too risky otherwise. if android.OnAndroid() || env.IsDev() || configDisabled { authMode, err := auth.FromEnv() if err == nil { c.authMode = authMode return nil } if err != auth.ErrNoAuth { return fmt.Errorf("Could not set up auth from env var CAMLI_AUTH: %v", err) } } if c.server == "" { return fmt.Errorf("No server defined for this client: can not set up auth.") } authConf := serverAuth(c.server) if authConf == "" { c.authErr = fmt.Errorf("could not find auth key for server %q in config, defaulting to no auth", c.server) c.authMode = auth.None{} return nil } var err error c.authMode, err = auth.FromConfig(authConf) return err }