// Create new AmazonSQS struct
func NewClient() *AmazonSQS {
	svc := &AmazonSQS{}
	svc.queues = make(map[string]*Queue)
	region := config.GetConfigValue(sqsConfigSectionName, "region", auth.EnvRegion())
	endpoint := config.GetConfigValue(sqsConfigSectionName, "endpoint", "")
	conf := auth.NewConfig(region, endpoint)
	conf.SetDefault(defaultRegion, defaultEndpoint)
	svc.client = SDK.New(conf.Config)
	return svc
}
// Create new AmazonSQS struct
func NewClient() *AmazonSNS {
	svc := &AmazonSNS{}
	svc.apps = make(map[string]*SNSApp)
	svc.topics = make(map[string]*SNSTopic)
	region := config.GetConfigValue(snsConfigSectionName, "region", auth.EnvRegion())
	endpoint := config.GetConfigValue(snsConfigSectionName, "endpoint", "")
	conf := auth.NewConfig(region, endpoint)
	conf.SetDefault(defaultRegion, defaultEndpoint)
	svc.Client = SDK.New(conf.Config)
	if config.GetConfigValue(snsConfigSectionName, "app.production", "false") != "false" {
		isProduction = true
	} else {
		isProduction = false
	}
	return svc
}
Beispiel #3
0
// Create new AmazonSQS struct
func NewClient() *AmazonSQS {
	svc := &AmazonSQS{}
	svc.queues = make(map[string]*Queue)
	region := config.GetConfigValue(sqsConfigSectionName, "region", auth.EnvRegion())
	awsConf := auth.NewConfig(region)
	endpoint := config.GetConfigValue(sqsConfigSectionName, "endpoint", "")
	switch {
	case endpoint != "":
		awsConf.Endpoint = endpoint
	case region == "":
		awsConf.Region = defaultRegion
		awsConf.Endpoint = defaultEndpoint
	}
	svc.client = SDK.New(awsConf)
	return svc
}
Beispiel #4
0
// return AWS authorization credentials
func Auth() *credentials.Credentials {
	if auth != nil {
		return auth
	}

	// return if environmental params for AWS auth
	e := credentials.NewEnvCredentials()
	_, err := e.Get()
	if err == nil {
		auth = e
		return auth
	}

	accessKey := config.GetConfigValue(authConfigSectionName, awsAccessConfigKey, "")
	secretKey := config.GetConfigValue(authConfigSectionName, awsSecretConfigKey, "")
	auth = credentials.NewStaticCredentials(accessKey, secretKey, "")
	return auth
}
Beispiel #5
0
// Create new AmazonDynamoDB struct
func NewClient() *AmazonDynamoDB {
	d := &AmazonDynamoDB{}
	d.tables = make(map[string]*DynamoTable)
	d.writeTables = make(map[string]bool)

	region := config.GetConfigValue(dynamodbConfigSectionName, "region", "")
	awsConf := auth.NewConfig(region)
	endpoint := config.GetConfigValue(dynamodbConfigSectionName, "endpoint", "")
	switch {
	case endpoint != "":
		awsConf.Endpoint = endpoint
	case region == "":
		awsConf.Region = defaultRegion
		awsConf.Endpoint = defaultEndpoint
	}
	d.client = SDK.New(awsConf)
	return d
}
Beispiel #6
0
// Create new AmazonS3 struct
func NewClient() *AmazonS3 {
	s := &AmazonS3{}
	s.buckets = make(map[string]*Bucket)
	region := config.GetConfigValue(s3ConfigSectionName, "region", "")
	awsConf := auth.NewConfig(region)
	endpoint := config.GetConfigValue(s3ConfigSectionName, "endpoint", "")
	switch {
	case endpoint != "":
		awsConf.Endpoint = endpoint
		awsConf.S3ForcePathStyle = true
	case region == "":
		awsConf.Region = defaultRegion
		awsConf.Endpoint = defaultEndpoint
		awsConf.S3ForcePathStyle = true
	}

	s.client = SDK.New(awsConf)
	return s
}
// Create new AmazonDynamoDB struct
func newClient(conf auth.Config) *AmazonDynamoDB {
	d := &AmazonDynamoDB{}
	d.tables = make(map[string]*DynamoTable)
	d.writeTables = make(map[string]bool)
	d.TablePrefix = config.GetConfigValue(dynamodbConfigSectionName, "prefix", defaultTablePrefix)

	conf.SetDefault(defaultRegion, defaultEndpoint)
	awsConf := conf.Config
	d.client = SDK.New(awsConf)
	return d
}
// Create SNS Topic and return `TopicARN`
func (svc *AmazonSNS) createTopic(name string) (string, error) {
	prefix := config.GetConfigValue(snsConfigSectionName, "prefix", defaultPrefix)
	in := &SDK.CreateTopicInput{
		Name: String(prefix + name),
	}
	resp, err := svc.Client.CreateTopic(in)
	if err != nil {
		log.Error("[SNS] error on `CreateTopic` operation, name="+name, err.Error())
		return "", err
	}
	return *resp.TopicArn, nil
}
Beispiel #9
0
// Create new AmazonSQS struct
func NewClient() *AmazonSNS {
	svc := &AmazonSNS{}
	svc.apps = make(map[string]*SNSApp)
	svc.topics = make(map[string]*SNSTopic)
	region := config.GetConfigValue(snsConfigSectionName, "region", auth.EnvRegion())
	awsConf := auth.NewConfig(region)
	endpoint := config.GetConfigValue(snsConfigSectionName, "endpoint", "")
	switch {
	case endpoint != "":
		awsConf.Endpoint = endpoint
	case region == "":
		awsConf.Region = defaultRegion
		awsConf.Endpoint = defaultEndpoint
	}
	svc.Client = SDK.New(awsConf)
	if config.GetConfigValue(snsConfigSectionName, "app.production", "false") != "false" {
		isProduction = true
	} else {
		isProduction = false
	}
	return svc
}
Beispiel #10
0
// get bucket
func (s *AmazonS3) GetBucket(bucket string) *Bucket {
	prefix := config.GetConfigValue(s3ConfigSectionName, "prefix", defaultBucketPrefix)
	bucketName := prefix + bucket

	// get the bucket from cache
	b, ok := s.buckets[bucketName]
	if ok {
		return b
	}

	b = &Bucket{}
	b.client = s.client
	b.name = bucketName
	s.buckets[bucketName] = b
	return b
}
// Get SNSApp struct
func (svc *AmazonSNS) GetApp(typ string) (*SNSApp, error) {
	// get the app from cache
	app, ok := svc.apps[typ]
	if ok {
		return app, nil
	}
	arn := config.GetConfigValue(snsConfigSectionName, "app."+typ, "")
	if arn == "" {
		errMsg := "[SNS] error, cannot find ARN setting"
		log.Error(errMsg, typ)
		return nil, errors.New(errMsg)
	}
	app = svc.NewApp(arn, typ)
	svc.apps[typ] = app
	return app, nil
}
// Get the prefix for DynamoDB table
func GetQueuePrefix() string {
	return config.GetConfigValue(sqsConfigSectionName, "prefix", defaultQueuePrefix)
}
Beispiel #13
0
// get the prefix for DynamoDB table
func GetTablePrefix() string {
	return config.GetConfigValue(dynamodbConfigSectionName, "prefix", defaultTablePrefix)
}
// Create new AmazonDynamoDB struct
func NewClient() *AmazonDynamoDB {
	region := config.GetConfigValue(dynamodbConfigSectionName, "region", "")
	endpoint := config.GetConfigValue(dynamodbConfigSectionName, "endpoint", "")
	conf := auth.NewConfig(region, endpoint)
	return newClient(conf)
}