本文整理汇总了Golang中camlistore/org/pkg/auth.FromConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang FromConfig函数的具体用法?Golang FromConfig怎么用?Golang FromConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FromConfig函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetupAuth
// 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
}
示例2: checkValidAuth
func (config *Config) checkValidAuth() error {
authConfig := config.OptionalString("auth", "")
mode, err := auth.FromConfig(authConfig)
if err == nil {
auth.SetMode(mode)
}
return err
}
示例3: newOwnerAuth
func newOwnerAuth(arg string) (auth.AuthMode, error) {
m := &ownerAuth{}
if arg != "" {
f, err := auth.FromConfig(arg)
if err != nil {
return nil, err
}
m.fallback = f
}
return m, nil
}
示例4: SetupAuthFromConfig
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
}
示例5: SetupAuthFromConfig
// 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
}
示例6: SetupAuth
// 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
}
示例7: SetupAuth
// 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
}
示例8: SetupAuthFromString
// SetupAuthFromString configures the clients authentication mode from
// an explicit auth string.
func (c *Client) SetupAuthFromString(a string) error {
// TODO(mpl): review the one using that (pkg/blobserver/remote/remote.go)
var err error
c.authMode, err = auth.FromConfig(a)
return err
}
示例9: checkValidAuth
func (config *Config) checkValidAuth() error {
authConfig := config.OptionalString("auth", "")
_, err := auth.FromConfig(authConfig)
return err
}