Skip to content

Commit

Permalink
Introduce Bucket provider constants with the common part as a prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Pimenta <[email protected]>
  • Loading branch information
matheuscscp committed Aug 22, 2024
1 parent b2f08f5 commit d181710
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
17 changes: 17 additions & 0 deletions api/v1beta2/bucket_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,34 @@ const (
)

const (
// BucketProviderGeneric for any S3 API compatible storage Bucket.
BucketProviderGeneric string = "generic"
// BucketProviderAmazon for an AWS S3 object storage Bucket.
// Provides support for retrieving credentials from the AWS EC2 service.
BucketProviderAmazon string = "aws"
// BucketProviderGoogle for a Google Cloud Storage Bucket.
// Provides support for authentication using a workload identity.
BucketProviderGoogle string = "gcp"
// BucketProviderAzure for an Azure Blob Storage Bucket.
// Provides support for authentication using a Service Principal,
// Managed Identity or Shared Key.
BucketProviderAzure string = "azure"

// GenericBucketProvider for any S3 API compatible storage Bucket.
// Deprecated: use BucketProviderGeneric.
GenericBucketProvider string = "generic"
// AmazonBucketProvider for an AWS S3 object storage Bucket.
// Provides support for retrieving credentials from the AWS EC2 service.
// Deprecated: use BucketProviderAmazon.
AmazonBucketProvider string = "aws"
// GoogleBucketProvider for a Google Cloud Storage Bucket.
// Provides support for authentication using a workload identity.
// Deprecated: use BucketProviderGoogle.
GoogleBucketProvider string = "gcp"
// AzureBucketProvider for an Azure Blob Storage Bucket.
// Provides support for authentication using a Service Principal,
// Managed Identity or Shared Key.
// Deprecated: use BucketProviderAzure.
AzureBucketProvider string = "azure"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
// Construct provider client
var provider BucketProvider
switch obj.Spec.Provider {
case bucketv1.GoogleBucketProvider:
case bucketv1.BucketProviderGoogle:
if err = gcp.ValidateSecret(secret); err != nil {
e := serror.NewGeneric(err, sourcev1.AuthenticationFailedReason)
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
Expand All @@ -459,7 +459,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, sp *patch.Serial
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
return sreconcile.ResultEmpty, e
}
case bucketv1.AzureBucketProvider:
case bucketv1.BucketProviderAzure:
if err = azure.ValidateSecret(secret); err != nil {
e := serror.NewGeneric(err, sourcev1.AuthenticationFailedReason)
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ func TestBucketReconciler_reconcileSource_gcs(t *testing.T) {
Spec: bucketv1.BucketSpec{
BucketName: tt.bucketName,
Timeout: &metav1.Duration{Duration: timeout},
Provider: bucketv1.GoogleBucketProvider,
Provider: bucketv1.BucketProviderGoogle,
},
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func NewClient(bucket *sourcev1.Bucket, opts ...Option) (*MinioClient, error) {
switch bucketProvider := bucket.Spec.Provider; {
case o.secret != nil:
minioOpts.Creds = newCredsFromSecret(o.secret)
case bucketProvider == sourcev1.AmazonBucketProvider:
case bucketProvider == sourcev1.BucketProviderAmazon:
minioOpts.Creds = newAWSCreds(bucket, o.proxyURL)
case bucketProvider == sourcev1.GenericBucketProvider:
case bucketProvider == sourcev1.BucketProviderGeneric:
minioOpts.Creds = newGenericCreds(bucket, &o)
}

Expand Down Expand Up @@ -241,7 +241,7 @@ func ValidateSTSProvider(bucketProvider string, sts *sourcev1.BucketSTSSpec) err
sts.Provider)

switch bucketProvider {
case sourcev1.AmazonBucketProvider:
case sourcev1.BucketProviderAmazon:
switch sts.Provider {
case sourcev1.STSProviderAmazon:
if sts.SecretRef != nil {
Expand All @@ -254,7 +254,7 @@ func ValidateSTSProvider(bucketProvider string, sts *sourcev1.BucketSTSSpec) err
default:
return errProviderIncompatbility
}
case sourcev1.GenericBucketProvider:
case sourcev1.BucketProviderGeneric:
switch sts.Provider {
case sourcev1.STSProviderLDAP:
return nil
Expand Down

0 comments on commit d181710

Please sign in to comment.