Skip to content

Commit

Permalink
fix config to get root of project
Browse files Browse the repository at this point in the history
  • Loading branch information
dagbay-rh committed Aug 22, 2023
1 parent e371042 commit 78d7dd4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/x509"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/spf13/viper"
Expand Down Expand Up @@ -157,19 +159,22 @@ func initialize() {
hostname = "entitlements"
}

wd, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current directory, some default config settings might not be set correctly. Err: [%w]", err)
wd := "."
_, filename, _, ok := runtime.Caller(0)
if !ok {
fmt.Printf("Error getting runtime caller, some default config settings might not be set correctly. Working directory set to: [%s]\n", wd)
} else {
wd = filepath.Dir(filename)
}

options.SetDefault(Keys.CertsFromEnv, false)
options.SetDefault(Keys.Port, "3000")
options.SetDefault(Keys.LogLevel, "info")
options.SetDefault(Keys.SubsHost, "https://subscription.api.redhat.com")
options.SetDefault(Keys.ComplianceHost, "https://export-compliance.api.redhat.com")
options.SetDefault(Keys.CaPath, fmt.Sprintf("%s/resources/ca.crt", wd))
options.SetDefault(Keys.Cert, fmt.Sprintf("%s/test_data/test.cert", wd)) // default values of Cert and Key are for testing purposes only
options.SetDefault(Keys.Key, fmt.Sprintf("%s/test_data/test.key", wd))
options.SetDefault(Keys.CaPath, fmt.Sprintf("%s/../resources/ca.crt", wd))
options.SetDefault(Keys.Cert, fmt.Sprintf("%s/../test_data/test.cert", wd)) // default values of Cert and Key are for testing purposes only
options.SetDefault(Keys.Key, fmt.Sprintf("%s/../test_data/test.key", wd))
options.SetDefault(Keys.OpenAPISpecPath, "./apispec/api.spec.json")
options.SetDefault(Keys.BundleInfoYaml, "./bundles/bundles.yml")
options.SetDefault(Keys.CwLogGroup, "platform-dev")
Expand Down

0 comments on commit 78d7dd4

Please sign in to comment.