当前位置: 首页>>代码示例>>Golang>>正文


Golang gophercloud.Authenticate函数代码示例

本文整理汇总了Golang中github.com/rackspace/gophercloud.Authenticate函数的典型用法代码示例。如果您正苦于以下问题:Golang Authenticate函数的具体用法?Golang Authenticate怎么用?Golang Authenticate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Authenticate函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Auth

// Auth returns a valid Auth object for access to openstack services, or
// an error if the authentication couldn't be resolved.
func (c *AccessConfig) Auth() (gophercloud.AccessProvider, error) {
	username := c.Username
	password := c.Password
	project := c.Project
	provider := c.Provider

	if username == "" {
		username = os.Getenv("SDK_USERNAME")
	}
	if password == "" {
		password = os.Getenv("SDK_PASSWORD")
	}
	if project == "" {
		project = os.Getenv("SDK_PROJECT")
	}
	if provider == "" {
		provider = os.Getenv("SDK_PROVIDER")
	}

	authoptions := gophercloud.AuthOptions{
		Username:    username,
		Password:    password,
		AllowReauth: true,
	}

	if project != "" {
		authoptions.TenantName = project
	}

	return gophercloud.Authenticate(provider, authoptions)
}
开发者ID:B-Rich,项目名称:packer,代码行数:33,代码来源:access_config.go

示例2: main

