Skip to content

Commit

Permalink
Update Cluster based on permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
fjogeleit committed Oct 13, 2024
1 parent 4973ef4 commit f04ddc2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (a Plugin) FromValues(values secrets.Values) Plugin {
return a
}

// APISetup configuration
// Cluster configuration
type Cluster struct {
Name string `mapstructure:"name"`
Host string `mapstructure:"host"`
Expand Down
3 changes: 3 additions & 0 deletions backend/pkg/config/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func MapConfig(c *Config) *api.Config {
Name: cl.Name,
Slug: slug.Make(cl.Name),
Plugins: plugins,
Permissions: auth.Permissions{
AccessControl: auth.AccessControl(cl.AccessControl),
},
})
}

Expand Down
29 changes: 29 additions & 0 deletions backend/pkg/server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@ func (h *Handler) Healthz(ctx *gin.Context) {
}

func (h *Handler) Config(ctx *gin.Context) {
if profile := auth.ProfileFrom(ctx); profile != nil {
cluster := h.config.Default

clusters := make([]Cluster, 0, len(h.config.Clusters))
for _, cl := range h.config.Clusters {
access := cl.AllowedEmail(profile.Email)
if access {
clusters = append(clusters, cl)
}
if cluster == cl.Slug && !access {
cluster = ""
}
}

if cluster == "" && len(clusters) > 0 {
cluster = clusters[0].Slug
}

ctx.JSON(http.StatusOK, Config{
Clusters: clusters,
Default: cluster,
User: h.config.User,
Sources: h.config.Sources,
Banner: h.config.Banner,
OAuth: h.config.OAuth,
})
return
}

ctx.JSON(http.StatusOK, h.config)
}

Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/server/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ type Source struct {
}

type Cluster struct {
Name string `json:"name"`
Slug string `json:"slug"`
Plugins []string `json:"plugins"`
auth.Permissions `json:"-"`
Name string `json:"name"`
Slug string `json:"slug"`
Plugins []string `json:"plugins"`
}

type PolicyReports struct {
Expand Down
2 changes: 1 addition & 1 deletion frontend/modules/core/components/form/ClusterSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
hide-details
density="compact"
prepend-inner-icon="mdi-kubernetes"
style="max-width: 140px;"
style="min-width: 140px;"
@update:model-value="input"
v-if="clusters.length > 1"
/>
Expand Down

0 comments on commit f04ddc2

Please sign in to comment.