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 verification service, service factory, and cloud provider control…
…lers Implement certificate generation and PDF generator
- Loading branch information
1 parent
1ad26aa
commit 3ff4020
Showing
13 changed files
with
301 additions
and
45 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 |
---|---|---|
@@ -1,24 +1,37 @@ | ||
FROM golang:1.19.4-alpine3.17 as builder | ||
|
||
RUN apk update && apk add git make bash | ||
# Start from the official Golang image to build the binary. | ||
FROM golang:alpine as builder | ||
|
||
# Enable Go modules. | ||
ENV GO111MODULE=on | ||
|
||
# Set the working directory outside $GOPATH to enable the support for modules. | ||
WORKDIR /app | ||
|
||
COPY . ./ | ||
# Copy go mod and sum files to download dependencies. | ||
COPY go.mod go.sum ./ | ||
|
||
# Download all dependencies. | ||
RUN go mod download | ||
|
||
# Do dep installs outside, due to private git modules | ||
# RUN make dep | ||
# Copy the source from the current directory to the working directory inside the container. | ||
COPY . . | ||
|
||
RUN make build | ||
# Build the Go app. | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o main . | ||
|
||
# Start a new stage from scratch for a smaller final image. | ||
FROM alpine:latest | ||
|
||
WORKDIR /app | ||
RUN apk --no-cache add ca-certificates | ||
|
||
WORKDIR /root/ | ||
|
||
COPY --from=builder /app/main /app/ | ||
COPY --from=builder /app/public /app/public | ||
COPY --from=builder /app/dist /app/dist | ||
# Copy the pre-built binary file from the previous stage. | ||
COPY --from=builder /app/main . | ||
|
||
EXPOSE 4001 | ||
# Command to run the executable. | ||
CMD ["./main"] | ||
|
||
CMD [ "/app/main" ] | ||
# Expose port 8080 to the outside world. | ||
EXPOSE 8080 |
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,32 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
// Import your service packages | ||
) | ||
|
||
// CertificateController handles certificate related requests | ||
type CertificateController struct { | ||
// fields for services | ||
} | ||
|
||
// NewCertificateController creates a new instance | ||
func NewCertificateController() *CertificateController { | ||
return &CertificateController{ | ||
// Initialize fields | ||
} | ||
} | ||
|
||
// GenerateCertificate handles requests to generate a destruction certificate | ||
func (ctrl *CertificateController) GenerateCertificate(c echo.Context) error { | ||
// certificate generation logic | ||
return c.JSON(http.StatusOK, certificate) | ||
} | ||
|
||
// GetCertificate retrieves a specific destruction certificate | ||
func (ctrl *CertificateController) GetCertificate(c echo.Context) error { | ||
// logic to retrieve a certificate | ||
return c.JSON(http.StatusOK, certificate) | ||
} |
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,32 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
// Import your service packages | ||
) | ||
|
||
// CloudProvidersController handles requests related to cloud providers | ||
type CloudProvidersController struct { | ||
// fields like service instances | ||
} | ||
|
||
// NewCloudProvidersController creates a new controller instance | ||
func NewCloudProvidersController() *CloudProvidersController { | ||
return &CloudProvidersController{ | ||
// fields | ||
} | ||
} | ||
|
||
// ListProviders handles GET requests to list cloud providers | ||
func (ctrl *CloudProvidersController) ListProviders(c echo.Context) error { | ||
// logic to list cloud providers | ||
return c.JSON(http.StatusOK, providers) | ||
} | ||
|
||
// InitiateDestruction handles POST requests to initiate data destruction | ||
func (ctrl *CloudProvidersController) InitiateDestruction(c echo.Context) error { | ||
// logic to start data destruction | ||
return c.JSON(http.StatusOK, response) | ||
} |
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,26 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
// service packages | ||
) | ||
|
||
// VerificationController handles requests related to verification of data destruction | ||
type VerificationController struct { | ||
// fields for services | ||
} | ||
|
||
// NewVerificationController creates a new controller instance | ||
func NewVerificationController() *VerificationController { | ||
return &VerificationController{ | ||
// Initialize fields | ||
} | ||
} | ||
|
||
// VerifyDestruction handles requests to verify data destruction | ||
func (ctrl *VerificationController) VerifyDestruction(c echo.Context) error { | ||
// verification logic | ||
return c.JSON(http.StatusOK, verificationResult) | ||
} |
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,21 @@ | ||
package services | ||
|
||
// Import AWS SDK | ||
|
||
// AWSVerificationService is an implementation of VerificationService for AWS | ||
type AWSVerificationService struct { | ||
// Add necessary fields, like AWS client | ||
} | ||
|
||
func NewAWSVerificationService( /* params */ ) *AWSVerificationService { | ||
return &AWSVerificationService{ | ||
// Initialize fields | ||
} | ||
} | ||
|
||
// VerifyDestruction checks if data has been completely destroyed on AWS | ||
func (svc *AWSVerificationService) VerifyDestruction(cloudProvider, identifier string) (bool, error) { | ||
// Implement logic to verify destruction on AWS | ||
// For example, check if an S3 object still exists | ||
return false, nil | ||
} |
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,21 @@ | ||
package services | ||
|
||
// Import Azure SDK | ||
|
||
// AzureVerificationService is an implementation of VerificationService for Azure | ||
type AzureVerificationService struct { | ||
// necessary fields, like Azure client | ||
} | ||
|
||
func NewAzureVerificationService( /* params */ ) *AzureVerificationService { | ||
return &AzureVerificationService{ | ||
// Initialize fields | ||
} | ||
} | ||
|
||
// VerifyDestruction checks if data has been completely destroyed on Azure | ||
func (svc *AzureVerificationService) VerifyDestruction(cloudProvider, identifier string) (bool, error) { | ||
// logic to verify destruction on Azure | ||
|
||
return false, nil | ||
} |
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,21 @@ | ||
package services | ||
|
||
// Import GCP SDK | ||
|
||
// GCPVerificationService is an implementation of VerificationService for GCP | ||
type GCPVerificationService struct { | ||
// necessary fields, like GCP client | ||
} | ||
|
||
func NewGCPVerificationService( /* params */ ) *GCPVerificationService { | ||
return &GCPVerificationService{ | ||
// Initialize fields | ||
} | ||
} | ||
|
||
// VerifyDestruction checks if data has been completely destroyed on GCP | ||
func (svc *GCPVerificationService) VerifyDestruction(cloudProvider, identifier string) (bool, error) { | ||
// logic to verify destruction on GCP | ||
|
||
return false, nil | ||
} |
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,17 @@ | ||
package services | ||
|
||
import "fmt" | ||
|
||
// GetVerificationService returns the appropriate verification service for a given cloud provider | ||
func GetVerificationService(cloudProvider string) (VerificationService, error) { | ||
switch cloudProvider { | ||
case "aws": | ||
return NewAWSVerificationService( /* params */ ), nil | ||
case "gcp": | ||
return NewGCPVerificationService( /* params */ ), nil | ||
case "azure": | ||
return NewAzureVerificationService( /* params */ ), nil | ||
default: | ||
return nil, fmt.Errorf("unsupported cloud provider: %s", cloudProvider) | ||
} | ||
} |
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,6 @@ | ||
package services | ||
|
||
// VerificationService defines the interface for a service that verifies data destruction | ||
type VerificationService interface { | ||
VerifyDestruction(cloudProvider, identifier string) (bool, error) | ||
} |
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,38 @@ | ||
package certificates | ||
|
||
import ( | ||
"bytes" | ||
"time" | ||
// Import packages for PDF or document generation | ||
) | ||
|
||
// DestructionCertificate contains the details for the data destruction certificate | ||
type DestructionCertificate struct { | ||
CloudProvider string | ||
Service string | ||
DataType string | ||
DestroyedAt time.Time | ||
AdditionalInfo map[string]string | ||
} | ||
|
||
// CertificateGenerator defines the interface for certificate generation | ||
type CertificateGenerator interface { | ||
Generate(certificate DestructionCertificate) ([]byte, error) | ||
} | ||
|
||
// PDFGenerator implements CertificateGenerator for PDF certificates | ||
type PDFGenerator struct { | ||
} | ||
|
||
// NewPDFGenerator creates a new instance of PDFGenerator | ||
func NewPDFGenerator() *PDFGenerator { | ||
return &PDFGenerator{} | ||
} | ||
|
||
// Generate creates a PDF certificate from the given DestructionCertificate details | ||
func (g *PDFGenerator) Generate(certificate DestructionCertificate) ([]byte, error) { | ||
var buf bytes.Buffer | ||
// Implement PDF generation logic, populating the buffer with the PDF data | ||
|
||
return buf.Bytes(), nil | ||
} |
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
version: '3.7' | ||
|
||
version: '3.8' | ||
|
||
services: | ||
postgres: | ||
image: postgres:13-alpine | ||
container_name: gotes-mx-pg | ||
restart: always | ||
environment: | ||
- POSTGRES_HOST_AUTH_METHOD=trust | ||
app: | ||
build: . | ||
ports: | ||
- '5757:5432' | ||
- "8080:8080" | ||
volumes: | ||
- .:/app | ||
- /app/node_modules | ||
environment: | ||
- GO_ENV=production | ||
command: ./main | ||
frontend: | ||
image: nginx:alpine | ||
volumes: | ||
- './postgres/data:/var/lib/postgresql/data' | ||
- ./dist:/usr/share/nginx/html:ro | ||
ports: | ||
- "80:80" |
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.