Skip to content

Commit

Permalink
Enable expand env for oidc discovery provider
Browse files Browse the repository at this point in the history
Fixes: spiffe#5688

Signed-off-by: Kevin Fox <Kevin.Fox@pnnl.gov>
  • Loading branch information
kfox1111 committed Dec 7, 2024
1 parent 7b3181d commit 47fbedd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions support/oidc-discovery-provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/hashicorp/hcl"
"github.com/spiffe/spire/pkg/common/config"
"github.com/zeebo/errs"
)

Expand Down Expand Up @@ -185,12 +186,16 @@ type experimentalWorkloadAPIConfig struct {
NamedPipeName string `hcl:"named_pipe_name" json:"named_pipe_name"`
}

func LoadConfig(path string) (*Config, error) {
func LoadConfig(path string, expandEnv bool) (*Config, error) {
hclBytes, err := os.ReadFile(path)
if err != nil {
return nil, errs.New("unable to load configuration: %v", err)
}
return ParseConfig(string(hclBytes))
hclString := string(hclBytes)
if expandEnv {
hclString = config.ExpandEnv(hclString)
}
return ParseConfig(hclString)
}

func ParseConfig(hclConfig string) (_ *Config, err error) {
Expand Down
7 changes: 4 additions & 3 deletions support/oidc-discovery-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
var (
versionFlag = flag.Bool("version", false, "print version")
configFlag = flag.String("config", "oidc-discovery-provider.conf", "configuration file")
expandEnv = flag.Bool("expandEnv", false, "expand environment variables in config file")
)

func main() {
Expand All @@ -35,14 +36,14 @@ func main() {
os.Exit(0)
}

if err := run(*configFlag); err != nil {
if err := run(*configFlag, *expandEnv); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)
}
}

func run(configPath string) error {
config, err := LoadConfig(configPath)
func run(configPath string, expandEnv bool) error {
config, err := LoadConfig(configPath, expandEnv)
if err != nil {
return err
}
Expand Down

0 comments on commit 47fbedd

Please sign in to comment.