Skip to content

Commit ac0d883

Browse files
committed
Adds pulling FA configuration from .env
1 parent 61087c7 commit ac0d883

4 files changed

Lines changed: 22 additions & 9 deletions

File tree

cmd/login.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ import (
1515
)
1616

1717
const (
18-
host string = "http://localhost:9011"
19-
apiKey string = "vB_ap-t-zsCbOYv9HhETbbRm1Ue8C3FFP28qJQWfNTo"
20-
21-
// ClientID is the OAuth client_id of our FA Application
22-
ClientID string = "7dde5f47-5000-4580-8003-b3b8d1cbe2e9"
23-
24-
// TenantID is the ID of our FA instance's default Tenant
25-
TenantID string = "8caf6467-fb94-6b02-e19c-46536e8e62ad"
18+
host string = "http://localhost:9011"
2619
)
2720

2821
var (
@@ -38,7 +31,7 @@ var LoginCmd = &cobra.Command{
3831
Use: "login [no options!]",
3932
Short: "Login to the FA server using the OAuth Device Flow.",
4033
Run: func(cmd *cobra.Command, args []string) {
41-
faClient = fusionauth.NewClient(httpClient, baseURL, apiKey)
34+
faClient = fusionauth.NewClient(httpClient, baseURL, APIKey)
4235
openIDConfig, err := faClient.RetrieveOpenIdConfiguration()
4336
if err != nil {
4437
log.Fatal(err)

cmd/root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@ import (
2525
"fmt"
2626
"os"
2727

28+
"github.com/joho/godotenv"
2829
"github.com/spf13/cobra"
2930
)
3031

32+
var (
33+
// APIKey is the FA API Key created in the FA UI under "Settings > API Keys"
34+
APIKey string
35+
36+
// ClientID is the OAuth client_id of our FA Application
37+
ClientID string
38+
39+
// TenantID is the ID of our FA instance's default Tenant
40+
TenantID string
41+
)
42+
3143
// rootCmd represents the base command when called without any subcommands
3244
var rootCmd = &cobra.Command{
3345
Use: "getgif",
@@ -49,6 +61,11 @@ func Execute() {
4961
}
5062

5163
func init() {
64+
godotenv.Load(".env")
65+
ClientID = os.Getenv("FA_CLIENT_ID")
66+
TenantID = os.Getenv("FA_TENANT_ID")
67+
APIKey = os.Getenv("FA_API_KEY")
68+
5269
rootCmd.AddCommand(LoginCmd)
5370
rootCmd.AddCommand(LogoutCmd)
5471
rootCmd.AddCommand(FetchCmd)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.14
55
require (
66
github.com/FusionAuth/go-client v0.0.0-20200521161034-4bc9352aa327
77
github.com/fatih/color v1.9.0
8+
github.com/joho/godotenv v1.3.0
89
github.com/mitchellh/go-homedir v1.1.0
910
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
1011
github.com/spf13/cobra v1.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
103103
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
104104
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
105105
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
106+
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
107+
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
106108
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
107109
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
108110
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=

0 commit comments

Comments
 (0)