Skip to content

Commit

Permalink
only get token if tab completion was executed
Browse files Browse the repository at this point in the history
This changes the completion mechanism to only gather a valid OIDC token if completion was requested rather then on every invocation of nctl.
  • Loading branch information
thirdeyenick committed Sep 18, 2024
1 parent 1fdf9ab commit f25b93d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions predictor/predictor.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ var argResourceMap = map[string]string{
}

type Resource struct {
client *api.Client
clientCreator func() (*api.Client, error)
client *api.Client
}

func NewResourceName(clientCreator func() (*api.Client, error)) *Resource {
c, err := clientCreator()
if err != nil {
return &Resource{}
return &Resource{
clientCreator: clientCreator,
}

return &Resource{client: c}
}

func (r *Resource) Predict(args complete.Args) []string {
if r.client == nil {
if r.clientCreator == nil {
return []string{}
}
if r.client == nil {
var err error
if r.client, err = r.clientCreator(); err != nil {
return []string{}
}
}

u := &unstructured.UnstructuredList{}
u.SetGroupVersionKind(r.findKind(args.LastCompleted))
Expand Down

0 comments on commit f25b93d

Please sign in to comment.