MCPcopy
hub / github.com/perkeep/perkeep / SetupAuth

Method SetupAuth

pkg/client/config.go:310–345  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

308
309// 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.
310func (c *Client) SetupAuth() error {
311 if c.noExtConfig {
312 if c.authMode != nil {
313 if _, ok := c.authMode.(*auth.None); !ok {
314 return nil
315 }
316 }
317 return errors.New("client: noExtConfig set; auth should not be configured from config or env vars")
318 }
319 // env var takes precedence, but only if we're in dev mode or on android.
320 // Too risky otherwise.
321 if android.OnAndroid() ||
322 env.IsDev() ||
323 configDisabled {
324 authMode, err := auth.FromEnv()
325 if err == nil {
326 c.authMode = authMode
327 return nil
328 }
329 if err != auth.ErrNoAuth {
330 return fmt.Errorf("Could not set up auth from env var CAMLI_AUTH: %v", err)
331 }
332 }
333 if c.server == "" {
334 return fmt.Errorf("no server defined for this client: can not set up auth")
335 }
336 authConf := serverAuth(c.server)
337 if authConf == "" {
338 c.authErr = fmt.Errorf("could not find auth key for server %q in config, defaulting to no auth", c.server)
339 c.authMode = auth.None{}
340 return nil
341 }
342 var err error
343 c.authMode, err = auth.FromConfig(authConf)
344 return err
345}
346
347// serverAuth returns the auth scheme for server from the config, or the empty string if the server was not found in the config.
348func serverAuth(server string) string {

Callers 5

NewFunction · 0.95
newClientFunction · 0.80
storageFromParamMethod · 0.80
syncAllMethod · 0.80
newClientFunction · 0.80

Calls 5

OnAndroidFunction · 0.92
IsDevFunction · 0.92
FromEnvFunction · 0.92
FromConfigFunction · 0.92
serverAuthFunction · 0.85

Tested by

no test coverage detected