From b05e30542810e85083d6804c05dc11386a4c59b4 Mon Sep 17 00:00:00 2001 From: Marcin Fabrykowski Date: Thu, 21 Oct 2021 08:00:14 +0200 Subject: [PATCH 1/3] add support for customizable username field Signed-off-by: Marcin Fabrykowski --- docs/config.md | 1 + main.go | 1 + templates.go | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index c57ec37..fd12401 100644 --- a/docs/config.md +++ b/docs/config.md @@ -21,6 +21,7 @@ An example configuration is available [here](../examples/config.yaml) | k8s_ca_pem_base64_encoded | no | cluster | The Base64 encoded CA for your k8s server (used in generating instructions) | | k8s_ca_pem_file | no | cluster | The CA file for your k8s server (used in generating instructions) | | scopes | no | cluster | A list OpenID scopes to request | +| username_field | no | cluster | A field that points to username | | tls_cert | no | root | Path to TLS cert if SSL enabled | | tls_key | no | root | Path to TLS key if SSL enabled | | idp_ca_uri | no | root | A url pointing to the CA for generating 'idp-certificate-authority' in the kubeconfig | diff --git a/main.go b/main.go index d77945e..f1b0bd2 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,7 @@ type Cluster struct { Client *http.Client Redirect_URI string Config Config + UserName_Field String } // Define our configuration diff --git a/templates.go b/templates.go index f639119..cd0003e 100644 --- a/templates.go +++ b/templates.go @@ -63,8 +63,13 @@ func (cluster *Cluster) renderToken(w http.ResponseWriter, } unix_username := "user" - if data["email"] != nil { - email := data["email"].(string) + username_field := "email" + if cluster.Username_Field != "" { + username_field = cluster.Username_Field + } + + if data[username_field] != nil { + email := data[username_field].(string) unix_username = strings.Split(email, "@")[0] } From cbff75b838d7eb90a1e66d02341b9090fd6009b2 Mon Sep 17 00:00:00 2001 From: Marcin Fabrykowski Date: Thu, 21 Oct 2021 08:30:55 +0200 Subject: [PATCH 2/3] typo Signed-off-by: Marcin Fabrykowski --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index f1b0bd2..525e823 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ type Cluster struct { Client *http.Client Redirect_URI string Config Config - UserName_Field String + Username_Field String } // Define our configuration From fa82a3080e5d0d044ba9b7f7823c6950be49bf68 Mon Sep 17 00:00:00 2001 From: Marcin Fabrykowski Date: Thu, 21 Oct 2021 10:10:39 +0200 Subject: [PATCH 3/3] fix typo String to string Signed-off-by: Marcin Fabrykowski --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 525e823..236a9cc 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ type Cluster struct { Client *http.Client Redirect_URI string Config Config - Username_Field String + Username_Field string } // Define our configuration