fix credential usage
Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>
This commit is contained in:
parent
c6d7cdd6d7
commit
e9c6d0021b
5 changed files with 13 additions and 30 deletions
|
|
@ -43,7 +43,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
||||||
|
|
||||||
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/metrics"
|
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/metrics"
|
||||||
"github.com/vmware/vmware-go-kcl-v2/logger"
|
"github.com/vmware/vmware-go-kcl-v2/logger"
|
||||||
|
|
@ -174,10 +173,10 @@ type (
|
||||||
KinesisEndpoint string
|
KinesisEndpoint string
|
||||||
|
|
||||||
// KinesisCredentials is used to access Kinesis
|
// KinesisCredentials is used to access Kinesis
|
||||||
KinesisCredentials *credentials.StaticCredentialsProvider
|
KinesisCredentials aws.CredentialsProvider
|
||||||
|
|
||||||
// DynamoDBCredentials is used to access DynamoDB
|
// DynamoDBCredentials is used to access DynamoDB
|
||||||
DynamoDBCredentials *credentials.StaticCredentialsProvider
|
DynamoDBCredentials aws.CredentialsProvider
|
||||||
|
|
||||||
// TableName is name of the dynamo db table for managing kinesis stream default to ApplicationName
|
// TableName is name of the dynamo db table for managing kinesis stream default to ApplicationName
|
||||||
TableName string
|
TableName string
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
|
|
||||||
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/metrics"
|
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/metrics"
|
||||||
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/utils"
|
"github.com/vmware/vmware-go-kcl-v2/clientlibrary/utils"
|
||||||
|
|
@ -55,13 +55,13 @@ func NewKinesisClientLibConfig(applicationName, streamName, regionName, workerID
|
||||||
|
|
||||||
// NewKinesisClientLibConfigWithCredential creates a default KinesisClientLibConfiguration based on the required fields and unique credentials.
|
// NewKinesisClientLibConfigWithCredential creates a default KinesisClientLibConfiguration based on the required fields and unique credentials.
|
||||||
func NewKinesisClientLibConfigWithCredential(applicationName, streamName, regionName, workerID string,
|
func NewKinesisClientLibConfigWithCredential(applicationName, streamName, regionName, workerID string,
|
||||||
creds *credentials.StaticCredentialsProvider) *KinesisClientLibConfiguration {
|
creds aws.CredentialsProvider) *KinesisClientLibConfiguration {
|
||||||
return NewKinesisClientLibConfigWithCredentials(applicationName, streamName, regionName, workerID, creds, creds)
|
return NewKinesisClientLibConfigWithCredentials(applicationName, streamName, regionName, workerID, creds, creds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKinesisClientLibConfigWithCredentials creates a default KinesisClientLibConfiguration based on the required fields and specific credentials for each service.
|
// NewKinesisClientLibConfigWithCredentials creates a default KinesisClientLibConfiguration based on the required fields and specific credentials for each service.
|
||||||
func NewKinesisClientLibConfigWithCredentials(applicationName, streamName, regionName, workerID string,
|
func NewKinesisClientLibConfigWithCredentials(applicationName, streamName, regionName, workerID string,
|
||||||
kinesisCreds, dynamodbCreds *credentials.StaticCredentialsProvider) *KinesisClientLibConfiguration {
|
kinesisCreds, dynamodbCreds aws.CredentialsProvider) *KinesisClientLibConfiguration {
|
||||||
checkIsValueNotEmpty("ApplicationName", applicationName)
|
checkIsValueNotEmpty("ApplicationName", applicationName)
|
||||||
checkIsValueNotEmpty("StreamName", streamName)
|
checkIsValueNotEmpty("StreamName", streamName)
|
||||||
checkIsValueNotEmpty("RegionName", regionName)
|
checkIsValueNotEmpty("RegionName", regionName)
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
||||||
|
|
||||||
cwatch "github.com/aws/aws-sdk-go-v2/service/cloudwatch"
|
cwatch "github.com/aws/aws-sdk-go-v2/service/cloudwatch"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
|
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
|
||||||
|
|
||||||
|
|
@ -51,7 +49,7 @@ type MonitoringService struct {
|
||||||
streamName string
|
streamName string
|
||||||
workerID string
|
workerID string
|
||||||
region string
|
region string
|
||||||
credentials *credentials.StaticCredentialsProvider
|
credentials aws.CredentialsProvider
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
|
|
||||||
// control how often to publish to CloudWatch
|
// control how often to publish to CloudWatch
|
||||||
|
|
@ -76,13 +74,13 @@ type cloudWatchMetrics struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMonitoringService returns a Monitoring service publishing metrics to CloudWatch.
|
// NewMonitoringService returns a Monitoring service publishing metrics to CloudWatch.
|
||||||
func NewMonitoringService(region string, creds *credentials.StaticCredentialsProvider) *MonitoringService {
|
func NewMonitoringService(region string, creds aws.CredentialsProvider) *MonitoringService {
|
||||||
return NewMonitoringServiceWithOptions(region, creds, logger.GetDefaultLogger(), DefaultCloudwatchMetricsBufferDuration)
|
return NewMonitoringServiceWithOptions(region, creds, logger.GetDefaultLogger(), DefaultCloudwatchMetricsBufferDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMonitoringServiceWithOptions returns a Monitoring service publishing metrics to
|
// NewMonitoringServiceWithOptions returns a Monitoring service publishing metrics to
|
||||||
// CloudWatch with the provided credentials, buffering duration and logger.
|
// CloudWatch with the provided credentials, buffering duration and logger.
|
||||||
func NewMonitoringServiceWithOptions(region string, creds *credentials.StaticCredentialsProvider, logger logger.Logger, bufferDur time.Duration) *MonitoringService {
|
func NewMonitoringServiceWithOptions(region string, creds aws.CredentialsProvider, logger logger.Logger, bufferDur time.Duration) *MonitoringService {
|
||||||
return &MonitoringService{
|
return &MonitoringService{
|
||||||
region: region,
|
region: region,
|
||||||
credentials: creds,
|
credentials: creds,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ import (
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
||||||
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
||||||
|
|
||||||
chk "github.com/vmware/vmware-go-kcl-v2/clientlibrary/checkpoint"
|
chk "github.com/vmware/vmware-go-kcl-v2/clientlibrary/checkpoint"
|
||||||
|
|
@ -171,11 +170,7 @@ func (w *Worker) initialize() error {
|
||||||
cfg, err := awsConfig.LoadDefaultConfig(
|
cfg, err := awsConfig.LoadDefaultConfig(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
awsConfig.WithRegion(w.regionName),
|
awsConfig.WithRegion(w.regionName),
|
||||||
awsConfig.WithCredentialsProvider(
|
awsConfig.WithCredentialsProvider(w.kclConfig.KinesisCredentials),
|
||||||
credentials.NewStaticCredentialsProvider(
|
|
||||||
w.kclConfig.KinesisCredentials.Value.AccessKeyID,
|
|
||||||
w.kclConfig.KinesisCredentials.Value.SecretAccessKey,
|
|
||||||
w.kclConfig.KinesisCredentials.Value.SessionToken)),
|
|
||||||
awsConfig.WithEndpointResolver(resolver),
|
awsConfig.WithEndpointResolver(resolver),
|
||||||
awsConfig.WithRetryer(func() aws.Retryer {
|
awsConfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
"github.com/aws/aws-sdk-go-v2/aws/retry"
|
||||||
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
"github.com/aws/aws-sdk-go-v2/service/kinesis"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
|
"github.com/aws/aws-sdk-go-v2/service/kinesis/types"
|
||||||
|
|
@ -42,7 +41,7 @@ import (
|
||||||
const specstr = `{"name":"kube-qQyhk","networking":{"containerNetworkCidr":"10.2.0.0/16"},"orgName":"BVT-Org-cLQch","projectName":"project-tDSJd","serviceLevel":"DEVELOPER","size":{"count":1},"version":"1.8.1-4"}`
|
const specstr = `{"name":"kube-qQyhk","networking":{"containerNetworkCidr":"10.2.0.0/16"},"orgName":"BVT-Org-cLQch","projectName":"project-tDSJd","serviceLevel":"DEVELOPER","size":{"count":1},"version":"1.8.1-4"}`
|
||||||
|
|
||||||
// NewKinesisClient to create a Kinesis Client.
|
// NewKinesisClient to create a Kinesis Client.
|
||||||
func NewKinesisClient(t *testing.T, regionName, endpoint string, creds *credentials.StaticCredentialsProvider) *kinesis.Client {
|
func NewKinesisClient(t *testing.T, regionName, endpoint string, creds aws.CredentialsProvider) *kinesis.Client {
|
||||||
// create session for Kinesis
|
// create session for Kinesis
|
||||||
t.Logf("Creating Kinesis client")
|
t.Logf("Creating Kinesis client")
|
||||||
|
|
||||||
|
|
@ -57,11 +56,7 @@ func NewKinesisClient(t *testing.T, regionName, endpoint string, creds *credenti
|
||||||
cfg, err := awsConfig.LoadDefaultConfig(
|
cfg, err := awsConfig.LoadDefaultConfig(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
awsConfig.WithRegion(regionName),
|
awsConfig.WithRegion(regionName),
|
||||||
awsConfig.WithCredentialsProvider(
|
awsConfig.WithCredentialsProvider(creds),
|
||||||
credentials.NewStaticCredentialsProvider(
|
|
||||||
creds.Value.AccessKeyID,
|
|
||||||
creds.Value.SecretAccessKey,
|
|
||||||
creds.Value.SessionToken)),
|
|
||||||
awsConfig.WithEndpointResolver(resolver),
|
awsConfig.WithEndpointResolver(resolver),
|
||||||
awsConfig.WithRetryer(func() aws.Retryer {
|
awsConfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
||||||
|
|
@ -77,7 +72,7 @@ func NewKinesisClient(t *testing.T, regionName, endpoint string, creds *credenti
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDynamoDBClient to create a Kinesis Client.
|
// NewDynamoDBClient to create a Kinesis Client.
|
||||||
func NewDynamoDBClient(t *testing.T, regionName, endpoint string, creds *credentials.StaticCredentialsProvider) *dynamodb.Client {
|
func NewDynamoDBClient(t *testing.T, regionName, endpoint string, creds aws.CredentialsProvider) *dynamodb.Client {
|
||||||
resolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
|
resolver := aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
|
||||||
return aws.Endpoint{
|
return aws.Endpoint{
|
||||||
PartitionID: "aws",
|
PartitionID: "aws",
|
||||||
|
|
@ -89,11 +84,7 @@ func NewDynamoDBClient(t *testing.T, regionName, endpoint string, creds *credent
|
||||||
cfg, err := awsConfig.LoadDefaultConfig(
|
cfg, err := awsConfig.LoadDefaultConfig(
|
||||||
context.TODO(),
|
context.TODO(),
|
||||||
awsConfig.WithRegion(regionName),
|
awsConfig.WithRegion(regionName),
|
||||||
awsConfig.WithCredentialsProvider(
|
awsConfig.WithCredentialsProvider(creds),
|
||||||
credentials.NewStaticCredentialsProvider(
|
|
||||||
creds.Value.AccessKeyID,
|
|
||||||
creds.Value.SecretAccessKey,
|
|
||||||
creds.Value.SessionToken)),
|
|
||||||
awsConfig.WithEndpointResolver(resolver),
|
awsConfig.WithEndpointResolver(resolver),
|
||||||
awsConfig.WithRetryer(func() aws.Retryer {
|
awsConfig.WithRetryer(func() aws.Retryer {
|
||||||
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
return retry.AddWithMaxBackoffDelay(retry.NewStandard(), retry.DefaultMaxBackoff)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue