Skip to content

Commit 84cc945

Browse files
d0weinbergerarthurpitman
authored andcommitted
feat(openpipeline): Adds violation path to resource creation and update for OpenPipeline
1 parent 127da5c commit 84cc945

File tree

3 files changed

+65
-47
lines changed

3 files changed

+65
-47
lines changed

dynatrace/rest/error.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (me Error) Error() string {
243243
return msg
244244
}
245245

246-
func (me Error) ViolationMessage() string {
246+
func (me Error) ViolationMessage(alwaysIncludePath bool) string {
247247
if len(me.ConstraintViolations) == 0 {
248248
return ""
249249
}
@@ -252,15 +252,23 @@ func (me Error) ViolationMessage() string {
252252
if len(result) > 0 {
253253
result = result + "\n"
254254
}
255-
if strings.Contains(violation.Message, "must not be null") || strings.Contains(violation.Message, "Element may not be null on creation") {
256-
result = result + violation.Path + " " + violation.Message
255+
if alwaysIncludePath || strings.Contains(violation.Message, "must not be null") || strings.Contains(violation.Message, "Element may not be null on creation") {
256+
result = result + removeSchemaAndObjectIndexFromConstraintViolationPath(violation.Path) + ": " + violation.Message
257257
} else {
258258
result = result + violation.Message
259259
}
260260
}
261261
return result
262262
}
263263

264+
func removeSchemaAndObjectIndexFromConstraintViolationPath(path string) string {
265+
pathSubstrings := strings.SplitN(path, "/", 3)
266+
if len(pathSubstrings) < 3 {
267+
return path
268+
}
269+
return strings.Join(pathSubstrings[2:], "/")
270+
}
271+
264272
type ConstraintViolation struct {
265273
Description string `json:"description,omitempty"`
266274
ParameterLocation string `json:"parameterLocation,omitempty"`

provider/provider.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -637,45 +637,45 @@ func Provider() *schema.Provider {
637637
"dynatrace_failure_detection_rule_sets": resources.NewGeneric(export.ResourceTypes.FailureDetectionRuleSets).Resource(),
638638
"dynatrace_endpoint_detection_rules_optin": resources.NewGeneric(export.ResourceTypes.EndpointDetectionRulesOptIn).Resource(),
639639
"dynatrace_endpoint_detection_rules": resources.NewGeneric(export.ResourceTypes.EndpointDetectionRules).Resource(),
640-
"dynatrace_openpipeline_v2_bizevents_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineBizeventsIngestsources).Resource(),
641-
"dynatrace_openpipeline_v2_bizevents_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineBizeventsPipelines).Resource(),
642-
"dynatrace_openpipeline_v2_bizevents_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineBizeventsRouting).Resource(),
643-
"dynatrace_openpipeline_v2_davis_events_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisEventsIngestsources).Resource(),
644-
"dynatrace_openpipeline_v2_davis_events_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisEventsPipelines).Resource(),
645-
"dynatrace_openpipeline_v2_davis_events_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisEventsRouting).Resource(),
646-
"dynatrace_openpipeline_v2_davis_problems_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisProblemsIngestsources).Resource(),
647-
"dynatrace_openpipeline_v2_davis_problems_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisProblemsPipelines).Resource(),
648-
"dynatrace_openpipeline_v2_davis_problems_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineDavisProblemsRouting).Resource(),
649-
"dynatrace_openpipeline_v2_events_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsIngestsources).Resource(),
650-
"dynatrace_openpipeline_v2_events_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsPipelines).Resource(),
651-
"dynatrace_openpipeline_v2_events_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsRouting).Resource(),
652-
"dynatrace_openpipeline_v2_events_sdlc_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSdlcIngestsources).Resource(),
653-
"dynatrace_openpipeline_v2_events_sdlc_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSdlcPipelines).Resource(),
654-
"dynatrace_openpipeline_v2_events_sdlc_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSdlcRouting).Resource(),
655-
"dynatrace_openpipeline_v2_events_security_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSecurityIngestsources).Resource(),
656-
"dynatrace_openpipeline_v2_events_security_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSecurityPipelines).Resource(),
657-
"dynatrace_openpipeline_v2_events_security_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineEventsSecurityRouting).Resource(),
658-
"dynatrace_openpipeline_v2_logs_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineLogsIngestsources).Resource(),
659-
"dynatrace_openpipeline_v2_logs_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineLogsPipelines).Resource(),
660-
"dynatrace_openpipeline_v2_logs_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineLogsRouting).Resource(),
661-
"dynatrace_openpipeline_v2_metrics_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineMetricsIngestsources).Resource(),
662-
"dynatrace_openpipeline_v2_metrics_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineMetricsPipelines).Resource(),
663-
"dynatrace_openpipeline_v2_metrics_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineMetricsRouting).Resource(),
664-
"dynatrace_openpipeline_v2_security_events_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineSecurityEventsIngestsources).Resource(),
665-
"dynatrace_openpipeline_v2_security_events_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineSecurityEventsPipelines).Resource(),
666-
"dynatrace_openpipeline_v2_security_events_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineSecurityEventsRouting).Resource(),
667-
"dynatrace_openpipeline_v2_spans_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineSpansIngestsources).Resource(),
668-
"dynatrace_openpipeline_v2_spans_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineSpansPipelines).Resource(),
669-
"dynatrace_openpipeline_v2_spans_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineSpansRouting).Resource(),
670-
"dynatrace_openpipeline_v2_system_events_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineSystemEventsIngestsources).Resource(),
671-
"dynatrace_openpipeline_v2_system_events_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineSystemEventsPipelines).Resource(),
672-
"dynatrace_openpipeline_v2_system_events_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineSystemEventsRouting).Resource(),
673-
"dynatrace_openpipeline_v2_user_events_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineUserEventsIngestsources).Resource(),
674-
"dynatrace_openpipeline_v2_user_events_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineUserEventsPipelines).Resource(),
675-
"dynatrace_openpipeline_v2_user_events_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineUserEventsRouting).Resource(),
676-
"dynatrace_openpipeline_v2_usersessions_ingestsources": resources.NewGeneric(export.ResourceTypes.OpenpipelineUsersessionsIngestsources).Resource(),
677-
"dynatrace_openpipeline_v2_usersessions_pipelines": resources.NewGeneric(export.ResourceTypes.OpenpipelineUsersessionsPipelines).Resource(),
678-
"dynatrace_openpipeline_v2_usersessions_routing": resources.NewGeneric(export.ResourceTypes.OpenpipelineUsersessionsRouting).Resource(),
640+
"dynatrace_openpipeline_v2_bizevents_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineBizeventsIngestsources).Resource(),
641+
"dynatrace_openpipeline_v2_bizevents_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineBizeventsPipelines).Resource(),
642+
"dynatrace_openpipeline_v2_bizevents_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineBizeventsRouting).Resource(),
643+
"dynatrace_openpipeline_v2_davis_events_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisEventsIngestsources).Resource(),
644+
"dynatrace_openpipeline_v2_davis_events_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisEventsPipelines).Resource(),
645+
"dynatrace_openpipeline_v2_davis_events_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisEventsRouting).Resource(),
646+
"dynatrace_openpipeline_v2_davis_problems_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisProblemsIngestsources).Resource(),
647+
"dynatrace_openpipeline_v2_davis_problems_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisProblemsPipelines).Resource(),
648+
"dynatrace_openpipeline_v2_davis_problems_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineDavisProblemsRouting).Resource(),
649+
"dynatrace_openpipeline_v2_events_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsIngestsources).Resource(),
650+
"dynatrace_openpipeline_v2_events_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsPipelines).Resource(),
651+
"dynatrace_openpipeline_v2_events_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsRouting).Resource(),
652+
"dynatrace_openpipeline_v2_events_sdlc_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSdlcIngestsources).Resource(),
653+
"dynatrace_openpipeline_v2_events_sdlc_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSdlcPipelines).Resource(),
654+
"dynatrace_openpipeline_v2_events_sdlc_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSdlcRouting).Resource(),
655+
"dynatrace_openpipeline_v2_events_security_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSecurityIngestsources).Resource(),
656+
"dynatrace_openpipeline_v2_events_security_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSecurityPipelines).Resource(),
657+
"dynatrace_openpipeline_v2_events_security_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineEventsSecurityRouting).Resource(),
658+
"dynatrace_openpipeline_v2_logs_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineLogsIngestsources).Resource(),
659+
"dynatrace_openpipeline_v2_logs_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineLogsPipelines).Resource(),
660+
"dynatrace_openpipeline_v2_logs_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineLogsRouting).Resource(),
661+
"dynatrace_openpipeline_v2_metrics_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineMetricsIngestsources).Resource(),
662+
"dynatrace_openpipeline_v2_metrics_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineMetricsPipelines).Resource(),
663+
"dynatrace_openpipeline_v2_metrics_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineMetricsRouting).Resource(),
664+
"dynatrace_openpipeline_v2_security_events_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSecurityEventsIngestsources).Resource(),
665+
"dynatrace_openpipeline_v2_security_events_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSecurityEventsPipelines).Resource(),
666+
"dynatrace_openpipeline_v2_security_events_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSecurityEventsRouting).Resource(),
667+
"dynatrace_openpipeline_v2_spans_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSpansIngestsources).Resource(),
668+
"dynatrace_openpipeline_v2_spans_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSpansPipelines).Resource(),
669+
"dynatrace_openpipeline_v2_spans_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSpansRouting).Resource(),
670+
"dynatrace_openpipeline_v2_system_events_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSystemEventsIngestsources).Resource(),
671+
"dynatrace_openpipeline_v2_system_events_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSystemEventsPipelines).Resource(),
672+
"dynatrace_openpipeline_v2_system_events_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineSystemEventsRouting).Resource(),
673+
"dynatrace_openpipeline_v2_user_events_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUserEventsIngestsources).Resource(),
674+
"dynatrace_openpipeline_v2_user_events_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUserEventsPipelines).Resource(),
675+
"dynatrace_openpipeline_v2_user_events_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUserEventsRouting).Resource(),
676+
"dynatrace_openpipeline_v2_usersessions_ingestsources": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUsersessionsIngestsources).Resource(),
677+
"dynatrace_openpipeline_v2_usersessions_pipelines": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUsersessionsPipelines).Resource(),
678+
"dynatrace_openpipeline_v2_usersessions_routing": resources.NewGenericWithAlwaysPrintingViolationPath(export.ResourceTypes.OpenpipelineUsersessionsRouting).Resource(),
679679
},
680680
ConfigureContextFunc: config.ProviderConfigure,
681681
}

