Skip to content

Commit

Permalink
resolve test
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioLangaritaBenitez committed Jan 10, 2025
1 parent eb812c1 commit f9ae520
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 4 additions & 1 deletion pkg/handlers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ func createBuckets(service *types.Service, cfg *types.Config, minIOAdminClient *
}

if !isAdminUser {
minIOAdminClient.CreateAddPolicy(b, service.AllowedUsers[i], false)
err = minIOAdminClient.CreateAddPolicy(b, service.AllowedUsers[i], false)
if err != nil {
return err
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/handlers/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ func deleteBuckets(service *types.Service, cfg *types.Config, minIOAdminClient *
// Delete user's buckets if isolated spaces had been created
if strings.ToUpper(service.IsolationLevel) == "USER" && len(service.BucketList) > 0 {
// Delete all private buckets
deletePrivateBuckets(service, minIOAdminClient, s3Client)
err = deletePrivateBuckets(service, minIOAdminClient, s3Client)
if err != nil {
return fmt.Errorf("error while disable the input notification")
}
}
}

Expand All @@ -195,7 +198,10 @@ func deleteBuckets(service *types.Service, cfg *types.Config, minIOAdminClient *
// Check if the provider identifier is defined in StorageProviders
if !isStorageProviderDefined(provName, provID, service.StorageProviders) {
// TODO fix
disableInputNotifications(s3Client, service.GetMinIOWebhookARN(), "")
err := disableInputNotifications(s3Client, service.GetMinIOWebhookARN(), "")
if err != nil {
return fmt.Errorf("error while disable the input notification")
}
return fmt.Errorf("the StorageProvider \"%s.%s\" is not defined", provName, provID)
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ func MakeUpdateHandler(cfg *types.Config, back types.ServerlessBackend) gin.Hand
return
}

disableInputNotifications(s3Client, oldService.GetMinIOWebhookARN(), splitPath[0])

err = disableInputNotifications(s3Client, oldService.GetMinIOWebhookARN(), splitPath[0])
if err != nil {
return
}
// Register minio webhook and restart the server
if err := registerMinIOWebhook(newService.Name, newService.Token, newService.StorageProviders.MinIO[types.DefaultProvider], cfg); err != nil {
uerr := back.UpdateService(*oldService)
Expand Down
13 changes: 9 additions & 4 deletions pkg/utils/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ func (minIOAdminClient *MinIOAdminClient) CreateAddPolicy(bucketName string, pol
policy = []byte(p)
} else {
actualPolicy := &Policy{}
json.Unmarshal(policyInfo.Policy, actualPolicy)

err := json.Unmarshal(policyInfo.Policy, actualPolicy)
if err != nil {
return fmt.Errorf("error unmarshal, the policy is not in correct format")
}
// Add new resource and create policy
actualPolicy.Statement = []Statement{
{
Expand Down Expand Up @@ -402,7 +404,10 @@ func (minIOAdminClient *MinIOAdminClient) RemoveFromPolicy(bucketName string, po
return fmt.Errorf("policy '%s' does not exist: %v", policyName, errInfo)
}
actualPolicy := &Policy{}
json.Unmarshal(policyInfo.Policy, actualPolicy)
err := json.Unmarshal(policyInfo.Policy, actualPolicy)
if err != nil {
return fmt.Errorf("error unmarshal, the policy is not in correct format")
}
if len(actualPolicy.Statement[0].Resource) == 1 {
if err := minIOAdminClient.adminClient.RemoveCannedPolicy(context.TODO(), policyName); err != nil {
return fmt.Errorf("error removing canned policy: %v", err)
Expand All @@ -422,7 +427,7 @@ func (minIOAdminClient *MinIOAdminClient) RemoveFromPolicy(bucketName string, po
return jsonErr
}

err := minIOAdminClient.adminClient.AddCannedPolicy(context.TODO(), policyName, []byte(policy))
err = minIOAdminClient.adminClient.AddCannedPolicy(context.TODO(), policyName, []byte(policy))
if err != nil {
return fmt.Errorf("error creating MinIO policy for user %s: %v", policyName, err)
}
Expand Down

0 comments on commit f9ae520

Please sign in to comment.