Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/config/v2alpha2/projectconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,17 @@ type GitCredential struct {
RepoPrefix string `json:"repoPrefix"`
}

// ExporterConfig contains configuration for decisions and user activity export
// ExporterConfigType defines the type of exporter config
type ExporterConfigType string

const (
// ExporterConfigTypeDecisions is the type for decisions exporter config
ExporterConfigTypeDecisions ExporterConfigType = "DecisionsExporter"
// ExporterConfigTypeActivity is the type for activity exporter config
ExporterConfigTypeActivity ExporterConfigType = "ActivityExporter"
)

// ExporterConfig contains configuration for exports
type ExporterConfig struct {
Enabled bool `json:"enabled,omitempty"`
Interval string `json:"interval,omitempty"`
Expand Down
16 changes: 9 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ func main() {
styraHostURL := strings.TrimSuffix(ctrlConfig.Styra.Address, "/")
styraClient := styra.New(styraHostURL, styraToken)

if err := configureExporter(styraClient, ctrlConfig.DecisionsExporter, "DecisionsExporter"); err != nil {
log.Error(err, "unable to configure DecisionsExporter")
if err := configureExporter(
styraClient, ctrlConfig.DecisionsExporter, configv2alpha2.ExporterConfigTypeDecisions); err != nil {
log.Error(err, fmt.Sprintf("unable to configure %s", configv2alpha2.ExporterConfigTypeDecisions))
}

if err := configureExporter(styraClient, ctrlConfig.ActivityExporter, "ActivityExporter"); err != nil {
log.Error(err, "unable to configure ActivityExporter")
if err := configureExporter(
styraClient, ctrlConfig.ActivityExporter, configv2alpha2.ExporterConfigTypeActivity); err != nil {
log.Error(err, fmt.Sprintf("unable to configure %s", configv2alpha2.ExporterConfigTypeActivity))
}

// System Controller
Expand Down Expand Up @@ -284,7 +286,7 @@ func exit(err error) {
func configureExporter(
styraClient styra.ClientInterface,
exporterConfig *configv2alpha2.ExporterConfig,
exporterType string) error {
exporterType configv2alpha2.ExporterConfigType) error {
if exporterConfig == nil {
ctrl.Log.Info(fmt.Sprintf("no exporter configuration found for %s", exporterType))
return nil
Expand All @@ -300,10 +302,10 @@ func configureExporter(
return err
}

if exporterType == "ActivityExporter" {
if exporterType == configv2alpha2.ExporterConfigTypeActivity {
rawJSON := json.RawMessage("{\"activity_exporter\": null}")
_, err = styraClient.UpdateWorkspaceRaw(context.Background(), rawJSON)
} else if exporterType == "DecisionsExporter" {
} else if exporterType == configv2alpha2.ExporterConfigTypeDecisions {
rawJSON := json.RawMessage("{\"decisions_exporter\": null}")
_, err = styraClient.UpdateWorkspaceRaw(context.Background(), rawJSON)
}
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/styra.bankdata.dk_libraries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
controller-gen.kubebuilder.io/version: v0.18.0
name: libraries.styra.bankdata.dk
spec:
group: styra.bankdata.dk
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/styra.bankdata.dk_systems.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.3
controller-gen.kubebuilder.io/version: v0.18.0
name: systems.styra.bankdata.dk
spec:
group: styra.bankdata.dk
Expand Down