Skip to content

Commit 530d2fc

Browse files
committed
pdok-19160 layers zonder naam, maar met styles geven npe in mapserver-operator
1 parent bdd4877 commit 530d2fc

6 files changed

Lines changed: 98 additions & 65 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ linters:
3131
- gocheckcompilerdirectives
3232
- goconst
3333
- gocritic
34-
- gomoddirectives
34+
# - gomoddirectives
3535
- gomodguard
3636
- goprintffuncname
3737
- gosec

api/v3/wms_validation.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,23 @@ func validateLayers(wms *WMS, warnings *[]string, allErrs *field.ErrorList) {
9595
}
9696
}
9797

98-
func validateLayer(layer AnnotatedLayer, path *field.Path, groupStyles []string, layerNames *[]string, hasVisibleLayer *bool, wms *WMS, warnings *[]string, allErrs *field.ErrorList) {
99-
service := wms.Spec.Service
100-
98+
func validateAndGetLayerName(layer AnnotatedLayer, path *field.Path, layerNames *[]string, allErrs *field.ErrorList) {
10199
var layerName string
100+
if layer.Name == nil && len(layer.Styles) > 0 {
101+
*allErrs = append(*allErrs, field.Invalid(
102+
path.Child("layer"),
103+
nil,
104+
fmt.Sprintf("layer with styles must have name. Layer name is empty and the name of the first style is: %s.", layer.Styles[0].Name),
105+
))
106+
}
107+
108+
if layer.IsGroupLayer && layer.Data != nil {
109+
*allErrs = append(*allErrs, field.Invalid(
110+
path.Child("data"),
111+
layer.Data,
112+
"must not be set on a GroupLayer",
113+
))
114+
}
102115
if layer.IsTopLayer && layer.Name == nil {
103116
layerName = "unnamed: " + TopLayer
104117
} else {
@@ -113,22 +126,12 @@ func validateLayer(layer AnnotatedLayer, path *field.Path, groupStyles []string,
113126
} else {
114127
*layerNames = append(*layerNames, layerName)
115128
}
129+
}
116130

117-
if layer.Name == nil && len(layer.Styles) > 0 {
118-
*allErrs = append(*allErrs, field.Invalid(
119-
path.Child("layer"),
120-
nil,
121-
fmt.Sprintf("layer with styles must have name. Layer name is empty and the name of the first style is: %s.", layer.Styles[0].Name),
122-
))
123-
}
131+
func validateLayer(layer AnnotatedLayer, path *field.Path, groupStyles []string, layerNames *[]string, hasVisibleLayer *bool, wms *WMS, warnings *[]string, allErrs *field.ErrorList) {
132+
service := wms.Spec.Service
124133

125-
if layer.IsGroupLayer && layer.Data != nil {
126-
*allErrs = append(*allErrs, field.Invalid(
127-
path.Child("data"),
128-
layer.Data,
129-
"must not be set on a GroupLayer",
130-
))
131-
}
134+
validateAndGetLayerName(layer, path, layerNames, allErrs)
132135

133136
validateLayerWithMapfile(layer, path, wms, warnings, allErrs)
134137

config/crd/update_openapi.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ func main() {
2121

2222
func updateWMSV3(crdDir string) {
2323
path := filepath.Join(crdDir, "pdok.nl_wms.yaml")
24+
cleanPath := filepath.Clean(path)
2425

25-
if _, err := os.Stat(path); os.IsNotExist(err) {
26+
// #nosec G703 -- path is internal and sanitized
27+
if _, err := os.Stat(cleanPath); os.IsNotExist(err) {
2628
panic(errors.Wrap(err, "WMS v3 manifest not found"))
2729
}
2830

29-
content, _ := os.ReadFile(path)
31+
// #nosec G703 -- path is internal and sanitized
32+
content, _ := os.ReadFile(cleanPath)
3033
crd := &v1.CustomResourceDefinition{}
3134
err := kyaml.Unmarshal(content, &crd)
3235
if err != nil {
@@ -53,7 +56,8 @@ func updateWMSV3(crdDir string) {
5356
_ = goyaml.Unmarshal(updatedContent, &rawData)
5457
delete(rawData, "status")
5558

56-
f, _ := os.OpenFile(path, os.O_TRUNC|os.O_WRONLY, 0644)
59+
// #nosec G703 -- path is internal and sanitized
60+
f, _ := os.OpenFile(cleanPath, os.O_TRUNC|os.O_WRONLY, 0644)
5761
defer f.Close()
5862

5963
enc := goyaml.NewEncoder(f)
@@ -117,12 +121,15 @@ func updateLayersV3(version *v1.CustomResourceDefinitionVersion) {
117121

118122
func updateWFSV3(crdDir string) {
119123
path := filepath.Join(crdDir, "pdok.nl_wfs.yaml")
124+
cleanPath := filepath.Clean(path)
120125

121-
if _, err := os.Stat(path); os.IsNotExist(err) {
126+
// #nosec G703 -- path is internal and sanitized
127+
if _, err := os.Stat(cleanPath); os.IsNotExist(err) {
122128
panic(errors.Wrap(err, "WFS v3 manifest not found"))
123129
}
124130

125-
content, _ := os.ReadFile(path)
131+
// #nosec G703 -- path is internal and sanitized
132+
content, _ := os.ReadFile(cleanPath)
126133
crd := &v1.CustomResourceDefinition{}
127134
err := kyaml.Unmarshal(content, &crd)
128135
if err != nil {
@@ -148,7 +155,8 @@ func updateWFSV3(crdDir string) {
148155
_ = goyaml.Unmarshal(updatedContent, &rawData)
149156
delete(rawData, "status")
150157

151-
f, _ := os.OpenFile(path, os.O_TRUNC|os.O_WRONLY, 0644)
158+
// #nosec G703 -- path is internal and sanitized
159+
f, _ := os.OpenFile(cleanPath, os.O_TRUNC|os.O_WRONLY, 0644)
152160
defer f.Close()
153161

154162
enc := goyaml.NewEncoder(f)

go.mod

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module github.com/pdok/mapserver-operator
22

3-
go 1.25
3+
go 1.25.0
44

55
godebug default=go1.25
66

77
require (
88
github.com/cbroglie/mustache v1.4.0
9-
github.com/onsi/ginkgo/v2 v2.23.4
10-
github.com/onsi/gomega v1.37.0
9+
github.com/onsi/ginkgo/v2 v2.28.3
10+
github.com/onsi/gomega v1.40.0
1111
github.com/pdok/featureinfo-generator v1.4.0
1212
github.com/pdok/ogc-capabilities-generator v1.0.1
1313
github.com/pdok/ogc-specifications v1.0.0
@@ -24,7 +24,10 @@ require (
2424

2525
replace github.com/abbot/go-http-auth => github.com/abbot/go-http-auth v0.4.0 // for github.com/traefik/traefik/v3
2626

27+
replace nhooyr.io/websocket => nhooyr.io/websocket v1.8.12 // for github.com/traefik/traefik/v3@v3.6.3
28+
2729
require (
30+
github.com/Masterminds/semver/v3 v3.4.0 // indirect
2831
github.com/aws/smithy-go v1.23.2 // indirect
2932
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
3033
github.com/go-acme/lego/v4 v4.29.0 // indirect
@@ -52,11 +55,10 @@ require (
5255
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.38.0 // indirect
5356
go.opentelemetry.io/otel/log v0.14.0 // indirect
5457
go.opentelemetry.io/otel/sdk/log v0.14.0 // indirect
55-
go.uber.org/automaxprocs v1.6.0 // indirect
5658
go.yaml.in/yaml/v2 v2.4.2 // indirect
5759
go.yaml.in/yaml/v3 v3.0.4 // indirect
58-
golang.org/x/crypto v0.45.0 // indirect
59-
golang.org/x/mod v0.29.0 // indirect
60+
golang.org/x/crypto v0.50.0 // indirect
61+
golang.org/x/mod v0.35.0 // indirect
6062
sigs.k8s.io/randfill v1.0.0 // indirect
6163
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
6264
)
@@ -87,7 +89,7 @@ require (
8789
github.com/google/cel-go v0.26.0 // indirect
8890
github.com/google/gnostic-models v0.7.0 // indirect
8991
github.com/google/go-cmp v0.7.0
90-
github.com/google/pprof v0.0.0-20250501235452-c0086092b71a // indirect
92+
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
9193
github.com/google/uuid v1.6.0 // indirect
9294
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
9395
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -117,14 +119,14 @@ require (
117119
go.uber.org/multierr v1.11.0 // indirect
118120
go.uber.org/zap v1.27.0
119121
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
120-
golang.org/x/net v0.47.0 // indirect
122+
golang.org/x/net v0.53.0 // indirect
121123
golang.org/x/oauth2 v0.33.0 // indirect
122-
golang.org/x/sync v0.18.0 // indirect
123-
golang.org/x/sys v0.38.0 // indirect
124-
golang.org/x/term v0.37.0 // indirect
125-
golang.org/x/text v0.31.0 // indirect
124+
golang.org/x/sync v0.20.0 // indirect
125+
golang.org/x/sys v0.43.0 // indirect
126+
golang.org/x/term v0.42.0 // indirect
127+
golang.org/x/text v0.36.0 // indirect
126128
golang.org/x/time v0.14.0 // indirect
127-
golang.org/x/tools v0.38.0
129+
golang.org/x/tools v0.44.0
128130
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
129131
google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect
130132
google.golang.org/genproto/googleapis/rpc v0.0.0-20251103181224-f26f9409b101 // indirect

0 commit comments

Comments
 (0)