Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Add security and cloud service integration
Browse files Browse the repository at this point in the history
  • Loading branch information
austinsonger committed Dec 26, 2023
1 parent d52cb5d commit d7b97b5
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 14 deletions.
54 changes: 54 additions & 0 deletions api/services/aws.go
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.
59 changes: 59 additions & 0 deletions api/services/azure.go
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.
45 changes: 45 additions & 0 deletions api/services/gcp.go
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.
67 changes: 53 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,69 @@ module github.com/muhwyndhamhp/gotes-mx
go 1.20

require (
github.com/Azure/azure-storage-blob-go v0.15.0
github.com/apsystole/log v0.3.0
github.com/aws/aws-sdk-go v1.49.9
github.com/joho/godotenv v1.5.1
github.com/labstack/echo/v4 v4.11.1
github.com/yuin/goldmark v1.5.5
golang.org/x/time v0.3.0
gorm.io/driver/postgres v1.5.2
gorm.io/gorm v1.25.3
github.com/labstack/echo/v4 v4.11.4
github.com/yuin/goldmark v1.6.0
golang.org/x/time v0.5.0
google.golang.org/api v0.154.0
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

require (
github.com/a-h/templ v0.2.408
cloud.google.com/go v0.111.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mattn/go-ieproxy v0.0.11 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)

require (
cloud.google.com/go/storage v1.36.0
github.com/a-h/templ v0.2.501
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
Loading

0 comments on commit d7b97b5

Please sign in to comment.