Skip to content

Commit

Permalink
Merge pull request #105 from davidpst/feature/login-token
Browse files Browse the repository at this point in the history
Allow login with token
  • Loading branch information
javaducky authored Dec 14, 2023
2 parents f60b994 + 371a30d commit b78303c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Kubernetes struct {
// KubeConfig represents the initialization settings for the kubernetes api client.
type KubeConfig struct {
ConfigPath string
Server string
Token string
}

// Ensure the interfaces are implemented correctly.
Expand Down Expand Up @@ -145,6 +147,18 @@ func (mi *ModuleInstance) newClient(c goja.ConstructorCall) *goja.Object {
}

func getClientConfig(options KubeConfig) (*rest.Config, error) {
// If server and token are provided, use them
if options.Server != "" && options.Token != "" {
return &rest.Config{
Host: options.Server,
BearerToken: options.Token,
TLSClientConfig: rest.TLSClientConfig{
Insecure: true,
},
}, nil
}

// If server and token are not provided, use kubeconfig
kubeconfig := options.ConfigPath
if kubeconfig == "" {
// are we in-cluster?
Expand Down

0 comments on commit b78303c

Please sign in to comment.