func main() {
	provider, authOptions, err := osutil.AuthOptions()
	if err != nil {
		panic(err)
	}
	_, err = gophercloud.Authenticate(provider, authOptions)
	if err != nil {
		panic(err)
	}
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:10,代码来源:18-osutil-authentication.go

示例3: GetClient

func GetClient(project string, region string, cache_path string) (Client, error) {
	c := Client{}
	cache, err := config.LoadCredCache(cache_path)
	if err != nil {
		fmt.Println("unable to get cache")
		return c, err
	}
	c.cache = cache
	if region == "" {
		region = defaultRegion
	}
	c.region = region
	if c.cache.Rackspace.User == "" || c.cache.Rackspace.APIKey == "" {
		var rack_user string
		var rack_pass string
		fmt.Printf("rackspace user: ")
		_, err = fmt.Scanf("%s", &rack_user)
		if err != nil {
			return c, err
		}
		fmt.Printf("rackspace api key: ")
		_, err = fmt.Scanf("%s", &rack_pass)
		if err != nil {
			return c, err
		}
		c.cache.Rackspace.User = rack_user
		c.cache.Rackspace.APIKey = rack_pass
		c.cache.Save()
		if err != nil {
			return c, err
		}
	}
	ao := gophercloud.AuthOptions{
		Username:    c.cache.Rackspace.User,
		ApiKey:      c.cache.Rackspace.APIKey,
		AllowReauth: true,
	}
	access, err := gophercloud.Authenticate("rackspace-us", ao)
	if err != nil {
		c.cache.Rackspace.User = ""
		c.cache.Rackspace.APIKey = ""
		c.cache.Save()
		return c, err
	}
	ac, err := gophercloud.PopulateApi("rackspace")
	if err != nil {
		return c, err
	}
	client, err := gophercloud.ServersApi(access, ac)
	if err != nil {
		return c, err
	}
	c.client = client
	return c, nil
}
开发者ID:philips,项目名称:coreup,代码行数:55,代码来源:rackspace.go

示例4: Auth

// Auth returns a valid Auth object for access to openstack services, or
// an error if the authentication couldn't be resolved.
func (c *AccessConfig) Auth() (gophercloud.AccessProvider, error) {
	c.Username = common.ChooseString(c.Username, os.Getenv("SDK_USERNAME"), os.Getenv("OS_USERNAME"))
	c.Password = common.ChooseString(c.Password, os.Getenv("SDK_PASSWORD"), os.Getenv("OS_PASSWORD"))
	c.ApiKey = common.ChooseString(c.ApiKey, os.Getenv("SDK_API_KEY"))
	c.Project = common.ChooseString(c.Project, os.Getenv("SDK_PROJECT"), os.Getenv("OS_TENANT_NAME"))
	c.Provider = common.ChooseString(c.Provider, os.Getenv("SDK_PROVIDER"), os.Getenv("OS_AUTH_URL"))
	c.RawRegion = common.ChooseString(c.RawRegion, os.Getenv("SDK_REGION"), os.Getenv("OS_REGION_NAME"))
	c.TenantId = common.ChooseString(c.TenantId, os.Getenv("OS_TENANT_ID"))

	// OpenStack's auto-generated openrc.sh files do not append the suffix
	// /tokens to the authentication URL. This ensures it is present when
	// specifying the URL.
	if strings.Contains(c.Provider, "://") && !strings.HasSuffix(c.Provider, "/tokens") {
		c.Provider += "/tokens"
	}

	authoptions := gophercloud.AuthOptions{
		AllowReauth: true,

		ApiKey:     c.ApiKey,
		TenantId:   c.TenantId,
		TenantName: c.Project,
		Username:   c.Username,
		Password:   c.Password,
	}

	default_transport := &http.Transport{}

	if c.Insecure {
		cfg := new(tls.Config)
		cfg.InsecureSkipVerify = true
		default_transport.TLSClientConfig = cfg
	}

	// For corporate networks it may be the case where we want our API calls
	// to be sent through a separate HTTP proxy than external traffic.
	if c.ProxyUrl != "" {
		url, err := url.Parse(c.ProxyUrl)
		if err != nil {
			return nil, err
		}

		// The gophercloud.Context has a UseCustomClient method which
		// would allow us to override with a new instance of http.Client.
		default_transport.Proxy = http.ProxyURL(url)
	}

	if c.Insecure || c.ProxyUrl != "" {
		http.DefaultTransport = default_transport
	}

	return gophercloud.Authenticate(c.Provider, authoptions)
}
开发者ID:JNPRAutomate,项目名称:packer,代码行数:55,代码来源:access_config.go

示例5: newOpenStack

func newOpenStack(cfg Config) (*OpenStack, error) {
	os := OpenStack{
		provider: cfg.Global.AuthUrl,
		authOpt:  cfg.toAuthOptions(),
		region:   cfg.Global.Region,
	}

	access, err := gophercloud.Authenticate(os.provider, os.authOpt)
	os.access = access

	return &os, err
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:12,代码来源:openstack.go

示例6: main

func main() {
	provider, username, password, _ := getCredentials()

	_, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username: username,
			Password: password,
		},
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:14,代码来源:01-authentication.go

示例7: createGopherCtx

func (rax *RaxCloud) createGopherCtx() (err error) {
	var (
		provider    string
		authOptions gophercloud.AuthOptions
		apiCriteria gophercloud.ApiCriteria
		access      *gophercloud.Access
		csp         gophercloud.CloudServersProvider
	)

	// Create our auth options set by the user's environment
	provider, authOptions, err = getAuthOptions()
	if err != nil {
		return err
	}

	// Set our API criteria
	apiCriteria, err = gophercloud.PopulateApi("rackspace-us")
	if err != nil {
		return err
	}

	// Set the region
	apiCriteria.Type = "compute"
	apiCriteria.Region = os.Getenv("OS_REGION_NAME")

	if rax.regionOverride != "" {
		log.Printf("Overriding region set in env with %s", rax.regionOverride)
		apiCriteria.Region = rax.regionOverride
	}

	if apiCriteria.Region == "" {
		return fmt.Errorf("No region set. Please set the OS_REGION_NAME environment variable or use the --region flag.")
	}

	// Attempt to authenticate
	access, err = gophercloud.Authenticate(provider, authOptions)
	if err != nil {
		fmt.Printf("ERROR: %v\n\n\n", err)
		return err
	}

	// Get a CSP ref!
	csp, err = gophercloud.ServersApi(access, apiCriteria)
	if err != nil {
		return err
	}

	rax.gopher = csp
	return nil
}
开发者ID:BillTheBest,项目名称:libswarm,代码行数:50,代码来源:rax.go

示例8: withAPIKeyIdentity

func withAPIKeyIdentity(ar bool, f func(gophercloud.AccessProvider)) {
	provider, username, _, apiKey := getCredentials()
	acc, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username:    username,
			ApiKey:      apiKey,
			AllowReauth: ar,
		},
	)
	if err != nil {
		panic(err)
	}

	f(acc)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:16,代码来源:libargs.go

示例9: withPasswordIdentity

func withPasswordIdentity(ar bool, f func(gophercloud.AccessProvider)) {
	provider, username, password, _ := getCredentials()
	acc, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username:    username,
			Password:    password,
			AllowReauth: ar,
		},
	)
	if err != nil {
		panic(err)
	}

	f(acc)
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:16,代码来源:libargs.go

