Skip to content

Commit

Permalink
Merge pull request #38 from AlexGacon/master
Browse files Browse the repository at this point in the history
Improve FeatureType instanciation and Provider checking
  • Loading branch information
AlexGacon authored Jun 5, 2024
2 parents 64dcf31 + cc87bb0 commit 8b09a13
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
35 changes: 35 additions & 0 deletions geoserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ type Config struct {
InsecureSkipVerify bool
}

func CreateConfig(URL string,
GwcURL string,
Username string,
Password string,
InsecureSkipVerify bool) (interface{}, error) {
// test GeoServer URL
if len(URL) > 0 {
_, err := http.Get(URL)
if err != nil {
log.Print(err.Error())
return nil, err
}
} else {
log.Printf("[INFO] No GeoServer URL configured")
}

// test GWC URL
if len(GwcURL) > 0 {
_, err := http.Get(GwcURL)
if err != nil {
log.Print(err.Error())
return nil, err
}
} else {
log.Printf("[INFO] No GeoWebCache URL configured")
}
return &Config{
URL: URL,
GwcURL: GwcURL,
Username: Username,
Password: Password,
InsecureSkipVerify: InsecureSkipVerify,
}, nil
}

// GeoserverClient creates a Geoserver client scoped to the global API
func (c *Config) GeoserverClient() *gs.Client {
tspt := &http.Transport{
Expand Down
23 changes: 20 additions & 3 deletions geoserver/resource_geoserver_featuretype.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,26 @@ func resourceGeoserverFeatureTypeDelete(d *schema.ResourceData, meta interface{}

client := meta.(*Config).GeoserverClient()

err := client.DeleteFeatureType(workspaceName, datastoreName, featureTypeName, true)
if err != nil {
return err
layer, errget := client.GetLayer(workspaceName, featureTypeName)
if layer != nil {
// If there is a matching layer into geoserver, delete it first
err1 := client.DeleteLayer(workspaceName, featureTypeName, true)
if err1 != nil {
return err1
}

err2 := client.DeleteFeatureType(workspaceName, datastoreName, featureTypeName, false)
if err2 != nil {
return err2
}
} else if errget.Error() == "not found" {
// If not, delete only the feature type
err2 := client.DeleteFeatureType(workspaceName, datastoreName, featureTypeName, true)
if err2 != nil {
return err2
}
} else {
return errget
}

d.SetId("")
Expand Down
2 changes: 1 addition & 1 deletion 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-20240415102559-1622f7987132
github.com/camptocamp/go-geoserver v0.0.0-20240605083447-9ae81a90b5fb
github.com/hashicorp/terraform-plugin-sdk v1.17.2
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ github.com/camptocamp/go-geoserver v0.0.0-20240316093744-f4045a49a9bb h1:I1A3UCs
github.com/camptocamp/go-geoserver v0.0.0-20240316093744-f4045a49a9bb/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240415102559-1622f7987132 h1:htCu63XZFIwMPbDtoO0sJtAA1vqhizeeSJ6xSU2DSbo=
github.com/camptocamp/go-geoserver v0.0.0-20240415102559-1622f7987132/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240604114100-d0a7ba1d48d4 h1:YzwAIcGrneK6XA4bdIwdCl6FuHjeYZ/hVAY9yjcbffo=
github.com/camptocamp/go-geoserver v0.0.0-20240604114100-d0a7ba1d48d4/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240605083447-9ae81a90b5fb h1:9gQZZYLFzBr6QrmyGtug9OF3WRvTQbqP6FTRt7e9s98=
github.com/camptocamp/go-geoserver v0.0.0-20240605083447-9ae81a90b5fb/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
Expand Down

0 comments on commit 8b09a13

Please sign in to comment.