Skip to content

Commit 5deec71

Browse files
committed
Setup capabilities generator config
1 parent 97098ec commit 5deec71

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package capabilitiesgenerator
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
7+
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
8+
yaml "sigs.k8s.io/yaml/goyaml.v3"
9+
)
10+
11+
func GetInput[W *pdoknlv3.WFS | *pdoknlv3.WMS](webservice W, ownerInfo *smoothoperatorv1.OwnerInfo) (input string, err error) {
12+
switch any(webservice).(type) {
13+
case *pdoknlv3.WFS:
14+
if WFS, ok := any(webservice).(*pdoknlv3.WFS); ok {
15+
return createInputForWFS(WFS, ownerInfo)
16+
}
17+
case *pdoknlv3.WMS:
18+
if _, ok := any(webservice).(*pdoknlv3.WMS); ok {
19+
return "", errors.New("not implemented for WMS")
20+
}
21+
default:
22+
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
23+
}
24+
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
25+
}
26+
27+
func createInputForWFS(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
28+
input, err := MapWFSToCapabilitiesGeneratorInput(wfs, ownerInfo)
29+
if err != nil {
30+
return "", err
31+
}
32+
yamlInput, err := yaml.Marshal(&input)
33+
if err != nil {
34+
return "", fmt.Errorf("failed to marshal the capabilities generator input to yaml: %w", err)
35+
}
36+
37+
return string(yamlInput), nil
38+
}

internal/controller/capabilitiesgenerator/mapper.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package capabilitiesgenerator
22

33
import (
4-
"encoding/xml"
54
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
65
"github.com/pdok/mapserver-operator/internal/controller/mapperutils"
76
"github.com/pdok/ogc-specifications/pkg/wfs200"
@@ -24,7 +23,7 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
2423
Version: *mapperutils.GetLabelValueByKey(wfs.ObjectMeta.Labels, "service-version"),
2524
},
2625
Services: Services{
27-
WFS200Config: WFS200Config{
26+
WFS200Config: &WFS200Config{
2827
Filename: capabilitiesFilename,
2928
Wfs200: wfs200.GetCapabilitiesResponse{
3029

@@ -48,24 +47,9 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
4847
Keyword: wfs.Spec.Service.Keywords,
4948
},
5049
},
51-
5250
Capabilities: wfs200.Capabilities{
5351
FeatureTypeList: getFeatureTypeList(wfs),
5452
},
55-
XMLName: xml.Name{},
56-
Namespaces: wfs200.Namespaces{ // TODO
57-
XmlnsGML: "",
58-
XmlnsWFS: "",
59-
XmlnsOWS: "",
60-
XmlnsXlink: "",
61-
XmlnsXSI: "",
62-
XmlnsFes: "",
63-
XmlnsInspireCommon: "",
64-
XmlnsInspireDls: "",
65-
XmlnsPrefix: "",
66-
Version: "",
67-
SchemaLocation: "",
68-
},
6953
},
7054
},
7155
},
@@ -75,7 +59,7 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
7559
config.Global.AdditionalSchemaLocations = inspireSchemaLocations
7660

7761
// Todo set extended capabilities
78-
config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata = wfs200.OperationsMetadata{}
62+
//config.Services.WFS200Config.Wfs200.Capabilities.OperationsMetadata = wfs200.OperationsMetadata{}
7963
}
8064

8165
return config, nil

internal/controller/capabilitiesgenerator/types.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// TODO Replace this by using the ogc-capabilities-generator from Github
1+
// TODO Move this to the ogc-capabilities-generator on Github
22

33
package capabilitiesgenerator
44

@@ -17,21 +17,21 @@ type Config struct {
1717

1818
// Global contains a collection of base var that are globally usable for the generation of the capabilities
1919
type Global struct {
20-
Prefix string `yaml:"prefix"`
21-
Namespace string `yaml:"namespace"`
22-
OnlineResourceurl string `yaml:"onlineResourceUrl"`
23-
Path string `yaml:"path"`
24-
Version string `yaml:"version"`
25-
AdditionalSchemaLocations string `yaml:"additionalSchemaLocations"`
26-
Empty string
20+
Prefix string `yaml:"prefix"`
21+
Namespace string `yaml:"namespace"`
22+
OnlineResourceurl string `yaml:"onlineResourceUrl"`
23+
Path string `yaml:"path"`
24+
Version string `yaml:"version"`
25+
AdditionalSchemaLocations string `yaml:"additionalSchemaLocations"`
26+
Empty *string `yaml:"-"`
2727
}
2828

2929
// Services contain a single service struct for every service type
3030
type Services struct {
31-
WFS200Config WFS200Config `yaml:"wfs200"`
32-
WMS130Config WMS130Config `yaml:"wms130"`
33-
WMTS100Config WMTS100Config `yaml:"wmts100"`
34-
WCS201Config WCS201Config `yaml:"wcs201"`
31+
WFS200Config *WFS200Config `yaml:"wfs200,omitempty"`
32+
WMS130Config *WMS130Config `yaml:"wms130,omitempty"`
33+
WMTS100Config *WMTS100Config `yaml:"wmts100,omitempty"`
34+
WCS201Config *WCS201Config `yaml:"wcs201,omitempty"`
3535
}
3636

3737
// The WFS200Config service struct

internal/controller/wfs_controller.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package controller
2626

2727
import (
2828
"context"
29-
"fmt"
3029
"github.com/pdok/mapserver-operator/internal/controller/blobdownload"
3130
"github.com/pdok/mapserver-operator/internal/controller/capabilitiesgenerator"
3231
"github.com/pdok/mapserver-operator/internal/controller/mapfilegenerator"
@@ -40,7 +39,6 @@ import (
4039
ctrl "sigs.k8s.io/controller-runtime"
4140
"sigs.k8s.io/controller-runtime/pkg/client"
4241
"sigs.k8s.io/controller-runtime/pkg/log"
43-
yaml "sigs.k8s.io/yaml/goyaml.v3"
4442

4543
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
4644
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
@@ -207,16 +205,11 @@ func (r *WFSReconciler) mutateConfigMapCapabilitiesGenerator(WFS *pdoknlv3.WFS,
207205
}
208206

209207
if len(configMap.Data) == 0 {
210-
input, err := capabilitiesgenerator.MapWFSToCapabilitiesGeneratorInput(WFS, ownerInfo)
208+
input, err := capabilitiesgenerator.GetInput(WFS, ownerInfo)
211209
if err != nil {
212210
return err
213211
}
214-
yamlInput, err := yaml.Marshal(&input)
215-
if err != nil {
216-
return fmt.Errorf("failed to marshal the capabilities generator input to yaml: %w", err)
217-
}
218-
219-
configMap.Data = map[string]string{capabilitiesGeneratorInput: string(yamlInput)}
212+
configMap.Data = map[string]string{capabilitiesGeneratorInput: string(input)}
220213

221214
}
222215
configMap.Immutable = smoothoperatorutils.Pointer(true)

0 commit comments

Comments
 (0)