overmindtech / discovery

Go libraries for writing SDP sources
Other
1 stars 0 forks source link

Lift NatsOptions handling into discovery.EngineConfig 🍫 [minting] #376

Open DavidS-ovm opened 1 day ago

DavidS-ovm commented 1 day ago

With MANAGED and LOCAL sources' configs drifting apart further, handling of ApiUrl, NATS_SERVERS, and other options needs to be fully centralised here, to be able to make a single decision and keep MANAGED considerations out of custom sources.

Take the entirety of https://github.com/overmindtech/stdlib-source/blob/a54fd03513e797a031324415a794a60c150817f1/cmd/root.go#L50-L126 and lift it into discovery.EngineConfigFromViper. This includes the following distinct bits:

Then all sources need to be upgraded to excise the existing code and replace it with a double whammy of discovery.EngineConfigFromViper(...).NewEngine(....).

tphoney commented 1 day ago

from comparing the sources https://github.com/overmindtech/aws-source/blob/main/cmd/root.go https://github.com/overmindtech/harness-source/blob/main/cmd/root.go // copy of aws-source https://github.com/overmindtech/stdlib-source/blob/main/cmd/root.go https://github.com/overmindtech/k8s-source/blob/main/cmd/root.go is the outlier, doing everything manually

using https://github.com/overmindtech/discovery/blob/main/cmd.go https://github.com/overmindtech/discovery/blob/main/engine.go

first step βœ…

we can pull the following cli options/env vars centrally into cmd.go in AddEngineFlags "nats-servers": natsServers, "nats-jwt": natsJWT, "nats-nkey-seed": natsNKeySeedLog, "nats-connection-name": natsConnectionName, and healthCheckPort := viper.GetInt("health-check-port")

second step

centralise var tokenClient auth.TokenClient

into discovery supplimenting EngineConfigFromViper

third step βœ…

modify each of the sources, if we overide the sane defaults. eg k8s vs aws: nats ReconnectWait

fourth step βœ…

update NewEngine in discovery to print out the variables used