TP-5555 | account provision

This commit is contained in:
varnit goyal
2024-11-29 16:20:01 +05:30
parent 09b2c9a88f
commit c04e0a9157
12 changed files with 115 additions and 39 deletions

View File

@@ -5,9 +5,10 @@ import (
"cybertron/configs"
"cybertron/internal/client/aws"
"cybertron/models/db"
"fmt"
"cybertron/pkg/log"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"gorm.io/gorm"
"net/http"
"path"
@@ -18,6 +19,7 @@ type SourceMapService struct {
dbClient *gorm.DB
s3Client *aws.Actions
awsConfig *configs.AwsConfig
logger *log.Logger
}
type SourceMapAckBody struct {
@@ -26,11 +28,12 @@ type SourceMapAckBody struct {
FileName string `json:"fileName" binding:"required"`
}
func NewSourceMapService(dbClient *gorm.DB, s3Client *aws.Actions, config *configs.AwsConfig) *SourceMapService {
func NewSourceMapService(logger *log.Logger, dbClient *gorm.DB, s3Client *aws.Actions, config *configs.AwsConfig) *SourceMapService {
return &SourceMapService{
dbClient: dbClient,
s3Client: s3Client,
awsConfig: config,
logger: logger,
}
}
@@ -38,6 +41,12 @@ func (s *SourceMapService) GetSourceMapUploadUrl(ctx *gin.Context) {
projectId := ctx.Query("project_id")
releaseId := ctx.Query("release_id")
fileName := ctx.Query("file_name")
account := ctx.DefaultQuery("account", "ppl")
appendedAccount := "-" + account
if appendedAccount == "ppl" {
appendedAccount = ""
}
if projectId == "" || releaseId == "" || fileName == "" {
ctx.JSON(http.StatusBadRequest, gin.H{
@@ -48,7 +57,7 @@ func (s *SourceMapService) GetSourceMapUploadUrl(ctx *gin.Context) {
//generate s3 pre-signed url
key := path.Join(projectId, releaseId, fileName)
bucket := s.awsConfig.Bucket
bucket := s.awsConfig.Bucket + appendedAccount
request, err := s.s3Client.S3PresignClient.PresignPutObject(context.TODO(), &s3.PutObjectInput{
Bucket: &bucket,
Key: &key,
@@ -56,7 +65,7 @@ func (s *SourceMapService) GetSourceMapUploadUrl(ctx *gin.Context) {
opts.Expires = time.Duration(7 * 24 * time.Hour)
})
if err != nil {
fmt.Println(err)
s.logger.Error("unable to generate pre-signed url", zap.Error(err))
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "unable to create S3 object"})
return
}