Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to organize clusters by group. #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ clusters:
- email
- profile
- openid
group: dev

# A path-prefix from which to serve requests and assets
web_path_prefix: /dex-auth
Expand Down
10 changes: 7 additions & 3 deletions html/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ pre {
overflow-wrap: break-word;
}

.groups-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 1em;
grid-auto-rows: 1fr;
}

.dex-container {
color: #333;
margin: 45px auto;
max-width: 500px;
min-width: 320px;
text-align: center;
}

.dex-kubeconfig-container {
color: #333;
margin: 45px auto;
max-width: 90%;
min-width: 320px;
text-align: left;
}

Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Cluster struct {
K8s_Ca_Pem string
Static_Context_Name bool
Scopes []string
Group string

Verifier *oidc.IDTokenVerifier
Provider *oidc.Provider
Expand All @@ -79,6 +80,7 @@ type Cluster struct {
// Define our configuration
type Config struct {
Clusters []Cluster
Groups map[string][]Cluster
Listen string
Web_Path_Prefix string
TLS_Cert string
Expand Down Expand Up @@ -220,6 +222,18 @@ func start_app(config Config) {
cluster.Scopes = []string{"openid", "profile", "email", "offline_access", "groups"}
}

// Any cluster without a group will be in the 'default' group
if cluster.Group == "" {
cluster.Group = "default"
}

// Sort clusters by group label
if _, ok := config.Groups[cluster.Group]; ok {
config.Groups[cluster.Group] = append(config.Groups[cluster.Group], cluster)
} else {
config.Groups[cluster.Group] = []Cluster{cluster}
}

cluster.Config = config

base_redirect_uri, err := url.Parse(cluster.Redirect_URI)
Expand Down
45 changes: 23 additions & 22 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,31 @@
{{ end }}
</div>

<div class="dex-container">

<div class="theme-panel">
<h2 class="theme-heading">Generate Kubernetes Token</h2>
<div>
<p>
Select which cluster you require a token for:
</p>

{{ range $cluster := .Clusters }}

<div class="theme-form-row">
<p class="theme-form-description">{{$cluster.Description}}</p>
<a href="{{ $.Web_Path_Prefix }}login/{{$cluster.Name}}" target="_self">
<button class="dex-btn theme-btn-provider">
<span class="dex-btn-icon dex-btn-icon--local"></span>
<span class="dex-btn-text">{{$cluster.Short_Description}}</span>
</button>
</a>
</div>
{{ end }}
</div>
<div class="groups-container">
{{ $length := len .Groups }}{{ if eq $length 1 }}<div></div>{{ end }}
{{ range $group, $clusters := .Groups }}
<div class="dex-container">
<div class="theme-panel">
<h2 class="theme-heading">{{ $group }} clusters</h2>
<div>
<p>
Select which cluster you require a token for:
</p>
{{ range $cluster := $clusters }}
<div class="theme-form-row">
<p class="theme-form-description">{{$cluster.Description}}</p>
<a href="{{ $.Web_Path_Prefix }}login/{{$cluster.Name}}" target="_self">
<button class="dex-btn theme-btn-provider">
<span class="dex-btn-icon dex-btn-icon--local"></span>
<span class="dex-btn-text">{{$cluster.Short_Description}}</span>
</button>
</a>
</div>
{{ end }}
</div>
</div>
</div>
{{ end }}
</div>
</body>
</html>