Skip to content

Commit

Permalink
Fixed variable and updated config handler
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Jan 31, 2024
1 parent 62de966 commit 9df9bad
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
54 changes: 53 additions & 1 deletion pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,67 @@ limitations under the License.
package handlers

import (
"fmt"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/grycap/oscar/v2/pkg/types"
"github.com/grycap/oscar/v2/pkg/utils/auth"
)

type configForUser struct {
Cfg *types.Config `json:"config"`
MinIOProvider *types.MinIOProvider `json:"minio_provider"`
}

// MakeConfigHandler makes a handler for getting server's configuration
func MakeConfigHandler(cfg *types.Config) gin.HandlerFunc {
return func(c *gin.Context) {
c.JSON(http.StatusOK, cfg)
// Return configForUser
var conf configForUser
minIOProvider := cfg.MinIOProvider
authHeader := c.GetHeader("Authorization")
if len(strings.Split(authHeader, "Bearer")) > 0 {
conf = configForUser{cfg, minIOProvider}
} else {

// Get MinIO credentials from k8s secret for user

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

if !mcExists {
c.String(http.StatusInternalServerError, "Missing multitenancy config")
}
if !uidExists {
c.String(http.StatusInternalServerError, "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))
return
}

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

ak, sk, err := mc.GetUserCredentials(uid)
if err != nil {
c.String(http.StatusInternalServerError, "Error getting credentials for MinIO user: ", uid)
}

minIOProvider.AccessKey = ak
minIOProvider.SecretKey = sk

conf = configForUser{cfg, minIOProvider}
}

c.JSON(http.StatusOK, conf)
}
}
3 changes: 1 addition & 2 deletions pkg/utils/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func CustomAuth(cfg *types.Config, kubeClientset *kubernetes.Clientset) gin.Hand
}

// Slice to add default user to all users group on MinIO
var oscarUser []string
oscarUser[0] = "console"
var oscarUser = []string{"console"}

minIOAdminClient.CreateAllUsersGroup()
minIOAdminClient.AddUserToGroup(oscarUser, "all_users_group")
Expand Down

0 comments on commit 9df9bad

Please sign in to comment.