Skip to content

Commit

Permalink
Fixed mistake on update
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Jan 25, 2024
1 parent 2d998cd commit 0ea1c4d
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions pkg/handlers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/grycap/oscar/v2/pkg/types"
"github.com/grycap/oscar/v2/pkg/utils"
"github.com/grycap/oscar/v2/pkg/utils/auth"
"k8s.io/apimachinery/pkg/api/errors"
)

Expand All @@ -39,6 +40,38 @@ func MakeUpdateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
return
}

mcUntyped, mcExists := c.Get("mc")
uidOrigin, uidExists := c.Get("uid_origin")

if !mcExists {
c.String(http.StatusInternalServerError, fmt.Sprintf("Missing multitenancy config"))
}
if !uidExists {
c.String(http.StatusInternalServerError, fmt.Sprintf("Missing EGI user uid"))
}

mc, mcParsed := mcUntyped.(*auth.MultitenancyConfig)
uid, uidParsed := uidOrigin.(string)

if !mcParsed {
c.String(http.StatusInternalServerError, fmt.Sprintf("Error parsing multitenancy config: %v", mcParsed))
}

if !uidParsed {
c.String(http.StatusInternalServerError, fmt.Sprintf("Error parsing uid origin: %v", uidParsed))
}

// Check if users in allowed_users have a MinIO associated user
minIOAdminClient, _ := utils.MakeMinIOAdminClient(cfg)
uids := mc.CheckUsersInCache(newService.AllowedUsers)
if len(uids) == 0 {
for _, uid := range uids {
sk, _ := auth.GenerateRandomKey(8)
minIOAdminClient.CreateMinIOUser(uid, sk)
mc.CreateSecretForOIDC(uid, sk)
}
}

// Check service values and set defaults
checkValues(&newService, cfg)

Expand Down Expand Up @@ -91,7 +124,7 @@ func MakeUpdateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
}

// Update buckets
if err := updateBuckets(&newService, oldService, cfg); err != nil {
if err := updateBuckets(&newService, oldService, minIOAdminClient, cfg); err != nil {
if err == errInput {
c.String(http.StatusBadRequest, err.Error())
} else {
Expand All @@ -115,13 +148,13 @@ func MakeUpdateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
}
}

func updateBuckets(newService, oldService *types.Service, cfg *types.Config) error {
func updateBuckets(newService, oldService *types.Service, minIOAdminClient *utils.MinIOAdminClient, cfg *types.Config) error {
// Disable notifications from oldService.Input
if err := disableInputNotifications(oldService.GetMinIOWebhookARN(), oldService.Input, oldService.StorageProviders.MinIO[types.DefaultProvider]); err != nil {
return fmt.Errorf("error disabling MinIO input notifications: %v", err)
}

// Create the input and output buckets/folders from newService
// TODO fix
return createBuckets(newService, cfg, newService.AllowedUsers)
return createBuckets(newService, cfg, minIOAdminClient, newService.AllowedUsers)
}

0 comments on commit 0ea1c4d

Please sign in to comment.