• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang scwversion.UserAgent函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: RunLogin

// RunLogin is the handler for 'scw login'
func RunLogin(ctx CommandContext, args LoginArgs) error {
	if config, cfgErr := config.GetConfig(); cfgErr == nil {
		if TestConnection, err := api.NewScalewayAPI(config.Organization, config.Token, scwversion.UserAgent(), "", clilogger.SetupLogger); err == nil {
			if user, err := TestConnection.GetUser(); err == nil {
				fmt.Println("You are already logged as", user.Fullname)
			}
		}
	}

	if args.Organization == "" || args.Token == "" {
		var err error

		args.Organization, args.Token, err = connectAPI()
		if err != nil {
			return err
		}
	}

	cfg := &config.Config{
		Organization: strings.Trim(args.Organization, "\n"),
		Token:        strings.Trim(args.Token, "\n"),
	}

	apiConnection, err := api.NewScalewayAPI(cfg.Organization, cfg.Token, scwversion.UserAgent(), "", clilogger.SetupLogger)
	if err != nil {
		return fmt.Errorf("Unable to create ScalewayAPI: %s", err)
	}
	err = apiConnection.CheckCredentials()
	if err != nil {
		return fmt.Errorf("Unable to contact ScalewayAPI: %s", err)
	}
	if !args.SkipSSHKey {
		if err = selectKey(&args); err != nil {
			logrus.Errorf("Unable to select a key: %v", err)
		} else {
			if args.SSHKey != "" {
				uploadSSHKeys(apiConnection, args.SSHKey)
			}
		}
	}
	name := "."
	user, err := apiConnection.GetUser()
	if err == nil {
		name = "as " + user.Fullname + "."
	}
	fmt.Println("")
	fmt.Println("You are now authenticated on Scaleway.com", name)
	fmt.Println("You can list your existing servers using `scw ps` or create a new one using `scw run ubuntu-xenial`.")
	fmt.Println("You can get a list of all available commands using `scw -h` and get more usage examples on github.com/scaleway/scaleway-cli.")
	fmt.Println("Happy cloud riding.")
	return cfg.Save()
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:53,代码来源:login.go


示例2: RealAPIContext

// RealAPIContext returns a CommandContext with a configured API
func RealAPIContext() *CommandContext {
	if os.Getenv("TEST_WITH_REAL_API") == "0" {
		return nil
	}
	config, err := config.GetConfig()
	if err != nil {
		logrus.Warnf("RealAPIContext: failed to call config.GetConfig(): %v", err)
		return nil
	}

	apiClient, err := api.NewScalewayAPI(config.Organization, config.Token, scwversion.UserAgent(), "par1")
	if err != nil {
		logrus.Warnf("RealAPIContext: failed to call api.NewScalewayAPI(): %v", err)
		return nil
	}

	stdout := bytes.Buffer{}
	stderr := bytes.Buffer{}

	ctx := CommandContext{
		Streams: Streams{
			Stdin:  os.Stdin,
			Stdout: &stdout,
			Stderr: &stderr,
		},
		Env: []string{
			"HOME" + os.Getenv("HOME"),
		},
		RawArgs: []string{},
		API:     apiClient,
	}
	return &ctx
}
开发者ID:pulcy,项目名称:quark,代码行数:34,代码来源:test.go


示例3: getToken

func getToken(connect api.ScalewayConnect) (string, error) {
	FakeConnection, err := api.NewScalewayAPI("", "", scwversion.UserAgent(), "", clilogger.SetupLogger)
	if err != nil {
		return "", fmt.Errorf("Unable to create a fake ScalewayAPI: %s", err)
	}
	FakeConnection.SetPassword(connect.Password)

	resp, err := FakeConnection.PostResponse(api.AccountAPI, "tokens", connect)
	if resp != nil {
		defer resp.Body.Close()
	}
	if err != nil {
		return "", fmt.Errorf("unable to connect %v", err)
	}

	// Succeed POST code
	if resp.StatusCode != 201 {
		return "", fmt.Errorf("[%d] maybe your email or your password is not valid", resp.StatusCode)
	}
	var data api.ScalewayConnectResponse

	decoder := json.NewDecoder(resp.Body)
	err = decoder.Decode(&data)
	if err != nil {
		return "", err
	}
	return data.Token.ID, nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:28,代码来源:login.go


示例4: getOrganization

func getOrganization(token string, email string) (string, error) {
	FakeConnection, err := api.NewScalewayAPI("", token, scwversion.UserAgent(), "", clilogger.SetupLogger)
	if err != nil {
		return "", fmt.Errorf("Unable to create a fake ScalewayAPI: %s", err)
	}
	data, err := FakeConnection.GetOrganization()
	if err != nil {
		return "", err
	}

	orgaID := ""

	for _, orga := range data.Organizations {
		for _, user := range orga.Users {
			if user.Email == email {
				for i := range user.Organizations {
					if user.Organizations[i].Name != "OCS" {
						orgaID = user.Organizations[i].ID
						goto exit
					}
				}
			}
		}
	}
	if orgaID == "" {
		return "", fmt.Errorf("Unable to find your organization")
	}
exit:
	return orgaID, nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:30,代码来源:login.go


示例5: RunLogin

// RunLogin is the handler for 'scw login'
func RunLogin(ctx CommandContext, args LoginArgs) error {
	if args.Organization == "" || args.Token == "" {
		var err error

		args.Organization, args.Token, err = connectAPI()
		if err != nil {
			return err
		}
	}

	cfg := &config.Config{
		Organization: strings.Trim(args.Organization, "\n"),
		Token:        strings.Trim(args.Token, "\n"),
	}

	apiConnection, err := api.NewScalewayAPI(cfg.Organization, cfg.Token, scwversion.UserAgent())
	if err != nil {
		return fmt.Errorf("Unable to create ScalewayAPI: %s", err)
	}
	err = apiConnection.CheckCredentials()
	if err != nil {
		return fmt.Errorf("Unable to contact ScalewayAPI: %s", err)
	}
	if !args.SkipSSHKey {
		if err := selectKey(&args); err != nil {
			logrus.Errorf("Unable to select a key: %v", err)
		} else {
			if args.SSHKey != "" {
				uploadSSHKeys(apiConnection, args.SSHKey)
			}
		}
	}
	return cfg.Save()
}
开发者ID:moul,项目名称:scaleway-cli,代码行数:35,代码来源:login.go


示例6: getScalewayAPI

// getScalewayAPI returns a ScalewayAPI using the user config file
func getScalewayAPI() (*api.ScalewayAPI, error) {
	// We already get config globally, but whis way we can get explicit error when trying to create a ScalewayAPI object
	config, err := config.GetConfig()
	if err != nil {
		return nil, err
	}
	return api.NewScalewayAPI(config.Organization, config.Token, scwversion.UserAgent())
}
开发者ID:moul,项目名称:scaleway-cli,代码行数:9,代码来源:main.go


示例7: TestNewScalewayAPI

func TestNewScalewayAPI(t *testing.T) {
	Convey("Testing NewScalewayAPI()", t, func() {
		api, err := NewScalewayAPI("my-organization", "my-token", scwversion.UserAgent())
		So(err, ShouldBeNil)
		So(api, ShouldNotBeNil)
		So(api.Token, ShouldEqual, "my-token")
		So(api.Organization, ShouldEqual, "my-organization")
		So(api.Cache, ShouldNotBeNil)
		So(api.client, ShouldNotBeNil)
		So(api.Logger, ShouldNotBeNil)
	})
}
开发者ID:Originate,项目名称:terraform,代码行数:12,代码来源:api_test.go


示例8: Client

// Client configures and returns a fully initialized Scaleway client
func (c *Config) Client() (*Client, error) {
	api, err := api.NewScalewayAPI(
		c.Organization,
		c.APIKey,
		scwversion.UserAgent(),
		func(s *api.ScalewayAPI) {
			s.Logger = newTerraformLogger()
		},
	)
	if err != nil {
		return nil, err
	}
	return &Client{api}, nil
}
开发者ID:Originate,项目名称:terraform,代码行数:15,代码来源:config.go


示例9: TestNewScalewayAPI

func TestNewScalewayAPI(t *testing.T) {
	Convey("Testing NewScalewayAPI()", t, func() {
		api, err := NewScalewayAPI("http://api-endpoint.com", "http://account-endpoint.com", "my-organization", "my-token", scwversion.UserAgent())
		So(err, ShouldBeNil)
		So(api, ShouldNotBeNil)
		So(api.ComputeAPI, ShouldEqual, "http://api-endpoint.com")
		So(api.AccountAPI, ShouldEqual, "http://account-endpoint.com")
		So(api.Token, ShouldEqual, "my-token")
		So(api.Organization, ShouldEqual, "my-organization")
		So(api.Cache, ShouldNotBeNil)
		So(api.client, ShouldNotBeNil)
		So(api.anonuuid, ShouldNotBeNil)
	})
}
开发者ID:awesome-docker,项目名称:scaleway-cli,代码行数:14,代码来源:api_test.go


示例10: runUserdata

func runUserdata(cmd *Command, args []string) error {
	if userdataHelp {
		return cmd.PrintUsage()
	}
	if len(args) < 1 {
		return cmd.PrintShortUsage()
	}
	metadata := false
	ctx := cmd.GetContext(args)
	var API *api.ScalewayAPI
	var err error
	var serverID string
	if args[0] == "local" {
		API, err = api.NewScalewayAPI("", "", scwversion.UserAgent(), *flRegion)
		if err != nil {
			return err
		}
		metadata = true
	} else {
		if ctx.API == nil {
			return fmt.Errorf("You need to login first: 'scw login'")
		}
		serverID, err = ctx.API.GetServerID(args[0])
		if err != nil {
			return err
		}
		API = ctx.API
	}

	switch len(args) {
	case 1:
		// List userdata
		res, errGetUserdata := API.GetUserdatas(serverID, metadata)
		if errGetUserdata != nil {
			return errGetUserdata
		}
		for _, key := range res.UserData {
			fmt.Fprintln(ctx.Stdout, key)
		}
	default:
		parts := strings.Split(args[1], "=")
		key := parts[0]
		switch len(parts) {
		case 1:
			// Get userdatas
			res, errGetUserdata := API.GetUserdata(serverID, key, metadata)
			if errGetUserdata != nil {
				return errGetUserdata
			}
			fmt.Fprintf(ctx.Stdout, "%s\n", res.String())
		default:
			value := args[1][len(parts[0])+1:]
			if value != "" {
				var data []byte
				// Set userdata
				if value[0] == '@' {
					if len(value) > 1 && value[1] == '~' {
						home, err := config.GetHomeDir()
						if err != nil {
							return err
						}
						value = "@" + home + value[2:]
					}
					data, err = ioutil.ReadFile(value[1:])
					if err != nil {
						return err
					}
				} else {
					data = []byte(value)
				}
				err := API.PatchUserdata(serverID, key, data, metadata)
				if err != nil {
					return err
				}
				fmt.Fprintln(ctx.Stdout, key)
			} else {
				// Delete userdata
				err := API.DeleteUserdata(serverID, key, metadata)
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:86,代码来源:x_userdata.go


示例11: ExampleCommandContext

func ExampleCommandContext() {
	apiClient, err := api.NewScalewayAPI("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", scwversion.UserAgent(), "")
	if err != nil {
		panic(err)
	}

	ctx := CommandContext{
		Streams: Streams{
			Stdin:  os.Stdin,
			Stdout: os.Stdout,
			Stderr: os.Stderr,
		},
		Env: []string{
			"HOME" + os.Getenv("HOME"),
		},
		RawArgs: []string{},
		API:     apiClient,
	}

	// Do stuff
	fmt.Println(ctx)
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:22,代码来源:command_test.go


示例12: testCommandContext

func testCommandContext() CommandContext {
	apiClient, err := api.NewScalewayAPI("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", scwversion.UserAgent(), "")
	if err != nil {
		panic(err)
	}

	ctx := CommandContext{
		Streams: Streams{
			Stdin:  os.Stdin,
			Stdout: os.Stdout,
			Stderr: os.Stderr,
		},
		Env: []string{
			"HOME" + os.Getenv("HOME"),
		},
		RawArgs: []string{},
		API:     apiClient,
	}
	return ctx
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:20,代码来源:command_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang logrus.Debugf函数代码示例发布时间:2022-05-28
下一篇:
Golang api.ScalewayServerPatchDefinition类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap