refactor: name changes and code clean up

This commit is contained in:
David Allen 2024-11-21 14:13:31 -07:00
parent b31056f297
commit 32065dc163
Signed by: towk
GPG key ID: 793B2924A49B3A3F
5 changed files with 134 additions and 135 deletions

View file

@ -25,11 +25,11 @@ var fetchCmd = &cobra.Command{
}
// check to see if an access token is available from env
if config.AccessToken == "" {
if conf.AccessToken == "" {
// check if OCHAMI_ACCESS_TOKEN env var is set if no access token is provided and use that instead
accessToken := os.Getenv("ACCESS_TOKEN")
if accessToken != "" {
config.AccessToken = accessToken
conf.AccessToken = accessToken
} else {
// TODO: try and fetch token first if it is needed
if verbose {
@ -46,7 +46,7 @@ var fetchCmd = &cobra.Command{
for _, target := range targets {
// make a request for each target
url := fmt.Sprintf("%s:%d/generate?target=%s", remoteHost, remotePort, target)
url := fmt.Sprintf("%s/generate?target=%s", remoteHost, target)
res, body, err := util.MakeRequest(url, http.MethodGet, nil, headers)
if err != nil {
log.Error().Err(err).Msg("failed to make request")
@ -63,8 +63,7 @@ var fetchCmd = &cobra.Command{
}
func init() {
fetchCmd.Flags().StringVar(&remoteHost, "host", "", "set the remote configurator host")
fetchCmd.Flags().IntVar(&remotePort, "port", 3334, "set the remote configurator port")
fetchCmd.Flags().StringVar(&remoteHost, "host", "", "set the remote configurator host and port")
fetchCmd.Flags().StringSliceVar(&targets, "target", nil, "set the target configs to make")
fetchCmd.Flags().StringVarP(&outputPath, "output", "o", "", "set the output path for config targets")
fetchCmd.Flags().StringVar(&accessToken, "access-token", "o", "set the output path for config targets")