From f25b93d8b55d276005fb6211d91c687ff4f41012 Mon Sep 17 00:00:00 2001 From: Sebastian Nickel Date: Wed, 18 Sep 2024 14:10:14 +0200 Subject: [PATCH] only get token if tab completion was executed This changes the completion mechanism to only gather a valid OIDC token if completion was requested rather then on every invocation of nctl. --- predictor/predictor.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/predictor/predictor.go b/predictor/predictor.go index 151896f..5ce5346 100644 --- a/predictor/predictor.go +++ b/predictor/predictor.go @@ -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))