This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
generated from muhwyndhamhp/gotes-mx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add security and cloud service integration
- Loading branch information
1 parent
d52cb5d
commit d7b97b5
Showing
17 changed files
with
490 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package services | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
) | ||
|
||
// AWSService struct holds the AWS clients and related configurations | ||
type AWSService struct { | ||
S3Client *s3.S3 | ||
} | ||
|
||
// NewAWSService creates a new instance of AWSService with initialized AWS clients | ||
func NewAWSService() *AWSService { | ||
sess := session.Must(session.NewSession(&aws.Config{ | ||
Region: aws.String("your-region"), // specify the AWS region | ||
})) | ||
|
||
return &AWSService{ | ||
S3Client: s3.New(sess), | ||
} | ||
} | ||
|
||
// DeleteObject deletes an object from an S3 bucket and returns a boolean indicating success | ||
func (svc *AWSService) DeleteObject(bucket, key string) (bool, error) { | ||
_, err := svc.S3Client.DeleteObject(&s3.DeleteObjectInput{ | ||
Bucket: aws.String(bucket), | ||
Key: aws.String(key), | ||
}) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// Optionally, add logic to wait for the deletion to be confirmed. | ||
// This can be done using the WaitUntilObjectNotExists function with the required input. | ||
|
||
return true, nil | ||
} | ||
|
||
// VerifyDeletion checks if an object exists in an S3 bucket to confirm deletion | ||
func (svc *AWSService) VerifyDeletion(bucket, key string) (bool, error) { | ||
_, err := svc.S3Client.HeadObject(&s3.HeadObjectInput{ | ||
Bucket: aws.String(bucket), | ||
Key: aws.String(key), | ||
}) | ||
if err != nil { | ||
// Handle the specific error to determine if it's because the object doesn't exist | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
// Generate additional functions as needed for other AWS services or operations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"github.com/Azure/azure-storage-blob-go/azblob" | ||
"net/url" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// AzureService struct holds the Azure clients and related configurations | ||
type AzureService struct { | ||
ServiceURL azblob.ServiceURL | ||
} | ||
|
||
// NewAzureService creates a new instance of AzureService with initialized Azure clients | ||
func NewAzureService(accountName, accountKey string) (*AzureService, error) { | ||
credential, err := azblob.NewSharedKeyCredential(accountName, accountKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pipeline := azblob.NewPipeline(credential, azblob.PipelineOptions{}) | ||
u, _ := url.Parse("https://" + accountName + ".blob.core.windows.net") | ||
serviceURL := azblob.NewServiceURL(*u, pipeline) | ||
|
||
return &AzureService{ | ||
ServiceURL: serviceURL, | ||
}, nil | ||
} | ||
|
||
// DeleteBlob deletes a blob from an Azure storage container and returns a boolean indicating success | ||
func (svc *AzureService) DeleteBlob(ctx context.Context, containerName, blobName string) (bool, error) { | ||
containerURL := svc.ServiceURL.NewContainerURL(containerName) | ||
blobURL := containerURL.NewBlockBlobURL(blobName) | ||
|
||
_, err := blobURL.Delete(ctx, azblob.DeleteSnapshotsOptionInclude, azblob.BlobAccessConditions{}) | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
// VerifyDeletion checks if a blob exists in an Azure storage container to confirm deletion | ||
func (svc *AzureService) VerifyDeletion(ctx context.Context, containerName, blobName string) (bool, error) { | ||
containerURL := svc.ServiceURL.NewContainerURL(containerName) | ||
blobURL := containerURL.NewBlockBlobURL(blobName) | ||
|
||
_, err := blobURL.GetProperties(ctx, azblob.BlobAccessConditions{}, azblob.ClientProvidedKeyOptions{}) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "BlobNotFound") { | ||
return true, nil | ||
} | ||
return false, err | ||
} | ||
return false, nil | ||
} | ||
|
||
// Add additional functions for other Azure services or more detailed operations as needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"cloud.google.com/go/storage" | ||
"google.golang.org/api/iterator" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
// GCPService struct holds the GCP clients and related configurations | ||
type GCPService struct { | ||
StorageClient *storage.Client | ||
} | ||
|
||
// NewGCPService creates a new instance of GCPService with initialized GCP clients | ||
func NewGCPService(ctx context.Context, credsFilePath string) (*GCPService, error) { | ||
client, err := storage.NewClient(ctx, option.WithCredentialsFile(credsFilePath)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &GCPService{ | ||
StorageClient: client, | ||
}, nil | ||
} | ||
|
||
// DeleteObject deletes an object from a GCS bucket and returns a boolean indicating success | ||
func (svc *GCPService) DeleteObject(ctx context.Context, bucket, object string) (bool, error) { | ||
err := svc.StorageClient.Bucket(bucket).Object(object).Delete(ctx) | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
// VerifyDeletion checks if an object exists in a GCS bucket to confirm deletion | ||
func (svc *GCPService) VerifyDeletion(ctx context.Context, bucket, object string) (bool, error) { | ||
_, err := svc.StorageClient.Bucket(bucket).Object(object).Attrs(ctx) | ||
if err == storage.ErrObjectNotExist { | ||
return true, nil | ||
} | ||
return false, err | ||
} | ||
|
||
// Add additional functions for other GCP services or more detailed operations as needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.