diff --git a/internal/credential/attributes.go b/internal/credential/attributes.go index 7e0438e..eac891a 100644 --- a/internal/credential/attributes.go +++ b/internal/credential/attributes.go @@ -37,7 +37,7 @@ type CredentialAttributes struct { // CredentialsConfig used for configuring an AWS session. An status error is returned // with an InvalidArgument code if any unrecognized fields are found in the protobuf // struct input. -func GetCredentialsConfig(secrets *structpb.Struct, attrs *CredentialAttributes, required bool) (*awsutil.CredentialsConfig, error) { +func GetCredentialsConfig(secrets *structpb.Struct, attrs *CredentialAttributes) (*awsutil.CredentialsConfig, error) { // initialize secrets if it is nil // secrets can be nil because static credentials are optional if secrets == nil { @@ -49,13 +49,13 @@ func GetCredentialsConfig(secrets *structpb.Struct, attrs *CredentialAttributes, unknownFields := values.StructFields(secrets) badFields := make(map[string]string) - accessKey, err := values.GetStringValue(secrets, ConstAccessKeyId, required) + accessKey, err := values.GetStringValue(secrets, ConstAccessKeyId, false) if err != nil { badFields[fmt.Sprintf("secrets.%s", ConstAccessKeyId)] = err.Error() } delete(unknownFields, ConstAccessKeyId) - secretKey, err := values.GetStringValue(secrets, ConstSecretAccessKey, required) + secretKey, err := values.GetStringValue(secrets, ConstSecretAccessKey, false) if err != nil { badFields[fmt.Sprintf("secrets.%s", ConstSecretAccessKey)] = err.Error() } diff --git a/internal/credential/attributes_test.go b/internal/credential/attributes_test.go index 927f8bb..b21a662 100644 --- a/internal/credential/attributes_test.go +++ b/internal/credential/attributes_test.go @@ -105,7 +105,6 @@ func TestGetCredentialsConfig(t *testing.T) { cases := []struct { name string secrets *structpb.Struct - required bool attrs *CredentialAttributes expected *awsutil.CredentialsConfig expectedErrContains string @@ -136,32 +135,6 @@ func TestGetCredentialsConfig(t *testing.T) { Region: "us-west-2", }, }, - { - name: "missing access key", - secrets: &structpb.Struct{ - Fields: map[string]*structpb.Value{ - ConstSecretAccessKey: structpb.NewStringValue("bazqux"), - }, - }, - attrs: &CredentialAttributes{ - Region: "us-west-2", - }, - required: true, - expectedErrContains: "secrets.access_key_id: missing required value", - }, - { - name: "missing secret key", - secrets: &structpb.Struct{ - Fields: map[string]*structpb.Value{ - ConstAccessKeyId: structpb.NewStringValue("AKIAfoobar"), - }, - }, - required: true, - attrs: &CredentialAttributes{ - Region: "us-west-2", - }, - expectedErrContains: "secrets.secret_access_key: missing required value", - }, { name: "unknown fields", secrets: &structpb.Struct{ @@ -260,7 +233,7 @@ func TestGetCredentialsConfig(t *testing.T) { t.Run(tc.name, func(t *testing.T) { require := require.New(t) - actual, err := GetCredentialsConfig(tc.secrets, tc.attrs, tc.required) + actual, err := GetCredentialsConfig(tc.secrets, tc.attrs) if tc.expectedErrContains != "" { require.Error(err) require.Contains(err.Error(), tc.expectedErrContains) diff --git a/plugin/service/host/plugin.go b/plugin/service/host/plugin.go index f8befc5..944523a 100644 --- a/plugin/service/host/plugin.go +++ b/plugin/service/host/plugin.go @@ -51,7 +51,7 @@ func (p *HostPlugin) OnCreateCatalog(ctx context.Context, req *pb.OnCreateCatalo if err != nil { return nil, err } - credConfig, err := credential.GetCredentialsConfig(catalog.GetSecrets(), catalogAttributes.CredentialAttributes, false) + credConfig, err := credential.GetCredentialsConfig(catalog.GetSecrets(), catalogAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -139,7 +139,7 @@ func (p *HostPlugin) OnUpdateCatalog(ctx context.Context, req *pb.OnUpdateCatalo // Verify the incoming credentials are valid and return any errors to the // user if they're not. Note this doesn't validate the credentials against // AWS - it only does logical validation on the fields. - updatedCredentials, err := credential.GetCredentialsConfig(newCatalog.GetSecrets(), newCatalogAttributes.CredentialAttributes, false) + updatedCredentials, err := credential.GetCredentialsConfig(newCatalog.GetSecrets(), newCatalogAttributes.CredentialAttributes) if err != nil { return nil, err } diff --git a/plugin/service/storage/plugin.go b/plugin/service/storage/plugin.go index f973678..08b81e0 100644 --- a/plugin/service/storage/plugin.go +++ b/plugin/service/storage/plugin.go @@ -64,7 +64,7 @@ func (p *StoragePlugin) OnCreateStorageBucket(ctx context.Context, req *pb.OnCre return nil, err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -155,7 +155,7 @@ func (p *StoragePlugin) OnUpdateStorageBucket(ctx context.Context, req *pb.OnUpd // Verify the incoming credentials are valid and return any errors to the // user if they're not. Note this doesn't validate the credentials against // AWS - it only does logical validation on the fields. - updatedCredentials, err := cred.GetCredentialsConfig(newBucket.GetSecrets(), newStorageAttributes.CredentialAttributes, false) + updatedCredentials, err := cred.GetCredentialsConfig(newBucket.GetSecrets(), newStorageAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -318,7 +318,7 @@ func (p *StoragePlugin) HeadObject(ctx context.Context, req *pb.HeadObjectReques return nil, err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -386,7 +386,7 @@ func (p *StoragePlugin) ValidatePermissions(ctx context.Context, req *pb.Validat return nil, err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -444,7 +444,7 @@ func (p *StoragePlugin) GetObject(req *pb.GetObjectRequest, stream pb.StoragePlu return err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return err } @@ -555,7 +555,7 @@ func (p *StoragePlugin) PutObject(ctx context.Context, req *pb.PutObjectRequest) return nil, err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return nil, err } @@ -650,7 +650,7 @@ func (p *StoragePlugin) DeleteObjects(ctx context.Context, req *pb.DeleteObjects return nil, err } - credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes, false) + credConfig, err := cred.GetCredentialsConfig(bucket.GetSecrets(), storageAttributes.CredentialAttributes) if err != nil { return nil, err }