Skip to content

Commit

Permalink
Merge pull request #147 from ninech/predictor-default-cluster
Browse files Browse the repository at this point in the history
fix: use default API cluster in autocomplete predictor
  • Loading branch information
ctrox authored Aug 28, 2024
2 parents 035e6e3 + 587c14b commit 3e0699f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

type flags struct {
Project string `predictor:"resource_name" help:"Limit commands to a specific project." short:"p"`
APICluster string `help:"Context name of the API cluster." default:"nineapis.ch" env:"NCTL_API_CLUSTER"`
APICluster string `help:"Context name of the API cluster." default:"${api_cluster}" env:"NCTL_API_CLUSTER"`
LogAPIAddress string `help:"Address of the deplo.io logging API server." default:"https://logs.deplo.io" env:"NCTL_LOG_ADDR"`
LogAPIInsecure bool `help:"Don't verify TLS connection to the logging API server." hidden:"" default:"false" env:"NCTL_LOG_INSECURE"`
Version kong.VersionFlag `name:"version" help:"Print version information and quit."`
Expand All @@ -49,7 +49,10 @@ type rootCommand struct {
Exec exec.Cmd `cmd:"" help:"Execute a command."`
}

var version = "dev"
const (
version = "dev"
defaultAPICluster = "nineapis.ch"
)

func main() {
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -72,17 +75,14 @@ func main() {
)

resourceNamePredictor := predictor.NewResourceName(func() (*api.Client, error) {
// for the resourcePredictor to use the correct APICluster, we need to
// call parse already. Note that this won't parse the flag for
// completion but it will work for the default and env.
_, err = parser.Parse(os.Args[1:])
if err != nil {
return nil, err
}
// the client for the predictor requires a static token in the client config
// since dynamic exec config seems to break with some shells during completion.
// The exact reason for that is unknown.
c, err := api.New(ctx, nctl.APICluster, nctl.Project, api.StaticToken(ctx))
apiCluster := defaultAPICluster
if v, ok := os.LookupEnv("NCTL_API_CLUSTER"); ok {
apiCluster = v
}
c, err := api.New(ctx, apiCluster, "", api.StaticToken(ctx))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -171,6 +171,7 @@ func setupSignalHandler(ctx context.Context, cancel context.CancelFunc) {
func kongVariables() (kong.Vars, error) {
result := make(kong.Vars)
result["version"] = version
result["api_cluster"] = defaultAPICluster
appCreateKongVars, err := create.ApplicationKongVars()
if err != nil {
return nil, fmt.Errorf("error on application create kong vars: %w", err)
Expand Down

0 comments on commit 3e0699f

Please sign in to comment.