Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
fix: centralize const used in multiple packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Dec 10, 2019
1 parent ea15e91 commit de08a79
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/mainawycliffe/kamanda/configs"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -65,8 +66,8 @@ func initConfig() {
}
viper.SetConfigFile(configPath)
}
viper.Set("GOOGLE_OAUTH_CLIENT_ID", GOOGLE_OAUTH_CLIENT_ID)
viper.Set("GOOGLE_OAUTH_CLIENT_SECRET", GOOGLE_OAUTH_CLIENT_SECRET)
viper.Set(configs.GoogleOAuthClientIDConfigKey, GOOGLE_OAUTH_CLIENT_ID)
viper.Set(configs.GoogleOAuthClientSecretConfigKey, GOOGLE_OAUTH_CLIENT_SECRET)
viper.AutomaticEnv()
// @todo: improve error handling here, i.e fail if error is due to missing
// config file
Expand Down
3 changes: 3 additions & 0 deletions configs/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package configs

// these are viper configs keynames
const (
FirebaseLoggedInUserEmailViperConfigKey = "FirebaseUserAccountEmail"
FirebaseRefreshTokenViperConfigKey = "FirebaseRefreshToken"
GoogleOAuthClientIDConfigKey = "GOOGLE_OAUTH_CLIENT_ID"
GoogleOAuthClientSecretConfigKey = "GOOGLE_OAUTH_CLIENT_SECRET"
)
4 changes: 2 additions & 2 deletions firebase/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (r RefreshToken) validate() error {
// constructToken create a json refresh token byte for use by a firebase client
func constructToken() ([]byte, error) {
refreshToken := RefreshToken{
ClientID: viper.GetString("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: viper.GetString("GOOGLE_OAUTH_CLIENT_SECRET"),
ClientID: viper.GetString(configs.GoogleOAuthClientIDConfigKey),
ClientSecret: viper.GetString(configs.GoogleOAuthClientSecretConfigKey),
RefreshToken: viper.GetString(configs.FirebaseRefreshTokenViperConfigKey),
Type: "authorized_user",
}
Expand Down
4 changes: 2 additions & 2 deletions oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func getGoogleOAuthConfig(port string) *oauth2.Config {
}
return &oauth2.Config{
RedirectURL: redirectURL,
ClientID: viper.GetString("GOOGLE_OAUTH_CLIENT_ID"),
ClientSecret: viper.GetString("GOOGLE_OAUTH_CLIENT_SECRET"),
ClientID: viper.GetString(configs.GoogleOAuthClientIDConfigKey),
ClientSecret: viper.GetString(configs.GoogleOAuthClientSecretConfigKey),
Scopes: googleOAuthScopes(),
Endpoint: google.Endpoint,
}
Expand Down

0 comments on commit de08a79

Please sign in to comment.