resources/generic.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ func NewGeneric(resourceType export.ResourceType, credVal ...int) *Generic {
4747
return &Generic{Type: resourceType, Descriptor: descriptor, CredentialValidation: cv}
4848
}
4949

50+
func NewGenericWithAlwaysPrintingViolationPath(resourceType export.ResourceType, credVal ...int) *Generic {
51+
descriptor := export.AllResources[resourceType]
52+
cv := CredValDefault
53+
if len(credVal) > 0 {
54+
cv = credVal[0]
55+
}
56+
return &Generic{Type: resourceType, Descriptor: descriptor, CredentialValidation: cv, AlwaysPrintViolationPath: true}
57+
}
58+
5059
type Computer interface {
5160
IsComputer() bool
5261
}
@@ -58,9 +67,10 @@ const (
5867
)
5968

6069
type Generic struct {
61-
Type export.ResourceType
62-
Descriptor export.ResourceDescriptor
63-
CredentialValidation int
70+
Type export.ResourceType
71+
Descriptor export.ResourceDescriptor
72+
CredentialValidation int
73+
AlwaysPrintViolationPath bool
6474
}
6575

6676
type Deprecated interface {
@@ -200,7 +210,7 @@ func (me *Generic) Create(ctx context.Context, d *schema.ResourceData, m any) di
200210
return diag.Diagnostics{diag.Diagnostic{Severity: diag.Warning, Summary: restWarning.Message}}
201211
}
202212
if restError, ok := err.(rest.Error); ok {
203-
vm := restError.ViolationMessage()
213+
vm := restError.ViolationMessage(me.AlwaysPrintViolationPath)
204214
if len(vm) > 0 {
205215
return diag.FromErr(errors.New(vm))
206216
}
@@ -262,7 +272,7 @@ func (me *Generic) Update(ctx context.Context, d *schema.ResourceData, m any) di
262272
return diag.Diagnostics{diag.Diagnostic{Severity: diag.Warning, Summary: restWarning.Message}}
263273
}
264274
if restError, ok := err.(rest.Error); ok {
265-
vm := restError.ViolationMessage()
275+
vm := restError.ViolationMessage(me.AlwaysPrintViolationPath)
266276
if len(vm) > 0 {
267277
return diag.FromErr(errors.New(vm))
268278
}

0 commit comments

Comments
 (0)