示例10: Client

// Client() returns a new client for accessing openstack.
//
func (c *Config) Client() (*OpenstackClient, error) {

	if v := os.Getenv("OS_AUTH_URL"); v != "" {
		c.Auth = v
	}
	if v := os.Getenv("OS_USERNAME"); v != "" {
		c.User = v
	}
	if v := os.Getenv("OS_PASSWORD"); v != "" {
		c.Password = v
	}
	if v := os.Getenv("OS_TENANT_ID"); v != "" {
		c.TenantId = v
	}
	if v := os.Getenv("OS_TENANT_NAME"); v != "" {
		c.TenantName = v
	}

	// OpenStack's auto-generated openrc.sh files do not append the suffix
	// /tokens to the authentication URL. This ensures it is present when
	// specifying the URL.
	if strings.Contains(c.Auth, "://") && !strings.HasSuffix(c.Auth, "/tokens") {
		c.Auth += "/tokens"
	}

	accessProvider, err := gophercloud.Authenticate(
		c.Auth,
		gophercloud.AuthOptions{
			ApiKey:     c.ApiKey,
			Username:   c.User,
			Password:   c.Password,
			TenantName: c.TenantName,
			TenantId:   c.TenantId,
		},
	)

	if err != nil {
		return nil, err
	}

	client := &OpenstackClient{c, accessProvider}

	log.Printf("[INFO] Openstack Client configured for user %s", client.Config.User)

	return client, nil
}
开发者ID:haklop,项目名称:terraform,代码行数:48,代码来源:config.go

示例11: Auth

// Auth returns a valid Auth object for access to openstack services, or
// an error if the authentication couldn't be resolved.
func (c *AccessConfig) Auth() (gophercloud.AccessProvider, error) {
	username := c.Username
	password := c.Password
	project := c.Project
	provider := c.Provider
	proxy := c.ProxyUrl

	if username == "" {
		username = os.Getenv("SDK_USERNAME")
	}
	if password == "" {
		password = os.Getenv("SDK_PASSWORD")
	}
	if project == "" {
		project = os.Getenv("SDK_PROJECT")
	}
	if provider == "" {
		provider = os.Getenv("SDK_PROVIDER")
	}

	authoptions := gophercloud.AuthOptions{
		Username:    username,
		Password:    password,
		AllowReauth: true,
	}

	if project != "" {
		authoptions.TenantName = project
	}

	// For corporate networks it may be the case where we want our API calls
	// to be sent through a separate HTTP proxy than external traffic.
	if proxy != "" {
		url, err := url.Parse(proxy)
		if err != nil {
			return nil, err
		}

		// The gophercloud.Context has a UseCustomClient method which
		// would allow us to override with a new instance of http.Client.
		http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(url)}
	}

	return gophercloud.Authenticate(provider, authoptions)
}
开发者ID:EdevMosaic,项目名称:packer,代码行数:47,代码来源:access_config.go

示例12: main

func main() {
	provider, username, _, apiKey := getCredentials()

	if !strings.Contains(provider, "rackspace") {
		fmt.Fprintf(os.Stdout, "Skipping test because provider doesn't support API_KEYs\n")
		return
	}

	_, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username: username,
			ApiKey:   apiKey,
		},
	)
	if err != nil {
		panic(err)
	}
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:19,代码来源:00-authentication.go

示例13: NewRackspaceFromUrl

