Skip to content

Commit

Permalink
♻️ Make config less confusing (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
stiidk committed Aug 21, 2024
1 parent cc0f2bf commit cc9e9c5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
15 changes: 12 additions & 3 deletions api/config/v2alpha2/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,23 @@ type StyraConfig struct {

// OPAConfig contains default configuration for the opa config generated by the styra-controller
type OPAConfig struct {
// Config for decision logs
DecisionLogs DecisionLog `json:"decision_logs"`
}

// DecisionLog section of the default OPA config
// DecisionLog contains configuration for the decision logs
type DecisionLog struct {
RequestContext RequestContext `json:"request_context"`
}

// RequestContext contains configuration for the RequestContext in the decision logs
type RequestContext struct {
HTTP HTTP `json:"http"`
}

// HTTP contains configuration for the HTTP config in the RequestContext
type HTTP struct {
// http headers that will be added to the decision logs
RequestContextHTTPHeaders []string `json:"request_context.http.headers"`
Headers []string `json:"headers"`
}

// SentryConfig contains configuration for how errors should be reported to
Expand Down
42 changes: 37 additions & 5 deletions api/config/v2alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions config/default/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ systemUserRoles:

#opa:
# decision_logs:
# request_context.http.headers:
# - "Accept"
# request_context:
# http:
# headers:
# - "Accept"
6 changes: 4 additions & 2 deletions config/samples/config_v2alpha2_projectconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,7 @@ readOnly: true
# request_context.http.headers: list of strings that will be added to the decision_logs
#opa:
# decision_logs:
# request_context.http.headers:
# - "Accept"
# request_context:
# http:
# headers:
# - "Accept"
8 changes: 4 additions & 4 deletions internal/k8sconv/k8sconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ func OpaConfToK8sOPAConfigMap(
},
}

if opaDefaultConfig.DecisionLogs.RequestContextHTTPHeaders != nil {
if opaDefaultConfig.DecisionLogs.RequestContext.HTTP.Headers != nil {
opaConfigMap.DecisionLogs = DecisionLogs{
RequestContext: RequestContext{
HTTP: HTTP{
Headers: opaDefaultConfig.DecisionLogs.RequestContextHTTPHeaders,
Headers: opaDefaultConfig.DecisionLogs.RequestContext.HTTP.Headers,
},
},
}
Expand Down Expand Up @@ -259,11 +259,11 @@ func OpaConfToK8sOPAConfigMapNoSLP(
},
}

if opaDefaultConfig.DecisionLogs.RequestContextHTTPHeaders != nil {
if opaDefaultConfig.DecisionLogs.RequestContext.HTTP.Headers != nil {
opaConfigMap.DecisionLogs = DecisionLogs{
RequestContext: RequestContext{
HTTP: HTTP{
Headers: opaDefaultConfig.DecisionLogs.RequestContextHTTPHeaders,
Headers: opaDefaultConfig.DecisionLogs.RequestContext.HTTP.Headers,
},
},
}
Expand Down
12 changes: 10 additions & 2 deletions internal/k8sconv/k8sconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ var _ = ginkgo.Describe("OpaConfToK8sOPAConfigMap", func() {
ginkgo.Entry("success", test{
opaDefaultConfig: configv2alpha2.OPAConfig{
DecisionLogs: configv2alpha2.DecisionLog{
RequestContextHTTPHeaders: strings.Split("header1,header2", ","),
RequestContext: configv2alpha2.RequestContext{
HTTP: configv2alpha2.HTTP{
Headers: strings.Split("header1,header2", ","),
},
},
},
},
opaconf: styra.OPAConfig{
Expand Down Expand Up @@ -136,7 +140,11 @@ var _ = ginkgo.Describe("OpaConfToK8sOPAConfigMapNoSLP", func() {
ginkgo.Entry("success", test{
opaDefaultConfig: configv2alpha2.OPAConfig{
DecisionLogs: configv2alpha2.DecisionLog{
RequestContextHTTPHeaders: strings.Split("header1,header2", ","),
RequestContext: configv2alpha2.RequestContext{
HTTP: configv2alpha2.HTTP{
Headers: strings.Split("header1,header2", ","),
},
},
},
},
opaconf: styra.OPAConfig{
Expand Down

0 comments on commit cc9e9c5

Please sign in to comment.