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

Golang credentials.NewSharedCredentials函数代码示例

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

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



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

示例1: cmdValidate

func cmdValidate(c *cli.Context) {

	processFlags(c)

	if fileLocation == "" {
		cli.ShowCommandHelp(c, "create")
		log.Fatal("You must specify a configuration file to use")
	}

	log.Infof("Config file %s", fileLocation)

	file, e := ioutil.ReadFile(fileLocation)
	if e != nil {
		fmt.Printf("File error: %v\n", e)
		os.Exit(1)
	}

	jsontype := providers.JSONObject{}
	json.Unmarshal(file, &jsontype)

	log.Info("*********************************************************************************")
	log.Info("** Loading configuration file " + fileLocation)
	log.Info("*********************************************************************************")

	log.Info("Configuration for environment " + jsontype.Provider.ProviderConfig.Aws.Vpc.Name)
	log.Info("Environment has " + strconv.Itoa(len(jsontype.Containers)) + " servers defined")

	//Validate Provider document using JSONSchema
	validated, validateErrors := vmproviders.ValidateDocument()
	if validated {
		log.Info("Successfully validated provider configuration")
	} else {
		log.Error("Error validating provider configuration %v", validateErrors)
	}

	homedir := os.Getenv("HOME")

	creds := credentials.NewSharedCredentials(homedir+"/.aws/credentials", profile)

	credValue, err := creds.Get()
	if err != nil {
		fmt.Printf("Credential token= %v\n", credValue)
		fmt.Println(err)
		os.Exit(1)
	}

	ec2client := vmproviders.GetEC2Client(creds, "us-east-1")

	validateSuccess, validateWarnings, validateErr := vmproviders.Validate(ec2client, &jsontype)
	if validateSuccess {
		log.Infof("Successfully validated environment %v", jsontype.Provider.ProviderConfig.Aws.Vpc.Name)
		for w := range validateWarnings {
			log.Warnf(validateWarnings[w])
		}
	} else {
		for e := range validateErr {
			log.Errorf(validateErr[e].Error())
		}
	}
}
开发者ID:podtools,项目名称:pod,代码行数:60,代码来源:validate.go


示例2: Svc

