Skip to content

Commit

Permalink
update config to set default certs so we dont have to in makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
dagbay-rh committed Aug 22, 2023
1 parent 103bb99 commit 11eabfa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
15 changes: 0 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,12 @@ image:
podman build -t entitlements-api-go .
debug-run: generate
ENT_DEBUG=1 \
ENT_CA_PATH=$(PWD)/resources/ca.crt \
ENT_KEY=$(PWD)/test_data/test.key \
ENT_CERT=$(PWD)/test_data/test.cert \
go run main.go
run: generate
ENT_CA_PATH=$(PWD)/resources/ca.crt \
ENT_KEY=$(PWD)/test_data/test.key \
ENT_CERT=$(PWD)/test_data/test.cert \
go run main.go
test: generate
ENT_CA_PATH=$(PWD)/resources/ca.crt \
ENT_KEY=$(PWD)/test_data/test.key \
ENT_CERT=$(PWD)/test_data/test.cert \
go test -v ./...
test-all: generate
ENT_CA_PATH=$(PWD)/resources/ca.crt \
ENT_KEY=$(PWD)/test_data/test.key \
ENT_CERT=$(PWD)/test_data/test.cert \
go test --race --coverprofile=coverage.out --covermode=atomic ./...
bench: generate
ENT_CA_PATH=$(PWD)/resources/ca.crt \
ENT_KEY=$(PWD)/test_data/test.key \
ENT_CERT=$(PWD)/test_data/test.cert \
go test -bench=. ./...
13 changes: 9 additions & 4 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func getRootCAs(localCertFile string) *x509.CertPool {
}

func loadCerts(options *viper.Viper) (tls.Certificate, error) {
if options.GetBool("CERTS_FROM_ENV") == true {
if options.GetBool(Keys.CertsFromEnv) {
return tls.X509KeyPair(
[]byte(options.GetString(Keys.Cert)),
[]byte(options.GetString(Keys.Key)),
Expand Down Expand Up @@ -157,14 +157,19 @@ 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)
}

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, "../resources/ca.crt")
options.SetDefault(Keys.Cert, "../test_data/test.cert") // default values of Cert and Key are for testing purposes only
options.SetDefault(Keys.Key, "../test_data/test.key")
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
8 changes: 5 additions & 3 deletions server/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package server

import (
"fmt"

chilogger "github.com/766b/chi-logger"
"github.com/RedHatInsights/entitlements-api-go/ams"
"github.com/RedHatInsights/entitlements-api-go/api"
Expand Down Expand Up @@ -39,12 +41,12 @@ func DoRoutes() chi.Router {
amsClient, err := ams.NewClient(debug)

if err != nil {
panic(err)
panic(fmt.Sprintf("Error constructing ams client: [%s]", err))
}

bopClient, err := bop.NewClient(debug)
if err != nil {
panic(err)
panic(fmt.Sprintf("Error constructing bop client: [%s]", err))
}

// This is odd, but the generated code will register handlers
Expand All @@ -53,7 +55,7 @@ func DoRoutes() chi.Router {
// a way to hack it in
if !configOptions.GetBool(config.Keys.DisableSeatManager) {
seatManagerApi := controllers.NewSeatManagerApi(amsClient, bopClient)
api.HandlerFromMuxWithBaseURL(seatManagerApi, r.With(identity.EnforceIdentity), "/api/entitlements/v1")
api.HandlerFromMuxWithBaseURL(seatManagerApi, r.With(identity.EnforceIdentity), "/api/entitlements/v1")
}

r.Route("/api/entitlements/v1", func(r chi.Router) {
Expand Down

0 comments on commit 11eabfa

Please sign in to comment.