Skip to content

Commit 8eb8cca

Browse files
committed
accesscontrstaintes & countdefault
1 parent c972394 commit 8eb8cca

File tree

9 files changed

+52
-27
lines changed

9 files changed

+52
-27
lines changed

api/v2beta1/wfs_conversion.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ package v2beta1
2626

2727
import (
2828
"log"
29+
"strconv"
2930

3031
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
3132
smoothoperatormodel "github.com/pdok/smooth-operator/model"
@@ -43,7 +44,7 @@ func (src *WFS) ConvertTo(dstRaw conversion.Hub) error {
4344
return src.ToV3(dst)
4445
}
4546

46-
//nolint:gosec,funlen
47+
//nolint:gosec,funlen,cyclop
4748
func (src *WFS) ToV3(dst *pdoknlv3.WFS) error {
4849
dst.ObjectMeta = src.ObjectMeta
4950

@@ -87,6 +88,9 @@ func (src *WFS) ToV3(dst *pdoknlv3.WFS) error {
8788
}
8889
}
8990

91+
if err != nil {
92+
return err
93+
}
9094
service := pdoknlv3.WFSService{
9195
Prefix: src.Spec.General.Dataset,
9296
URL: *url,
@@ -106,10 +110,17 @@ func (src *WFS) ToV3(dst *pdoknlv3.WFS) error {
106110
"EPSG::4258",
107111
"EPSG::4326",
108112
},
109-
CountDefault: src.Spec.Service.Maxfeatures,
110113
FeatureTypes: make([]pdoknlv3.FeatureType, 0),
111114
}
112115

116+
if src.Spec.Service.Maxfeatures != nil {
117+
maxFeatures, err := strconv.Atoi(*src.Spec.Service.Maxfeatures)
118+
if err != nil {
119+
return err
120+
}
121+
service.CountDefault = &maxFeatures
122+
}
123+
113124
if src.Spec.Service.Mapfile != nil {
114125
service.Mapfile = &pdoknlv3.Mapfile{
115126
ConfigMapKeyRef: src.Spec.Service.Mapfile.ConfigMapKeyRef,
@@ -209,13 +220,16 @@ func (dst *WFS) ConvertFrom(srcRaw conversion.Hub) error {
209220
Keywords: src.Spec.Service.Keywords,
210221
AccessConstraints: &accessConstraints,
211222
DataEPSG: src.Spec.Service.DefaultCrs,
212-
Maxfeatures: src.Spec.Service.CountDefault,
213223
Authority: Authority{
214224
Name: "",
215225
URL: "",
216226
},
217227
}
218228

229+
if src.Spec.Service.CountDefault != nil {
230+
service.Maxfeatures = smoothoperatorutils.Pointer(strconv.Itoa(*src.Spec.Service.CountDefault))
231+
}
232+
219233
if src.Spec.Service.Bbox != nil {
220234
service.Extent = smoothoperatorutils.Pointer(src.Spec.Service.Bbox.DefaultCRS.ToExtent())
221235
} else {

api/v3/shared_validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v3
22

33
import (
44
"fmt"
5+
56
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"
67
v1 "k8s.io/api/core/v1"
78

api/v3/wfs_types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ type WFSService struct {
126126
Fees *string `json:"fees,omitempty"`
127127

128128
// AccessConstraints URL
129-
// +kubebuilder:validation:Pattern:="https?://"
130129
// +kubebuilder:default="https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
131-
// +kubebuilder:validation:MinLength:=1
132130
AccessConstraints smoothoperatormodel.URL `json:"accessConstraints,omitempty"`
133131

134132
// Default CRS (DataEPSG)
@@ -144,8 +142,8 @@ type WFSService struct {
144142
Bbox *Bbox `json:"bbox,omitempty"`
145143

146144
// CountDefault -> wfs_maxfeatures in mapfile
147-
// +kubebuilder:validation:MinLength:=1
148-
CountDefault *string `json:"countDefault,omitempty"`
145+
// +kubebuilder:validation:Minimum:=1
146+
CountDefault *int `json:"countDefault,omitempty"`
149147

150148
// FeatureTypes configurations
151149
// +kubebuilder:validation:MinItems:=1

api/v3/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/pdok.nl_wfs.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,14 +1064,6 @@ spec:
10641064
format: int32
10651065
type: integer
10661066
type: object
1067-
x-kubernetes-validations:
1068-
- message: 'maxReplicas (default: 30) cannot be less than minReplicas
1069-
(default: 2)'
1070-
rule: (!has(self.maxReplicas) && !has(self.minReplicas)) || (has(self.maxReplicas)
1071-
&& has(self.minReplicas) && self.maxReplicas >= self.minReplicas)
1072-
|| (has(self.maxReplicas) && !has(self.minReplicas) && self.maxReplicas
1073-
>= 2) || (!has(self.maxReplicas) && has(self.minReplicas) && 30
1074-
>= self.minReplicas)
10751067
lifecycle:
10761068
description: Optional lifecycle settings
10771069
properties:
@@ -1143,8 +1135,7 @@ spec:
11431135
accessConstraints:
11441136
default: https://creativecommons.org/publicdomain/zero/1.0/deed.nl
11451137
description: AccessConstraints URL
1146-
minLength: 1
1147-
pattern: https?://
1138+
pattern: ^https?://.+/.+
11481139
type: string
11491140
bbox:
11501141
description: Service bounding box
@@ -1179,8 +1170,8 @@ spec:
11791170
type: object
11801171
countDefault:
11811172
description: CountDefault -> wfs_maxfeatures in mapfile
1182-
minLength: 1
1183-
type: string
1173+
minimum: 1
1174+
type: integer
11841175
defaultCrs:
11851176
description: Default CRS (DataEPSG)
11861177
minLength: 1

config/crd/bases/pdok.nl_wms.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,6 @@ spec:
10851085
format: int32
10861086
type: integer
10871087
type: object
1088-
x-kubernetes-validations:
1089-
- message: 'maxReplicas (default: 30) cannot be less than minReplicas (default: 2)'
1090-
rule: (!has(self.maxReplicas) && !has(self.minReplicas)) || (has(self.maxReplicas) && has(self.minReplicas) && self.maxReplicas >= self.minReplicas) || (has(self.maxReplicas) && !has(self.minReplicas) && self.maxReplicas >= 2) || (!has(self.maxReplicas) && has(self.minReplicas) && 30 >= self.minReplicas)
10911088
lifecycle:
10921089
description: Optional lifecycle settings
10931090
properties:

config/samples/v3_wfs.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ apiVersion: pdok.nl/v3
22
kind: WFS
33
metadata:
44
name: sample
5+
labels:
6+
sample: sample
57
spec:
6-
podSpecPatch: {}
8+
podSpecPatch:
9+
containers:
10+
- name: mapserver
11+
resources:
12+
limits:
13+
ephemeral-storage: 2G
714
service:
8-
accessConstraints: "f"
15+
accessConstraints: "http://bla/bla"
916
title: "title"
1017
abstract: "abstract"
1118
defaultCrs: "EPSG:28992"
@@ -14,6 +21,12 @@ spec:
1421
ownerInfoRef: "owner"
1522
prefix: "prefix"
1623
url: "http://host/path"
24+
inspire:
25+
language: dut
26+
serviceMetadataUrl:
27+
csw:
28+
metadataIdentifier: testtest-test-test-test-testtesttest
29+
spatialDatasetIdentifier: testtest-test-test-test-testtesttest
1730
featureTypes:
1831
- name: "name"
1932
title: "title"

internal/controller/capabilitiesgenerator/mapper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
9191
},
9292
}
9393
}
94+
if wfs.Spec.Service.CountDefault != nil {
95+
operationsMetadata := config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata
96+
if operationsMetadata == nil {
97+
operationsMetadata = &wfs200.OperationsMetadata{}
98+
}
99+
operationsMetadata.Constraint = append(operationsMetadata.Constraint, wfs200.Constraint{
100+
Name: "CountDefault",
101+
DefaultValue: smoothoperatorutils.Pointer(strconv.Itoa(*wfs.Spec.Service.CountDefault)),
102+
})
103+
config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata = operationsMetadata
104+
}
94105

95106
return &config, nil
96107
}

internal/controller/mapfilegenerator/mapper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func MapWFSToMapfileGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv
4848
metadataID = wfs.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier
4949
}
5050

51-
var extent string
51+
extent := defaultExtent
5252
if wfs.Spec.Service.Bbox != nil {
5353
extent = wfs.Spec.Service.Bbox.DefaultCRS.ToExtent()
5454
}
@@ -70,7 +70,7 @@ func MapWFSToMapfileGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv
7070
EPSGList: defaultEpsgList, // wfs.Spec.Service.OtherCrs,
7171
DebugLevel: mapserverDebugLevel,
7272
},
73-
MaxFeatures: smoothoperatorutils.PointerVal(wfs.Spec.Service.CountDefault, strconv.Itoa(defaultMaxFeatures)),
73+
MaxFeatures: strconv.Itoa(smoothoperatorutils.PointerVal(wfs.Spec.Service.CountDefault, defaultMaxFeatures)),
7474
Layers: getWFSLayers(wfs.Spec.Service),
7575
}
7676

0 commit comments

Comments
 (0)