// Svc configures the DynamoDB service to use
func Svc(opts config.Options) *dynamodb.DynamoDB {
	awsConfig := &aws.Config{Region: aws.String(opts.Storage.AWS.Region)}

	// If a session was passed... (AWS Lambda does this)
	if opts.Storage.AWS.SessionToken != "" {
		os.Setenv("AWS_SESSION_TOKEN", opts.Storage.AWS.SessionToken)
	}

	// Look in a variety of places for AWS credentials. First, try the credentials file set by AWS CLI tool.
	// Note the empty string instructs to look under default file path (different based on OS).
	// This file can have multiple profiles and a default profile will be used unless otherwise configured.
	// See: https://godoc.org/github.com/aws/aws-sdk-go/aws/credentials#SharedCredentialsProvider
	creds := credentials.NewSharedCredentials("", opts.Storage.AWS.CredProfile)
	_, err := creds.Get()
	// If that failed, try environment variables.
	if err != nil {
		// The following are checked:
		// Access Key ID: AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY
		// Secret Access Key: AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY
		creds = credentials.NewEnvCredentials()
	}

	// If credentials were passed via config, then use those. They will take priority over other methods.
	if opts.Storage.AWS.AccessKeyID != "" && opts.Storage.AWS.SecretAccessKey != "" {
		creds = credentials.NewStaticCredentials(opts.Storage.AWS.AccessKeyID, opts.Storage.AWS.SecretAccessKey, "")
	}
	awsConfig.Credentials = creds

	return dynamodb.New(session.New(awsConfig))
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:31,代码来源:dynamodb.go


示例3: TestMain

func TestMain(m *testing.M) {
	flag.Parse()
	if !*integration {
		fmt.Fprintln(os.Stderr, "Skipping integration tests")
		os.Exit(0)
	}
	cfg = &aws.Config{
		Region:      aws.String("us-west-2"),
		Endpoint:    aws.String("http://localhost:8000"),
		Credentials: credentials.NewSharedCredentials("", *awsprofile),
	}
	sess = session.New(cfg)
	if *dynamodebug {
		sess.Config.LogLevel = aws.LogLevel(aws.LogDebug)
	}

	if err := loadUserFixtures(sess); err != nil {
		fmt.Fprintf(os.Stderr, "Error loading 'user' integration fixtures: %s", err)
		os.Exit(1)
	}
	if err := loadPostFixtures(sess); err != nil {
		fmt.Fprintf(os.Stderr, "Error loading 'post' integration fixtures: %s", err)
		os.Exit(1)
	}
	os.Exit(m.Run())
}
开发者ID:blang,项目名称:posty,代码行数:26,代码来源:model_integration_test.go


示例4: createCommandFactory

// createCommandFactory create a command factory and wraps the command processor
func createCommandFactory(cx *cli.Context, commandFunc func(*cli.Context, *commandFactory) error) {
	awsRegion := cx.GlobalString("region")
	awsProfile := cx.GlobalString("profile")
	awsCredentials := cx.GlobalString("crendentials")

	if awsRegion == "" {
		usage(cx, "you need to specify the region or export the environment variable AWS_DEFAULT_REGION")
	}

	// step: create a default aws configuration
	cfg := &aws.Config{Region: &awsRegion}

	// step: are we specifying a aws profile, if so, we need to be using the $HOME/.aws/credentials file
	if awsProfile != "" {
		cfg.Credentials = credentials.NewSharedCredentials(awsCredentials, awsProfile)
	}

	// step: create a command line factory
	factory := &commandFactory{
		s3:  newS3Client(cfg),
		kms: newKmsClient(cfg),
	}

	if err := commandFunc(cx, factory); err != nil {
		usage(cx, err.Error())
	}
}
开发者ID:lucmichalski,项目名称:s3secrets,代码行数:28,代码来源:main.go


示例5: preRun

// PreRun sets up global tasks used for most commands, some use PreRunNoop
// to remove this default behaviour.
func preRun(c *cobra.Command, args []string) error {
	if l, err := log.ParseLevel(logLevel); err == nil {
		log.SetLevel(l)
	}

	config := aws.NewConfig()

	if profile != "" {
		config = config.WithCredentials(credentials.NewSharedCredentials("", profile))
	}

	Session = session.New(config)

	Project = &project.Project{
		Log:  log.Log,
		Path: ".",
	}

	if dryRun {
		log.SetLevel(log.WarnLevel)
		Project.Service = dryrun.New(Session)
		Project.Concurrency = 1
	} else {
		Project.Service = lambda.New(Session)
	}

	if chdir != "" {
		if err := os.Chdir(chdir); err != nil {
			return err
		}
	}

	return Project.Open()
}
开发者ID:aom,项目名称:apex,代码行数:36,代码来源:root.go


示例6: Start

// Start a test
func (t *Test) Start() <-chan queue.RegionsAggData {
	awsConfig := aws.NewConfig().WithRegion(t.config.Regions[0])

	if t.config.AwsProfile != "" {
		creds := credentials.NewSharedCredentials("", t.config.AwsProfile)
		if _, err := creds.Get(); err != nil {
			log.Fatal(err)
		}
		awsConfig.WithCredentials(creds)
	}

	infra, err := infrastructure.New(t.config.Regions, awsConfig)
	if err != nil {
		log.Fatal(err)
	}

	t.invokeLambdas(awsConfig, infra.QueueURL())

	results := make(chan queue.RegionsAggData)

	go func() {
		for result := range queue.Aggregate(awsConfig, infra.QueueURL(), t.config.TotalRequests) {
			results <- result
		}
		infra.Clean()
		close(results)
	}()

	return results
}
开发者ID:goadapp,项目名称:goad,代码行数:31,代码来源:goad.go


示例7: Connect

func (c *Config) Connect() interface{} {

	c.readConf()

	var client AWSClient

	awsConfig := new(aws.Config)

	if len(c.Profile) > 0 {
		awsConfig = &aws.Config{
			Credentials: credentials.NewSharedCredentials(c.Awsconf, fmt.Sprintf("profile %s", c.Profile)),
			Region:      aws.String(c.Region),
			MaxRetries:  aws.Int(3),
		}

	} else {
		// use instance role
		awsConfig = &aws.Config{
			Region: aws.String(c.Region),
		}

	}

	sess := session.New(awsConfig)

	client.ec2conn = ec2.New(sess)

	return &client

}
开发者ID:mhlias,项目名称:awscleaner,代码行数:30,代码来源:config.go


示例8: mount

// Mount the file system based on the supplied arguments, returning a
// fuse.MountedFileSystem that can be joined to wait for unmounting.
func mount(
	ctx context.Context,
	bucketName string,
	mountPoint string,
	flags *FlagStorage) (mfs *fuse.MountedFileSystem, err error) {

	awsConfig := &aws.Config{
		Region: &flags.Region,
		Logger: GetLogger("s3"),
		//LogLevel: aws.LogLevel(aws.LogDebug),
	}

	if len(flags.Profile) > 0 {
		awsConfig.Credentials = credentials.NewSharedCredentials("", flags.Profile)
	}

	if len(flags.Endpoint) > 0 {
		awsConfig.Endpoint = &flags.Endpoint
	}

	// deprecate flags.UsePathRequest
	if flags.UsePathRequest {
		log.Infoln("--use-path-request is deprecated, it's always on")
	}
	awsConfig.S3ForcePathStyle = aws.Bool(true)

	goofys := NewGoofys(bucketName, awsConfig, flags)
	if goofys == nil {
		err = fmt.Errorf("Mount: initialization failed")
		return
	}
	server := fuseutil.NewFileSystemServer(goofys)

	fuseLog := GetLogger("fuse")

	// Mount the file system.
	mountCfg := &fuse.MountConfig{
		FSName:                  bucketName,
		Options:                 flags.MountOptions,
		ErrorLogger:             GetStdLogger(NewLogger("fuse"), logrus.ErrorLevel),
		DisableWritebackCaching: true,
	}

	if flags.DebugFuse {
		fuseLog.Level = logrus.DebugLevel
		log.Level = logrus.DebugLevel
		mountCfg.DebugLogger = GetStdLogger(fuseLog, logrus.DebugLevel)
	}

	mfs, err = fuse.Mount(mountPoint, server, mountCfg)
	if err != nil {
		err = fmt.Errorf("Mount: %v", err)
		return
	}

	return
}
开发者ID:kahing,项目名称:goofys,代码行数:59,代码来源:main.go


示例9: ProfileCredentials

// ProfileCredentials checks to see if specific profile is being asked to use
func (config SsmagentConfig) ProfileCredentials() (credsInConfig *credentials.Credentials, err error) {
	// the credentials file location and profile to load
	credsInConfig = credentials.NewSharedCredentials(config.Profile.Path, config.Profile.Name)
	_, err = credsInConfig.Get()
	if err != nil {
		return nil, err
	}
	fmt.Printf("Using AWS credentials configured under %v user profile \n", config.Profile.Name)
	return
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:11,代码来源:appconfig.go


示例10: main

func main() {
	home := os.Getenv("HOME")
	if home == "" {
		log.Fatalf("HOME environment variable not set")
	}
	credentialsFile := fmt.Sprintf("%s/.aws/credentials", home)
	config := aws.NewConfig().WithCredentials(credentials.NewSharedCredentials(credentialsFile, *profile)).WithRegion(*region).WithMaxRetries(3)

	svc := s3.New(config)

	switch *op {
	case "get":
		params := &s3.GetObjectInput{
			Bucket: aws.String(*bucketName),
			Key:    aws.String(*objectKey),
		}

		resp, err := svc.GetObject(params)
		if err != nil {
			log.Fatal(err)
		}

		data, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			log.Fatal(err)
		}

		if err := ioutil.WriteFile(*fileName, data, 0644); err != nil {
			log.Fatal(err)
		}
	case "put":
		data, err := ioutil.ReadFile(*fileName)
		if err != nil {
			log.Fatal(err)
		}
		params := &s3.PutObjectInput{
			Bucket:               aws.String(*bucketName),
			Key:                  aws.String(*objectKey),
			Body:                 bytes.NewReader(data),
			ServerSideEncryption: aws.String("AES256"),
		}
		if *publicRead {
			params.ACL = aws.String("public-read")
		}
		if *contentType != "" {
			params.ContentType = aws.String(*contentType)
		}
		if _, err = svc.PutObject(params); err != nil {
			log.Fatal(err.Error())
		}
	default:
		log.Fatalf("Operation not supported %s\n", *op)
	}
}
开发者ID:ae6rt,项目名称:s3rw,代码行数:54,代码来源:main.go


示例11: LoadDefaultOptions

// LoadDefaultOptions is used to load in the default options into the globally
// available options struct. This is typically one of the first things called
// on start up. After this all options can be overridden
func LoadDefaultOptions() {
	Options.CacheDir = "/tmp/S3Proxy/"
	Options.BindAddress = ":9090"
	Options.ObjectCacheTTL = time.Duration(1 * time.Minute)
	Options.Region = "eu-west-1"
	Options.Bucket = "example-bucket"
	Options.TokenKey = "test_keys/sample_key"
	Options.TokenMethod = jwt.SigningMethodRS512
	Options.CookieMaxAge = 3600
	Options.AwsCredentials = credentials.NewSharedCredentials("", "default")
}
开发者ID:gitu,项目名称:S3Proxy,代码行数:14,代码来源:options.go


示例12: checkCreds

func checkCreds() (err error) {
	creds := credentials.NewEnvCredentials()
	_, err = creds.Get()
	if err == nil {
		// If ENV credentials are present, I don't need to check shared credentials on fs
		return
	}
	creds = credentials.NewSharedCredentials("", "")
	_, err = creds.Get()
	return
}
开发者ID:cloudacademy,项目名称:s3zipper,代码行数:11,代码来源:s3.go


示例13: getService

func getService(debug bool, profile string) *route53.Route53 {
	config := aws.Config{}
	if profile != "" {
		config.Credentials = credentials.NewSharedCredentials("", profile)
	}
	// ensures throttled requests are retried
	config.MaxRetries = aws.Int(100)
	if debug {
		config.LogLevel = aws.LogLevel(aws.LogDebug)
	}
	return route53.New(session.New(), &config)
}
开发者ID:TheBigBear,项目名称:cli53,代码行数:12,代码来源:util.go


示例14: rootCredentials

func (c *CredentialConfig) rootCredentials() client.ConfigProvider {
	config := &aws.Config{
		Region: aws.String(c.Region),
	}
	if c.AccessKey != "" || c.SecretKey != "" {
		config.Credentials = credentials.NewStaticCredentials(c.AccessKey, c.SecretKey, c.Token)
	} else if c.Profile != "" || c.Filename != "" {
		config.Credentials = credentials.NewSharedCredentials(c.Filename, c.Profile)
	}

	return session.New(config)
}
开发者ID:jeichorn,项目名称:telegraf,代码行数:12,代码来源:credentials.go


示例15: main

func main() {

	reportTable := map[string]float64{}
	constTable := map[string]string{}
	screds := credentials.NewSharedCredentials("/Users/ilyakravchenko/.aws/credentials", "myal")
	config := aws.Config{Region: aws.String("us-east-1"), Credentials: screds}
	sess := session.New(&config)
	if sess == nil {
		fmt.Println("problems with authorization")
	}
	svc := ec2.New(sess)
	params := &ec2.DescribeInstancesInput{}
	resp, err := svc.DescribeInstances(params)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	for index, _ := range resp.Reservations {
		for _, instance := range resp.Reservations[index].Instances {
			for _, tag := range instance.Tags {
				if *tag.Key == "Name" {
					extraInfo := *instance.InstanceType + "," + *instance.PrivateIpAddress //store extra info
					constTable[*tag.Value] = extraInfo
					_, ok := reportTable[*tag.Value]
					if !ok {
						reportTable[*tag.Value] = getPrice(*instance.InstanceType)

					} else {
						reportTable[*tag.Value] += getPrice(*instance.InstanceType)
					}
				}
			}
		}
	}
	for key, _ := range reportTable {
		_, ok := constTable[key]
		if ok {
			val := reportTable[key]
			constTable[key] = strconv.FormatFloat(val, 'f', 2, 64) + "," + constTable[key]
		}
	}
	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Type", "Price", "IP", "Name"})
	for k, v := range constTable {
		s := strings.Split(v, ",")
		s = []string{s[1], s[0], s[2]}

		table.Append(append(s, k))
	}
	table.Render()
}
开发者ID:ikrauchanka,项目名称:tahoa-cleo,代码行数:52,代码来源:ec2_stat.go


示例16: NewS3

func NewS3(filename, profile, region string) *S3 {
	var creds *credentials.Credentials
	if _, err := os.Stat(filename); err == nil {
		log.Printf("Connecting to AWS using credentials from '%s'", filename)
		creds = credentials.NewSharedCredentials(filename, profile)
	} else {
		log.Printf("AWS credentials file '%s' dosen't exists, I will be using EC2 Role credentials", filename)
		sess := session.New()
		creds = credentials.NewCredentials(&ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(sess)})
	}
	sess := session.New(&aws.Config{Credentials: creds, Region: aws.String(region)})
	return &S3{svc: s3.New(sess)}
}
开发者ID:dzlab,项目名称:qbench,代码行数:13,代码来源:aws.go


