Skip to content

Commit 82c4243

Browse files
fix: move run_worker_first validator out of shared validator package
1 parent 6acb157 commit 82c4243

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

internal/customvalidator/run_worker_first_validator.go renamed to internal/services/workers_script/run_worker_first_validator.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package customvalidator
1+
package workers_script
22

33
import (
44
"context"
@@ -15,12 +15,6 @@ var _ validator.Dynamic = runWorkerFirstValidator{}
1515
// - A list/tuple of strings (for path rules)
1616
type runWorkerFirstValidator struct{}
1717

18-
// RunWorkerFirst returns a validator that ensures the dynamic value is either
19-
// a boolean or a list/tuple containing only string elements.
20-
func RunWorkerFirst() validator.Dynamic {
21-
return runWorkerFirstValidator{}
22-
}
23-
2418
func (v runWorkerFirstValidator) Description(ctx context.Context) string {
2519
return v.MarkdownDescription(ctx)
2620
}
@@ -49,7 +43,7 @@ func (v runWorkerFirstValidator) ValidateDynamic(ctx context.Context, req valida
4943
if _, isStringElement := listType.ElemType.(basetypes.StringType); isStringElement {
5044
return // List of strings is valid
5145
}
52-
resp.Diagnostics.AddAttributeError(req.Path, "Invalid list element type",
46+
resp.Diagnostics.AddAttributeError(req.Path, "Invalid list element type",
5347
"When using a list, all elements must be strings containing path rules")
5448
return
5549
}
@@ -59,7 +53,7 @@ func (v runWorkerFirstValidator) ValidateDynamic(ctx context.Context, req valida
5953
// Verify all elements are strings
6054
for i, elemType := range tupleType.ElemTypes {
6155
if _, isString := elemType.(basetypes.StringType); !isString {
62-
resp.Diagnostics.AddAttributeError(req.Path, "Invalid tuple element type",
56+
resp.Diagnostics.AddAttributeError(req.Path, "Invalid tuple element type",
6357
fmt.Sprintf("Element at index %d must be a string, got %T", i, elemType))
6458
return
6559
}
@@ -68,6 +62,6 @@ func (v runWorkerFirstValidator) ValidateDynamic(ctx context.Context, req valida
6862
}
6963

7064
// If we get here, the type is not supported
71-
resp.Diagnostics.AddAttributeError(req.Path, "Invalid type for run_worker_first",
65+
resp.Diagnostics.AddAttributeError(req.Path, "Invalid type for run_worker_first",
7266
fmt.Sprintf("Expected boolean or list/tuple of strings, got %T", valueType))
7367
}

internal/services/workers_script/schema.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"context"
77

88
"github.com/cloudflare/terraform-provider-cloudflare/internal/customfield"
9-
"github.com/cloudflare/terraform-provider-cloudflare/internal/customvalidator"
109
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
1110
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1211
"github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator"
@@ -125,11 +124,9 @@ func ResourceSchema(ctx context.Context) schema.Schema {
125124
},
126125
},
127126
"run_worker_first": schema.DynamicAttribute{
128-
Description: "When a boolean true, requests will always invoke the Worker script. Otherwise, attempt to serve an asset matching the request, falling back to the Worker script. When a list of strings, contains path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.",
129-
Optional: true,
130-
Validators: []validator.Dynamic{
131-
customvalidator.RunWorkerFirst(),
132-
},
127+
Description: "When a boolean true, requests will always invoke the Worker script. Otherwise, attempt to serve an asset matching the request, falling back to the Worker script. When a list of strings, contains path rules to control routing to either the Worker or assets. Glob (*) and negative (!) rules are supported. Rules must start with either '/' or '!/'. At least one non-negative rule must be provided, and negative rules have higher precedence than non-negative rules.",
128+
Optional: true,
129+
Validators: []validator.Dynamic{runWorkerFirstValidator{}},
133130
CustomType: customfield.NormalizedDynamicType{},
134131
PlanModifiers: []planmodifier.Dynamic{customfield.NormalizeDynamicPlanModifier()},
135132
},

0 commit comments

Comments
 (0)