func NewRackspaceFromUrl(u *url.URL) (*Rackspace, error) {
	var port = DEFAULT_PORT
	var region = DEFAULT_REGION
	var protocol = DEFAULT_PROTOCOL
	var username = ""
	var apiKey = ""

	if os.Getenv("OS_REGION_NAME") != "" {
		region = strings.ToLower(os.Getenv("OS_REGION_NAME"))
	}

	qs := u.Query()

	if qs.Get("port") != "" {
		port = qs.Get("port")
	}

	if qs.Get("protocol") != "" {
		protocol = qs.Get("protocol")
	}

	if qs.Get("region") != "" {
		region = strings.ToLower(qs.Get("region"))
	}

	if os.Getenv("OS_USERNAME") != "" {
		username = os.Getenv("OS_USERNAME")
	}

	if os.Getenv("OS_PASSWORD") != "" {
		apiKey = os.Getenv("OS_PASSWORD")
	}

	if username == "" && u.User != nil {
		username = u.User.Username()
	} else if username == "" && u.User == nil {
		return nil, fmt.Errorf("Missing Username for Rackspace provider.")
	}

	if apiKey == "" && u.User != nil {
		var ok bool
		apiKey, ok = u.User.Password()
		if !ok {
			return nil, fmt.Errorf("Missing API Key for Rackspace provider.")
		}
	}

	auth := gophercloud.AuthOptions{
		Username:    username,
		ApiKey:      apiKey,
		AllowReauth: true}

	var identityRegion = "rackspace-us"

	if region == "lon" {
		identityRegion = "rackspace-uk"
	}

	ap, err := gophercloud.Authenticate(identityRegion, auth)

	if err != nil {
		return nil, err
	}

	r := &Rackspace{accessProvider: ap,
		region:   region,
		port:     port,
		protocol: protocol,
		backoff:  timeutils.NewBackoffTimer(30.0, 1800.0),
	}

	err = r.UpdateCache()

	if err != nil {
		return nil, err
	}

	go r.Watch()

	return r, nil
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:81,代码来源:rackspace.go

示例14: New

func New(authURL, providerName string, credential, builder map[string]interface{}) (*Openstack, error) {
	// OpenStack's auto-generated openrc.sh files do not append the suffix
	// /tokens to the authentication URL. This ensures it is present when
	// specifying the URL.
	if strings.Contains(authURL, "://") && !strings.HasSuffix(authURL, "/tokens") {
		authURL += "/tokens"
	}

	o := &Openstack{
		AuthURL:  authURL,
		Provider: providerName,
	}

	// Credentials
	if err := mapstructure.Decode(credential, &o.Creds); err != nil {
		return nil, err
	}

	// Builder data
	if err := mapstructure.Decode(builder, &o.Builder); err != nil {
		return nil, err
	}

	if o.Creds.Username == "" {
		return nil, errors.New("Username is not set")
	}

	if o.Creds.Password == "" && o.Creds.ApiKey == "" {
		return nil, errors.New("Password/ApiKey is not set")
	}

	authoptions := gophercloud.AuthOptions{
		AllowReauth: true,
		ApiKey:      o.Creds.ApiKey,
		TenantId:    o.Creds.TenantId,
		TenantName:  o.Creds.TenantName,
		Username:    o.Creds.Username,
		Password:    o.Creds.Password,
	}

	access, err := gophercloud.Authenticate(authURL, authoptions)
	if err != nil {
		return nil, err
	}

	//fetches the api requisites from gophercloud for the appropriate
	//openstack variant
	api, err := gophercloud.PopulateApi(providerName)
	if err != nil {
		return nil, err
	}

	// if not given the default is used which is returned for that account.
	if o.Builder.RawRegion != "" {
		api.Region = o.Builder.RawRegion
	}

	csp, err := gophercloud.ServersApi(access, api)
	if err != nil {
		log.Printf("Region: %s", o.Builder.RawRegion)
		return nil, err
	}
	o.Client = csp

	return o, nil
}
开发者ID:koding,项目名称:koding,代码行数:66,代码来源:openstack.go


注:本文中的github.com/rackspace/gophercloud.Authenticate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。