示例17: GetSessionWithProfile

// GetSessionWithProfile will return a new aws session with optional profile
func GetSessionWithProfile(profile string) (*session.Session, error) {
	config := aws.NewConfig()

	// Get and save profile
	if profile != "" {
		profileName = profile
		config = config.WithCredentials(credentials.NewSharedCredentials("", profileName))

		// Debug creds...
		// fmt.Println(config.Credentials.Get())
	}

	return getSessionWithConfig(config)
}
开发者ID:colinmutter,项目名称:go-ecs,代码行数:15,代码来源:config.go


示例18: getConfig

func getConfig(c *cli.Context) *aws.Config {
	debug := c.Bool("debug")
	profile := c.String("profile")
	config := aws.Config{}
	if profile != "" {
		config.Credentials = credentials.NewSharedCredentials("", profile)
	}
	// ensures throttled requests are retried
	config.MaxRetries = aws.Int(100)
	if debug {
		config.LogLevel = aws.LogLevel(aws.LogDebug)
	}
	return &config
}
开发者ID:barnybug,项目名称:cli53,代码行数:14,代码来源:util.go


示例19: AWSConfig

func AWSConfig(key, secret, token, file, profile string) (conf *aws.Config) {
	var creds *credentials.Credentials
	if file != "" {
		creds = credentials.NewSharedCredentials(file, profile)
	}
	if key != "" && secret != "" {
		creds = credentials.NewStaticCredentials(key, secret, token)
	}

	conf = &aws.Config{
		Credentials: creds,
	}

	return conf
}
开发者ID:tkuchiki,项目名称:iam-server-cert,代码行数:15,代码来源:main.go


