Skip to content

Commit

Permalink
added feature flag to expose seat manager apis, and features env (Red…
Browse files Browse the repository at this point in the history
  • Loading branch information
dagbay-rh authored May 8, 2023
1 parent 0cd6f0d commit 6904012
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 64 deletions.
125 changes: 64 additions & 61 deletions config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,71 +24,73 @@ type EntitlementsConfig struct {

// EntitlementsConfigKeysType is the definition of the struct hat houses all the env variables key names
type EntitlementsConfigKeysType struct {
Key string
Cert string
Port string
LogLevel string
CertsFromEnv string
SubsHost string
ComplianceHost string
CaPath string
OpenAPISpecPath string
BundleInfoYaml string
CwLogGroup string
CwLogStream string
CwRegion string
CwKey string
CwSecret string
Features string
FeaturesPath string
SubAPIBasePath string
CompAPIBasePath string
RunBundleSync string
EntitleAll string
AMSHost string
ClientID string
ClientSecret string
TokenURL string
Debug string
BOPClientID string
BOPToken string
BOPURL string
BOPEnv string
BOPMockOrgId string
Key string
Cert string
Port string
LogLevel string
CertsFromEnv string
SubsHost string
ComplianceHost string
CaPath string
OpenAPISpecPath string
BundleInfoYaml string
CwLogGroup string
CwLogStream string
CwRegion string
CwKey string
CwSecret string
Features string
FeaturesPath string
SubAPIBasePath string
CompAPIBasePath string
RunBundleSync string
EntitleAll string
AMSHost string
ClientID string
ClientSecret string
TokenURL string
Debug string
BOPClientID string
BOPToken string
BOPURL string
BOPEnv string
BOPMockOrgId string
DisableSeatManager string
}

// Keys is a struct that houses all the env variables key names
var Keys = EntitlementsConfigKeysType{
Key: "KEY",
Cert: "CERT",
Port: "PORT",
LogLevel: "LOG_LEVEL",
CertsFromEnv: "CERTS_FROM_ENV",
SubsHost: "SUBS_HOST",
ComplianceHost: "COMPLIANCE_HOST",
CaPath: "CA_PATH",
OpenAPISpecPath: "OPENAPI_SPEC_PATH",
BundleInfoYaml: "BUNDLE_INFO_YAML",
CwLogGroup: "CW_LOG_GROUP",
CwLogStream: "CW_LOG_STEAM",
CwRegion: "CW_REGION",
CwKey: "CW_KEY",
CwSecret: "CW_SECRET",
Features: "FEATURES",
SubAPIBasePath: "SUB_API_BASE_PATH",
CompAPIBasePath: "COMP_API_BASE_PATH",
RunBundleSync: "RUN_BUNDLE_SYNC",
EntitleAll: "ENTITLE_ALL",
AMSHost: "AMS_HOST",
ClientID: "OIDC_CLIENT_ID",
ClientSecret: "OIDC_CLIENT_SECRET",
TokenURL: "OAUTH_TOKEN_URL",
BOPClientID: "BOP_CLIENT_ID",
BOPToken: "BOP_TOKEN",
BOPURL: "BOP_URL",
BOPMockOrgId: "BOP_MOCK_ORG_ID",
BOPEnv: "BOP_ENV",
Debug: "DEBUG",
Key: "KEY",
Cert: "CERT",
Port: "PORT",
LogLevel: "LOG_LEVEL",
CertsFromEnv: "CERTS_FROM_ENV",
SubsHost: "SUBS_HOST",
ComplianceHost: "COMPLIANCE_HOST",
CaPath: "CA_PATH",
OpenAPISpecPath: "OPENAPI_SPEC_PATH",
BundleInfoYaml: "BUNDLE_INFO_YAML",
CwLogGroup: "CW_LOG_GROUP",
CwLogStream: "CW_LOG_STEAM",
CwRegion: "CW_REGION",
CwKey: "CW_KEY",
CwSecret: "CW_SECRET",
Features: "FEATURES",
SubAPIBasePath: "SUB_API_BASE_PATH",
CompAPIBasePath: "COMP_API_BASE_PATH",
RunBundleSync: "RUN_BUNDLE_SYNC",
EntitleAll: "ENTITLE_ALL",
AMSHost: "AMS_HOST",
ClientID: "OIDC_CLIENT_ID",
ClientSecret: "OIDC_CLIENT_SECRET",
TokenURL: "OAUTH_TOKEN_URL",
BOPClientID: "BOP_CLIENT_ID",
BOPToken: "BOP_TOKEN",
BOPURL: "BOP_URL",
BOPMockOrgId: "BOP_MOCK_ORG_ID",
BOPEnv: "BOP_ENV",
Debug: "DEBUG",
DisableSeatManager: "DISABLE_SEAT_MANAGER",
}

func getBaseFeaturesPath(options *viper.Viper) string {
Expand Down Expand Up @@ -173,6 +175,7 @@ func initialize() {
options.SetDefault(Keys.BOPMockOrgId, "4384938490324")
options.SetDefault(Keys.BOPEnv, "stage")
options.SetDefault(Keys.Debug, false)
options.SetDefault(Keys.DisableSeatManager, false)

options.SetEnvPrefix("ENT")
options.AutomaticEnv()
Expand Down
10 changes: 10 additions & 0 deletions deployment/clowdapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ objects:
value: /apispec/api.spec.json
- name: ENT_BUNDLE_INFO_YAML
value: /bundles/bundles.yml
- name: ENT_FEATURES
value: ${FEATURES}
- name: ENT_DISABLE_SEAT_MANAGER
value: ${DISABLE_SEAT_MANAGER}
- name: GLITCHTIP_DSN
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -209,6 +213,12 @@ parameters:
name: GLITCHTIP_SECRET
required: false
value: 'entitlements-secret'
- description: List of feature bundles to onboard during bundle sync
name: FEATURES
required: false
- description: Flag to disable seat manager by not exposing any of the apis related to the feature
name: DISABLE_SEAT_MANAGER
required: false
- description: ClowdEnv Name
name: ENV_NAME
required: true
10 changes: 10 additions & 0 deletions deployment/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ objects:
value: ${BOP_URL}
- name: ENT_BOP_ENV
value: ${BOP_ENV}
- name: ENT_FEATURES
value: ${FEATURES}
- name: ENT_DISABLE_SEAT_MANAGER
value: ${DISABLE_SEAT_MANAGER}
- name: ENT_CW_LOG_GROUP
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -242,3 +246,9 @@ parameters:
name: GLITCHTIP_SECRET
required: false
value: 'entitlements-secret'
- description: List of feature bundles to onboard during bundle sync
name: FEATURES
required: false
- description: Flag to disable seat manager by not exposing any of the apis related to the feature
name: DISABLE_SEAT_MANAGER
required: false
9 changes: 6 additions & 3 deletions server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func DoRoutes() chi.Router {
r.Use(chilogger.NewLogrusMiddleware("router", log.Log))
r.Use(sentryMiddleware.Handle)

debug := config.GetConfig().Options.GetBool(config.Keys.Debug)
configOptions := config.GetConfig().Options
debug := configOptions.GetBool(config.Keys.Debug)
amsClient, err := ams.NewClient(debug)

if err != nil {
Expand All @@ -50,8 +51,10 @@ func DoRoutes() chi.Router {
// and return a http.Handler. This is normally used with .Mount,
// but since only part of the server is using code gen this is
// a way to hack it in
seatManagerApi := controllers.NewSeatManagerApi(amsClient, bopClient)
api.HandlerFromMuxWithBaseURL(seatManagerApi, r.With(identity.EnforceIdentity), "/api/entitlements/v1")
if !configOptions.GetBool(config.Keys.DisableSeatManager) {
seatManagerApi := controllers.NewSeatManagerApi(amsClient, bopClient)
api.HandlerFromMuxWithBaseURL(seatManagerApi, r.With(identity.EnforceIdentity), "/api/entitlements/v1")
}

r.Route("/api/entitlements/v1", func(r chi.Router) {
r.With(identity.EnforceIdentity).Route("/", controllers.LubDub)
Expand Down

0 comments on commit 6904012

Please sign in to comment.