Skip to content

Commit

Permalink
use latest version of geoserver lib
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobioz committed Apr 9, 2021
1 parent 9585a75 commit 5d06228
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 79 deletions.
40 changes: 18 additions & 22 deletions geoserver/resource_geoserver_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func resourceGeoserverDatastore() *schema.Resource {
func resourceGeoserverDatastoreCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Creating Geoserver Datastore: %s", d.Id())

entries := []*gs.DatastoreEntry{}
connectionParameters := []*gs.DatastoreConnectionParameter{}
for key, value := range d.Get("connection_params").(map[string]interface{}) {
entries = append(entries, &gs.DatastoreEntry{
connectionParameters = append(connectionParameters, &gs.DatastoreConnectionParameter{
Key: key,
Value: value.(string),
})
Expand All @@ -69,13 +69,11 @@ func resourceGeoserverDatastoreCreate(d *schema.ResourceData, meta interface{})

workspaceName := d.Get("workspace_name").(string)
datastore := &gs.Datastore{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
Default: d.Get("default").(bool),
ConnectionParameters: &gs.DatastoreConnectionParameters{
Entries: entries,
},
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
Default: d.Get("default").(bool),
ConnectionParameters: connectionParameters,
}

err := client.CreateDatastore(workspaceName, datastore)
Expand Down Expand Up @@ -113,12 +111,12 @@ func resourceGeoserverDatastoreRead(d *schema.ResourceData, meta interface{}) er
d.Set("enabled", datastore.Enabled)
d.Set("default", datastore.Default)

entries := map[string]string{}
for _, entry := range datastore.ConnectionParameters.Entries {
entries[entry.Key] = entry.Value
connectionParameters := map[string]string{}
for _, entry := range datastore.ConnectionParameters {
connectionParameters[entry.Key] = entry.Value
}

d.Set("connection_params", entries)
d.Set("connection_params", connectionParameters)

return nil
}
Expand Down Expand Up @@ -149,9 +147,9 @@ func resourceGeoserverDatastoreUpdate(d *schema.ResourceData, meta interface{})
workspaceName := splittedID[0]
datastoreName := splittedID[1]

entries := []*gs.DatastoreEntry{}
connectionParameters := []*gs.DatastoreConnectionParameter{}
for key, value := range d.Get("connection_params").(map[string]interface{}) {
entries = append(entries, &gs.DatastoreEntry{
connectionParameters = append(connectionParameters, &gs.DatastoreConnectionParameter{
Key: key,
Value: value.(string),
})
Expand All @@ -160,13 +158,11 @@ func resourceGeoserverDatastoreUpdate(d *schema.ResourceData, meta interface{})
client := meta.(*Config).Client()

err := client.UpdateDatastore(workspaceName, datastoreName, &gs.Datastore{
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
Default: d.Get("default").(bool),
ConnectionParameters: &gs.DatastoreConnectionParameters{
Entries: entries,
},
Name: d.Get("name").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
Default: d.Get("default").(bool),
ConnectionParameters: connectionParameters,
})
if err != nil {
return err
Expand Down
56 changes: 43 additions & 13 deletions geoserver/resource_geoserver_featuretype.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func resourceGeoserverFeatureType() *schema.Resource {
},
},
},
"metadata": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -168,14 +173,22 @@ func resourceGeoserverFeatureTypeCreate(d *schema.ResourceData, meta interface{}
})
}

var metadata []*gs.FeatureTypeMetadata
for key, value := range d.Get("metadata").(map[string]interface{}) {
metadata = append(metadata, &gs.FeatureTypeMetadata{
Key: key,
Value: value.(string),
})
}

featureType := &gs.FeatureType{
Name: d.Get("name").(string),
NativeName: d.Get("native_name").(string),
Enabled: d.Get("enabled").(bool),
ProjectionPolicy: d.Get("projection_policy").(string),
Title: d.Get("title").(string),
Abstract: d.Get("abstract").(string),
NativeCRS: gs.CRSWrapper{
NativeCRS: gs.FeatureTypeCRS{
Class: d.Get("native_crs_class").(string),
Value: d.Get("native_crs_value").(string),
},
Expand All @@ -185,7 +198,7 @@ func resourceGeoserverFeatureTypeCreate(d *schema.ResourceData, meta interface{}
MaxX: d.Get("native_bounding_box_max_x").(float64),
MinY: d.Get("native_bounding_box_min_y").(float64),
MaxY: d.Get("native_bounding_box_max_y").(float64),
CRS: gs.CRSWrapper{
CRS: gs.FeatureTypeCRS{
Class: d.Get("native_bounding_box_crs_class").(string),
Value: d.Get("native_bounding_box_crs_value").(string),
},
Expand All @@ -195,14 +208,13 @@ func resourceGeoserverFeatureTypeCreate(d *schema.ResourceData, meta interface{}
MaxX: d.Get("lat_lon_bounding_box_max_x").(float64),
MinY: d.Get("lat_lon_bounding_box_min_y").(float64),
MaxY: d.Get("lat_lon_bounding_box_max_y").(float64),
CRS: gs.CRSWrapper{
CRS: gs.FeatureTypeCRS{
Class: d.Get("lat_lon_bounding_box_crs_class").(string),
Value: d.Get("lat_lon_bounding_box_crs_value").(string),
},
},
Attributes: gs.FeatureTypeAttributesList{
Attribute: attributes,
},
Attributes: attributes,
Metadata: metadata,
}

err := client.CreateFeatureType(workspaceName, datastoreName, featureType)
Expand Down Expand Up @@ -242,6 +254,9 @@ func resourceGeoserverFeatureTypeRead(d *schema.ResourceData, meta interface{})
d.Set("projection_policy", featureType.ProjectionPolicy)
d.Set("srs", featureType.SRS)

d.Set("native_crs_class", featureType.NativeCRS.Class)
d.Set("native_crs_value", featureType.NativeCRS.Value)

d.Set("native_bounding_box_min_x", featureType.NativeBoundingBox.MinX)
d.Set("native_bounding_box_max_x", featureType.NativeBoundingBox.MaxX)
d.Set("native_bounding_box_min_y", featureType.NativeBoundingBox.MinY)
Expand All @@ -257,7 +272,7 @@ func resourceGeoserverFeatureTypeRead(d *schema.ResourceData, meta interface{})
d.Set("lat_lon_bounding_box_crs_value", featureType.LatLonBoundingBox.CRS.Value)

var attributes []map[string]interface{}
for _, value := range featureType.Attributes.Attribute {
for _, value := range featureType.Attributes {
attributes = append(attributes, map[string]interface{}{
"name": value.Name,
"nillable": value.Nillable,
Expand All @@ -268,6 +283,14 @@ func resourceGeoserverFeatureTypeRead(d *schema.ResourceData, meta interface{})
}
d.Set("attribute", attributes)

metadata := map[string]interface{}{}
if featureType.Metadata != nil {
for _, entry := range featureType.Metadata {
metadata[entry.Key] = entry.Value
}
d.Set("metadata", metadata)
}

return nil
}

Expand Down Expand Up @@ -313,14 +336,22 @@ func resourceGeoserverFeatureTypeUpdate(d *schema.ResourceData, meta interface{}
})
}

var metadata []*gs.FeatureTypeMetadata
for key, value := range d.Get("metadata").(map[string]interface{}) {
metadata = append(metadata, &gs.FeatureTypeMetadata{
Key: key,
Value: value.(string),
})
}

featureType := &gs.FeatureType{
Name: d.Get("name").(string),
NativeName: d.Get("native_name").(string),
Enabled: d.Get("enabled").(bool),
ProjectionPolicy: d.Get("projection_policy").(string),
Title: d.Get("title").(string),
Abstract: d.Get("abstract").(string),
NativeCRS: gs.CRSWrapper{
NativeCRS: gs.FeatureTypeCRS{
Class: d.Get("native_crs_class").(string),
Value: d.Get("native_crs_value").(string),
},
Expand All @@ -330,7 +361,7 @@ func resourceGeoserverFeatureTypeUpdate(d *schema.ResourceData, meta interface{}
MaxX: d.Get("native_bounding_box_max_x").(float64),
MinY: d.Get("native_bounding_box_min_y").(float64),
MaxY: d.Get("native_bounding_box_max_y").(float64),
CRS: gs.CRSWrapper{
CRS: gs.FeatureTypeCRS{
Class: d.Get("native_bounding_box_crs_class").(string),
Value: d.Get("native_bounding_box_crs_value").(string),
},
Expand All @@ -340,14 +371,13 @@ func resourceGeoserverFeatureTypeUpdate(d *schema.ResourceData, meta interface{}
MaxX: d.Get("lat_lon_bounding_box_max_x").(float64),
MinY: d.Get("lat_lon_bounding_box_min_y").(float64),
MaxY: d.Get("lat_lon_bounding_box_max_y").(float64),
CRS: gs.CRSWrapper{
CRS: gs.FeatureTypeCRS{
Class: d.Get("lat_lon_bounding_box_crs_class").(string),
Value: d.Get("lat_lon_bounding_box_crs_value").(string),
},
},
Attributes: gs.FeatureTypeAttributesList{
Attribute: attributes,
},
Attributes: attributes,
Metadata: metadata,
}

err := client.UpdateFeatureType(workspaceName, datastoreName, featureTypeName, featureType)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/camptocamp/terraform-provider-geoserver
go 1.15

require (
github.com/camptocamp/go-geoserver v0.0.0-20201217085406-b8f2cc28cf28
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/camptocamp/go-geoserver v0.0.0-20210409170459-4ecb9de42a98
github.com/hashicorp/terraform-plugin-sdk v1.16.1
)
Loading

0 comments on commit 5d06228

Please sign in to comment.