Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXCDT-297: Remove env var ingestion #554

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/guiguan/caster v0.0.0-20191104051807-3736c4464f38
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lestrrat-go/jwx v1.2.25
github.com/logrusorgru/aurora v2.0.3+incompatible
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd h1:nIzoSW6OhhppWLm4yqBwZsKJlAayUu5FGozhrF3ETSM=
github.com/joeshaw/envdecode v0.0.0-20200121155833-099f1fc765bd/go.mod h1:MEQrHur0g8VplbLOv5vXmDzacSaH9Z7XhcgsSh1xciU=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
Expand Down
25 changes: 11 additions & 14 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"strings"
"time"

"github.com/joeshaw/envdecode"
"golang.org/x/oauth2/clientcredentials"
)

Expand Down Expand Up @@ -74,10 +73,10 @@ var requiredScopes = []string{

// Authenticator is used to facilitate the login process.
type Authenticator struct {
Audience string `env:"AUTH0_AUDIENCE,default=https://*.auth0.com/api/v2/"`
ClientID string `env:"AUTH0_CLIENT_ID,default=2iZo3Uczt5LFHacKdM0zzgUO2eG2uDjT"`
DeviceCodeEndpoint string `env:"AUTH0_DEVICE_CODE_ENDPOINT,default=https://auth0.auth0.com/oauth/device/code"`
OauthTokenEndpoint string `env:"AUTH0_OAUTH_TOKEN_ENDPOINT,default=https://auth0.auth0.com/oauth/token"`
Audience string
ClientID string
DeviceCodeEndpoint string
OauthTokenEndpoint string
}

// SecretStore provides access to stored sensitive data.
Expand Down Expand Up @@ -124,16 +123,14 @@ func (s *State) IntervalDuration() time.Duration {
return time.Duration(s.Interval+waitThresholdInSeconds) * time.Second
}

// New returns a new instance of Authenticator
// after decoding its parameters from env vars.
func New() (*Authenticator, error) {
authenticator := Authenticator{}

if err := envdecode.StrictDecode(&authenticator); err != nil {
return nil, fmt.Errorf("failed to decode env vars for authenticator: %w", err)
// New returns a new instance of Authenticator using Auth0 Public Cloud default values
func New() *Authenticator {
return &Authenticator{
Audience: "https://*.auth0.com/api/v2/",
ClientID: "2iZo3Uczt5LFHacKdM0zzgUO2eG2uDjT",
DeviceCodeEndpoint: "https://auth0.auth0.com/oauth/device/code",
OauthTokenEndpoint: "https://auth0.auth0.com/oauth/token",
}

return &authenticator, nil
}

// Start kicks-off the device authentication flow by requesting
Expand Down
11 changes: 1 addition & 10 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ const rootShort = "Supercharge your development workflow."

// Execute is the primary entrypoint of the CLI app.
func Execute() {
// cfg contains tenant related information, e.g. `travel0-dev`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this comment because it references a now irrelevant AUTH0_API_KEY env var and generally doesn't apply to this codebase anymore.

// `travel0-prod`. some of its information can be sourced via:
// 1. env var (e.g. AUTH0_API_KEY)
// 2. global flag (e.g. --api-key)
// 3. JSON file (e.g. api_key = "..." in ~/.config/auth0/config.json)
cli := &cli{
renderer: display.NewRenderer(),
tracker: analytics.NewTracker(),
Expand Down Expand Up @@ -85,11 +80,7 @@ func buildRootCmd(cli *cli) *cobra.Command {
Long: rootShort + "\n" + getLogin(cli),
Version: buildinfo.GetVersionWithCommit(),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error
cli.authenticator, err = auth.New()
if err != nil {
return err
}
cli.authenticator = auth.New()

ansi.DisableColors = cli.noColor
prepareInteractivity(cmd)
Expand Down