Skip to content

Commit

Permalink
feat(utils/k8s_oidc_utils): Create k8s_oidc_utils with method CreateO…
Browse files Browse the repository at this point in the history
…idcUser
  • Loading branch information
ondrejsika committed Jun 28, 2023
1 parent b0a9a3b commit 2fd0394
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions utils/k8s_oidc_utils/k8s_oidc_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package k8s_oidc_utils

import (
"fmt"

"github.com/sikalabs/slu/utils/exec_utils"
)

func CreateOidcUser(
name, issuerUrl, clientId, clientSecret string,
dry bool,
) {
args := []string{
"config", "set-credentials", name,
"--exec-api-version=client.authentication.k8s.io/v1beta1",
"--exec-command=kubectl",
"--exec-arg=oidc-login",
"--exec-arg=get-token",
"--exec-arg=--oidc-issuer-url=" + issuerUrl,
"--exec-arg=--oidc-client-id=" + clientId,
}
if clientSecret != "" {
args = append(args, "--exec-arg=--oidc-client-secret="+clientSecret)
}

if dry {
fmt.Print("kubectl")
for _, arg := range args {
fmt.Printf(" %s", arg)
}
fmt.Println("")
} else {
exec_utils.ExecOut("kubectl", args...)
}
}

0 comments on commit 2fd0394

Please sign in to comment.