From 223e1c95084d047118c73bfa86ffb8aab5cba5b5 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Mon, 10 Jun 2024 20:00:20 +0000 Subject: [PATCH] Amend README Signed-off-by: Gabriel Adrian Samfira --- README.md | 5 ++++- config/config.go | 8 ++++---- config/config_test.go | 16 ++++++++-------- internal/client/aws_test.go | 16 ++++++++-------- internal/spec/spec_test.go | 2 +- provider/provider_test.go | 18 +++++++++--------- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index ac2e1a1..d8927ce 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ region = "eu-central-1" subnet_id = "sample_subnet_id" [credentials] - credential_type = "access_key" + # Allowed values are: static, role + # When using IAM roles, you can omit the [credentials.static] section + credential_type = "static" + [credentials.static] access_key_id = "sample_access_key_id" secret_access_key = "sample_secret_access_key" session_token = "sample_session_token" diff --git a/config/config.go b/config/config.go index ff8440a..9b9be3b 100644 --- a/config/config.go +++ b/config/config.go @@ -28,8 +28,8 @@ import ( type AWSCredentialType string const ( - AWSCredentialTypeStaticCredentials AWSCredentialType = "static" - AWSCredentialTypeRole AWSCredentialType = "role" + AWSCredentialTypeStatic AWSCredentialType = "static" + AWSCredentialTypeRole AWSCredentialType = "role" ) // NewConfig returns a new Config @@ -99,7 +99,7 @@ type Credentials struct { func (c Credentials) Validate() error { switch c.CredentialType { - case AWSCredentialTypeStaticCredentials: + case AWSCredentialTypeStatic: return c.StaticCredentials.Validate() case AWSCredentialTypeRole: case "": @@ -118,7 +118,7 @@ func (c Config) GetAWSConfig(ctx context.Context) (aws.Config, error) { var cfg aws.Config var err error switch c.Credentials.CredentialType { - case AWSCredentialTypeStaticCredentials: + case AWSCredentialTypeStatic: cfg, err = config.LoadDefaultConfig(ctx, config.WithCredentialsProvider( credentials.NewStaticCredentialsProvider( diff --git a/config/config_test.go b/config/config_test.go index 469cf60..23dc01f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -32,7 +32,7 @@ func TestConfigValidate(t *testing.T) { name: "valid config", c: &Config{ Credentials: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret_access_key", @@ -48,7 +48,7 @@ func TestConfigValidate(t *testing.T) { name: "missing subnet_id", c: &Config{ Credentials: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret_access_key", @@ -63,7 +63,7 @@ func TestConfigValidate(t *testing.T) { name: "missing region", c: &Config{ Credentials: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret_access_key", @@ -116,7 +116,7 @@ func TestCredentialsValidate(t *testing.T) { { name: "valid credentials", c: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret_access_key", @@ -128,7 +128,7 @@ func TestCredentialsValidate(t *testing.T) { { name: "missing access_key_id", c: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "", SecretAccessKey: "secret_access_key", @@ -140,7 +140,7 @@ func TestCredentialsValidate(t *testing.T) { { name: "missing secret_access_key", c: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "", @@ -152,7 +152,7 @@ func TestCredentialsValidate(t *testing.T) { { name: "missing session_token", c: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret_access_key", @@ -205,7 +205,7 @@ func TestNewConfig(t *testing.T) { require.NoError(t, err, "NewConfig() should not have returned an error") require.Equal(t, &Config{ Credentials: Credentials{ - CredentialType: AWSCredentialTypeStaticCredentials, + CredentialType: AWSCredentialTypeStatic, StaticCredentials: StaticCredentials{ AccessKeyID: "access_key_id", SecretAccessKey: "secret", diff --git a/internal/client/aws_test.go b/internal/client/aws_test.go index 96efdaa..fbdf64e 100644 --- a/internal/client/aws_test.go +++ b/internal/client/aws_test.go @@ -35,7 +35,7 @@ func TestStartInstance(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -65,7 +65,7 @@ func TestStopInstance(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -95,7 +95,7 @@ func TestFindInstances(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -154,7 +154,7 @@ func TestFindOneInstanceWithName(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -207,7 +207,7 @@ func TestFindOneInstanceWithID(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -249,7 +249,7 @@ func TestGetInstance(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -288,7 +288,7 @@ func TestTerminateInstance(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -336,7 +336,7 @@ func TestCreateRunningInstance(t *testing.T) { Region: "us-west-2", SubnetID: "subnet-1234567890abcdef0", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", diff --git a/internal/spec/spec_test.go b/internal/spec/spec_test.go index 4487a70..b70f274 100644 --- a/internal/spec/spec_test.go +++ b/internal/spec/spec_test.go @@ -120,7 +120,7 @@ func TestGetRunnerSpecFromBootstrapParams(t *testing.T) { config := &config.Config{ Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", diff --git a/provider/provider_test.go b/provider/provider_test.go index 945bb59..35b8195 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -74,7 +74,7 @@ func TestCreateInstance(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -109,7 +109,7 @@ func TestDeleteInstanceWithID(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -140,7 +140,7 @@ func TestDeleteInstanceWithName(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -204,7 +204,7 @@ func TestGetInstanceWithID(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -276,7 +276,7 @@ func TestGetInstanceWithName(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -363,7 +363,7 @@ func TestListInstances(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -452,7 +452,7 @@ func TestStop(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -482,7 +482,7 @@ func TestStartStoppedInstance(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey", @@ -534,7 +534,7 @@ func TestStartStoppingInstance(t *testing.T) { Region: "us-east-1", SubnetID: "subnet-123456", Credentials: config.Credentials{ - CredentialType: config.AWSCredentialTypeStaticCredentials, + CredentialType: config.AWSCredentialTypeStatic, StaticCredentials: config.StaticCredentials{ AccessKeyID: "AccessKeyID", SecretAccessKey: "SecretAccessKey",