本文整理汇总了Golang中github.com/AdRoll/goamz/aws.GetAuth函数的典型用法代码示例。如果您正苦于以下问题:Golang GetAuth函数的具体用法?Golang GetAuth怎么用?Golang GetAuth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetAuth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
func (e EC2Tags) Get() (map[string]string, error) {
tags := make(map[string]string)
// Passing blank values here instructs the AWS library to look at the
// current instances meta data for the security credentials.
auth, err := aws.GetAuth("", "", "", time.Time{})
if err != nil {
return tags, errors.New(fmt.Sprintf("Error creating AWS authentication: %s", err.Error()))
}
// Find the current region and create a new EC2 connection
region := aws.GetRegion(aws.InstanceRegion())
ec2Client := ec2.New(auth, region)
// Filter by the current machines instance-id
filter := ec2.NewFilter()
filter.Add("resource-id", aws.InstanceId())
// Describe the tags for the current instance
resp, err := ec2Client.DescribeTags(filter)
if err != nil {
return tags, errors.New(fmt.Sprintf("Error downloading tags: %s", err.Error()))
}
// Collect the tags
for _, tag := range resp.Tags {
tags[tag.Key] = tag.Value
}
return tags, nil
}
示例2: getSqsQueueSize
func getSqsQueueSize(region, awsAccessKeyID, awsSecretAccessKey, queueName string) (int, error) {
// Auth
auth, err := aws.GetAuth(awsAccessKeyID, awsSecretAccessKey, "", time.Now())
if err != nil {
return -1, err
}
// SQS
sqsClient := sqs.New(auth, aws.GetRegion(region))
queue, err := sqsClient.GetQueue(queueName)
if err != nil {
return -1, err
}
// Get queue attribute
attr, err := queue.GetQueueAttributes(sqsAttributeOfQueueSize)
if err != nil {
return -1, err
}
// Queue size
size, err := strconv.Atoi(attr.Attributes[0].Value)
if err != nil {
return -1, err
}
return size, nil
}
示例3: awsS3Auth
func awsS3Auth() (aws.Auth, error) {
// First try to authenticate using the BUILDKITE_ ENV variables
buildkiteAuth, buildkiteErr := buildkiteS3EnvAuth()
if buildkiteErr == nil {
return buildkiteAuth, nil
}
// Passing blank values here instructs the AWS library to look at the
// current instances meta data for the security credentials.
awsAuth, awsErr := aws.GetAuth("", "", "", time.Time{})
if awsErr == nil {
return awsAuth, nil
}
var err error
// If they attempted to use the BUILDKITE_ ENV variables, return them
// that error, otherwise default to the error from AWS
if buildkiteErr != nil && buildkiteAuth.AccessKey != "" || buildkiteAuth.SecretKey != "" {
err = buildkiteErr
} else {
err = awsErr
}
return aws.Auth{}, err
}
示例4: main
func main() {
flag.Parse()
if *region == "" {
*region = aws.InstanceRegion()
}
auth, err := aws.GetAuth("", "", "", time.Now())
if err != nil {
log.Panic(err)
}
s3service := s3.New(auth, aws.GetRegion(*region))
bucket := s3service.Bucket(flag.Arg(0))
for {
var entries []RoutingEntry
data, err := bucket.Get("/routing-table.json")
if err == nil {
err = json.Unmarshal(data, &entries)
if err == nil {
updateProxies(entries)
}
} else {
log.Print("no get routing table", err)
}
time.Sleep(time.Second * 10)
}
}
示例5: TestGetAuthEnv
func (s *S) TestGetAuthEnv(c *check.C) {
os.Clearenv()
os.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
os.Setenv("AWS_ACCESS_KEY_ID", "access")
auth, err := aws.GetAuth("", "", "", time.Time{})
c.Assert(err, check.IsNil)
c.Assert(auth, check.Equals, aws.Auth{SecretKey: "secret", AccessKey: "access"})
}
示例6: New
// New constructs a new Driver with the given AWS credentials, region, encryption flag, and
// bucketName
func New(params DriverParameters) (*Driver, error) {
auth, err := aws.GetAuth(params.AccessKey, params.SecretKey, "", time.Time{})
if err != nil {
return nil, err
}
if !params.Secure {
params.Region.S3Endpoint = strings.Replace(params.Region.S3Endpoint, "https", "http", 1)
}
s3obj := s3.New(auth, params.Region)
bucket := s3obj.Bucket(params.Bucket)
if params.V4Auth {
s3obj.Signature = aws.V4Signature
} else {
if params.Region.Name == "eu-central-1" {
return nil, fmt.Errorf("The eu-central-1 region only works with v4 authentication")
}
}
// Validate that the given credentials have at least read permissions in the
// given bucket scope.
if _, err := bucket.List(strings.TrimRight(params.RootDirectory, "/"), "", "", 1); err != nil {
return nil, err
}
// TODO Currently multipart uploads have no timestamps, so this would be unwise
// if you initiated a new s3driver while another one is running on the same bucket.
// multis, _, err := bucket.ListMulti("", "")
// if err != nil {
// return nil, err
// }
// for _, multi := range multis {
// err := multi.Abort()
// //TODO appropriate to do this error checking?
// if err != nil {
// return nil, err
// }
// }
d := &driver{
S3: s3obj,
Bucket: bucket,
ChunkSize: params.ChunkSize,
Encrypt: params.Encrypt,
RootDirectory: params.RootDirectory,
}
return &Driver{
baseEmbed: baseEmbed{
Base: base.Base{
StorageDriver: d,
},
},
}, nil
}
示例7: New
// New constructs a new Driver with the given AWS credentials, region, encryption flag, and
// bucketName
func New(params DriverParameters) (*Driver, error) {
auth, err := aws.GetAuth(params.AccessKey, params.SecretKey, "", time.Time{})
if err != nil {
return nil, fmt.Errorf("unable to resolve aws credentials, please ensure that 'accesskey' and 'secretkey' are properly set or the credentials are available in $HOME/.aws/credentials: %v", err)
}
if !params.Secure {
params.Region.S3Endpoint = strings.Replace(params.Region.S3Endpoint, "https", "http", 1)
}
s3obj := s3.New(auth, params.Region)
bucket := s3obj.Bucket(params.Bucket)
if params.V4Auth {
s3obj.Signature = aws.V4Signature
} else {
if params.Region.Name == "eu-central-1" {
return nil, fmt.Errorf("The eu-central-1 region only works with v4 authentication")
}
}
// TODO Currently multipart uploads have no timestamps, so this would be unwise
// if you initiated a new s3driver while another one is running on the same bucket.
// multis, _, err := bucket.ListMulti("", "")
// if err != nil {
// return nil, err
// }
// for _, multi := range multis {
// err := multi.Abort()
// //TODO appropriate to do this error checking?
// if err != nil {
// return nil, err
// }
// }
d := &driver{
S3: s3obj,
Bucket: bucket,
ChunkSize: params.ChunkSize,
Encrypt: params.Encrypt,
RootDirectory: params.RootDirectory,
zeros: make([]byte, params.ChunkSize),
}
d.pool.New = func() interface{} {
return make([]byte, d.ChunkSize)
}
return &Driver{
baseEmbed: baseEmbed{
Base: base.Base{
StorageDriver: d,
},
},
}, nil
}
示例8: TestGetAuthStatic
func (s *S) TestGetAuthStatic(c *check.C) {
exptdate := time.Now().Add(time.Hour)
auth, err := aws.GetAuth("access", "secret", "token", exptdate)
c.Assert(err, check.IsNil)
c.Assert(auth.AccessKey, check.Equals, "access")
c.Assert(auth.SecretKey, check.Equals, "secret")
c.Assert(auth.Token(), check.Equals, "token")
c.Assert(auth.Expiration(), check.Equals, exptdate)
}
示例9: initAwsBucket
func initAwsBucket() {
expiration := time.Now().Add(time.Hour * 1)
auth, err := aws.GetAuth(config.AccessKey, config.SecretKey, "", expiration) //"" = token which isn't needed
if err != nil {
panic(err)
}
aws_bucket = s3.New(auth, aws.GetRegion(config.Region)).Bucket(config.Bucket)
}
示例10: getDynamoServer
func getDynamoServer(ctx *Context, region string) (*dynamodb.Server, error) {
Log(INFO, ctx, "getDynamoServer", "region", region)
// If we don't have real access keys, just try local. See
// ../local-dynamodb/. Otherwise go for real DynamoDB. ToDo:
// insist on using the real DynamoDB.
// ToDo: Combine with router/aws.go FindAWS()
if region == "local" {
r := aws.Region{DynamoDBEndpoint: "http://127.0.0.1:8000"}
auth := aws.Auth{AccessKey: "DUMMY_KEY", SecretKey: "DUMMY_SECRET"}
return dynamodb.New(auth, r), nil
} else if strings.HasPrefix(region, "http:") {
r := aws.Region{DynamoDBEndpoint: region}
auth, err := aws.GetAuth("", "", "", time.Now().Add(100000*time.Hour))
if err != nil {
Log(INFO, ctx, "router.FindAWS", "warning", err)
return nil, err
}
return dynamodb.New(auth, r), nil
} else {
auth, err := aws.EnvAuth()
if err != nil {
Log(INFO, ctx, "getDynamoServer", "warning", err, "when", "aws.EnvAuth")
// return nil, nil, err
// ToDo: Fix 100000 ...
auth, err = aws.GetAuth("", "", "", time.Now().Add(100000*time.Hour))
if err != nil {
Log(INFO, ctx, "router.FindAWS", "warning", err)
return nil, err
}
}
r, found := aws.Regions[region]
if !found {
err = fmt.Errorf("Bad region name '%s'", region)
Log(INFO, ctx, "getDynamoServer", "error", err)
return nil, err
}
return dynamodb.New(auth, r), nil
}
}
示例11: initAwsBucket
func initAwsBucket() {
fmt.Println("Initializing aws buccket bear!", config.Port)
expiration := time.Now().Add(time.Hour * 1)
auth, err := aws.GetAuth(config.AccessKey, config.SecretKey, "", expiration) //"" = token which isn't needed
if err != nil {
panic(err)
}
aws_bucket = s3.New(auth, aws.GetRegion(config.Region)).Bucket(config.Bucket)
}
示例12: New
func New(service string, region string, tableName string) *Discovery {
pk, err := tableDescription.BuildPrimaryKey()
if err != nil {
log.Fatal(err)
}
auth, err := aws.GetAuth("", "", "", time.Now())
dbServer := dynamodb.New(auth, aws.GetRegion(region))
table := dbServer.NewTable(tableName, pk)
return &Discovery{table: table, Service: service}
}
示例13: New
func (f *Factory) New(uri *url.URL) bridge.RegistryAdapter {
pk, err := tableDescription.BuildPrimaryKey()
if err != nil {
log.Fatal(err)
}
auth, err := aws.GetAuth("", "", "", time.Now())
dbServer := dynamodb.New(auth, aws.GetRegion(uri.Host))
table := dbServer.NewTable(strings.TrimPrefix(uri.Path, "/"), pk)
return &MikroAdapter{table: table}
}
示例14: Init
func (input *S3OffsetInput) Init(config interface{}) (err error) {
conf := config.(*S3OffsetInputConfig)
input.S3OffsetInputConfig = conf
if conf.MetaFile != "" {
// We already have the required metadata. Don't need to fetch it.
input.metaFileName = conf.MetaFile
} else if conf.ClientIdListFile != "" {
// Load clientids from file.
input.clientids, err = readLines(conf.ClientIdListFile)
if err != nil {
return fmt.Errorf("Error reading file %s for 'client_id_list': %s", conf.ClientIdListFile, err)
}
} else {
return fmt.Errorf("Missing parameter: You must specify either 'client_id_list' or 'metadata_file'")
}
auth, err := aws.GetAuth(conf.AWSKey, conf.AWSSecretKey, "", time.Now())
if err != nil {
return fmt.Errorf("Authentication error: %s\n", err)
}
region, ok := aws.Regions[conf.AWSRegion]
if !ok {
return fmt.Errorf("Parameter 'aws_region' must be a valid AWS Region")
}
s := s3.New(auth, region)
s.ConnectTimeout = time.Duration(conf.S3ConnectTimeout) * time.Second
s.ReadTimeout = time.Duration(conf.S3ReadTimeout) * time.Second
// TODO: ensure we can read from (and list, for meta) the buckets.
input.bucket = s.Bucket(conf.S3Bucket)
if conf.S3MetaBucket != "" {
input.metaBucket = s.Bucket(conf.S3MetaBucket)
} else if conf.MetaFile == "" {
return fmt.Errorf("Parameter 's3_meta_bucket' is required unless using 'metadata_file'")
}
// Remove any excess path separators from the bucket prefix.
conf.S3MetaBucketPrefix = CleanBucketPrefix(conf.S3MetaBucketPrefix)
input.stop = make(chan bool)
input.offsetChan = make(chan MessageLocation, 1000)
return nil
}
示例15: Init
func (input *S3SplitFileInput) Init(config interface{}) (err error) {
conf := config.(*S3SplitFileInputConfig)
input.S3SplitFileInputConfig = conf
input.schema, err = LoadSchema(conf.SchemaFile)
if err != nil {
return fmt.Errorf("Parameter 'schema_file' must be a valid JSON file: %s", err)
}
if conf.S3Bucket != "" {
auth, err := aws.GetAuth(conf.AWSKey, conf.AWSSecretKey, "", time.Now())
if err != nil {
return fmt.Errorf("Authentication error: %s\n", err)
}
region, ok := aws.Regions[conf.AWSRegion]
if !ok {
return fmt.Errorf("Parameter 'aws_region' must be a valid AWS Region")
}
s := s3.New(auth, region)
s.ConnectTimeout = time.Duration(conf.S3ConnectTimeout) * time.Second
s.ReadTimeout = time.Duration(conf.S3ReadTimeout) * time.Second
// TODO: ensure we can read from the bucket.
input.bucket = s.Bucket(conf.S3Bucket)
} else {
input.bucket = nil
}
if conf.S3ObjectMatchRegex != "" {
if input.objectMatch, err = regexp.Compile(conf.S3ObjectMatchRegex); err != nil {
err = fmt.Errorf("S3SplitFileInput: %s", err)
return
}
} else {
input.objectMatch = nil
}
// Remove any excess path separators from the bucket prefix.
conf.S3BucketPrefix = CleanBucketPrefix(conf.S3BucketPrefix)
input.stop = make(chan bool)
input.listChan = make(chan string, 1000)
return nil
}