示例20: main

func main() {
	accounts := []string{"default", "default2", "otherprofile"}

	// Spin off a worker for each account to retrieve that account's
	bucketCh := make(chan *Bucket, 5)
	var wg sync.WaitGroup
	for _, acc := range accounts {
		wg.Add(1)
		go func(acc string) {
			sess := session.New(&aws.Config{Credentials: credentials.NewSharedCredentials("", acc)})
			if err := getAccountBuckets(sess, bucketCh, acc); err != nil {
				fmt.Fprintf(os.Stderr, "failed to get account %s's bucket info, %v\n", acc, err)
			}
			wg.Done()
		}(acc)
	}
	// Spin off a goroutine which will wait until all account buckets have been collected and
	// added to the bucketCh. Close the bucketCh so the for range below will exit once all
	// bucket info is printed.
	go func() {
		wg.Wait()
		close(bucketCh)
	}()

	// Receive from the bucket channel printing the information for each bucket to the console
	// when the bucketCh channel is drained.
	buckets := []*Bucket{}
	for b := range bucketCh {
		buckets = append(buckets, b)
	}

	sortBuckets(buckets)
	for _, b := range buckets {
		if b.Error != nil {
			fmt.Printf("Bucket %s, owned by: %s, failed: %v\n", b.Name, b.Owner, b.Error)
			continue
		}

		encObjs := b.encryptedObjects()
		fmt.Printf("Bucket: %s, owned by: %s, total objects: %d, failed objects: %d, encrypted objects: %d\n",
			b.Name, b.Owner, len(b.Objects), len(b.ErrObjects), len(encObjs))
		if len(encObjs) > 0 {
			for _, encObj := range encObjs {
				fmt.Printf("\t%s %s:%s/%s\n", encObj.EncryptionType, b.Region, b.Name, encObj.Key)
			}
		}
	}
}
开发者ID:CNDonny,项目名称:scope,代码行数:48,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang credentials.NewStaticCredentials函数代码示例发布时间:2022-05-24
下一篇:
Golang credentials.NewEnvCredentials函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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