Skip to content

Commit

Permalink
Merge pull request #627 from ericchiang/dev-expand-envs-in-config
Browse files Browse the repository at this point in the history
*: expand environment variables in config
  • Loading branch information
ericchiang authored Oct 25, 2016
2 parents 101a2bc + a11db55 commit ff98164
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmd/dex/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net"
"net/http"
"os"

"github.com/spf13/cobra"
"golang.org/x/net/context"
Expand Down Expand Up @@ -44,6 +45,7 @@ func serve(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("read config file %s: %v", configFile, err)
}
configData = []byte(os.ExpandEnv(string(configData)))

var c Config
if err := yaml.Unmarshal(configData, &c); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions connector/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"

"golang.org/x/net/context"
Expand All @@ -32,8 +31,8 @@ func (c *Config) Open() (connector.Connector, error) {
redirectURI: c.RedirectURI,
org: c.Org,
oauth2Config: &oauth2.Config{
ClientID: os.ExpandEnv(c.ClientID),
ClientSecret: os.ExpandEnv(c.ClientSecret),
ClientID: c.ClientID,
ClientSecret: c.ClientSecret,
Endpoint: github.Endpoint,
Scopes: []string{
"user:email", // View user's email
Expand Down
5 changes: 2 additions & 3 deletions connector/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"net/http"
"os"

"github.com/ericchiang/oidc"
"golang.org/x/net/context"
Expand Down Expand Up @@ -42,12 +41,12 @@ func (c *Config) Open() (conn connector.Connector, err error) {
scopes = append(scopes, "profile", "email")
}

clientID := os.ExpandEnv(c.ClientID)
clientID := c.ClientID
return &oidcConnector{
redirectURI: c.RedirectURI,
oauth2Config: &oauth2.Config{
ClientID: clientID,
ClientSecret: os.ExpandEnv(c.ClientSecret),
ClientSecret: c.ClientSecret,
Endpoint: provider.Endpoint(),
Scopes: scopes,
RedirectURL: c.RedirectURI,
Expand Down
9 changes: 9 additions & 0 deletions examples/config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ connectors:
- type: mockCallback
id: mock
name: Example
# - type: oidc
# id: google
# name: Google
# config:
# issuer: https://accounts.google.com
# # Config values starting with a "$" will read from the environment.
# clientID: $GOOGLE_CLIENT_ID
# clientSecret: $GOOGLE_CLIENT_SECRET
# redirectURI: http://127.0.0.1:5556/dex/callback/google

# Let dex keep a list of passwords which can be used to login the user
enablePasswordDB: true
Expand Down

0 comments on commit ff98164

Please sign in to comment.