Skip to content

Commit

Permalink
Merge pull request #46 from AlexGacon/master
Browse files Browse the repository at this point in the history
Implement url checks as resource and fix gridset creation issue
  • Loading branch information
AlexGacon authored Aug 2, 2024
2 parents 02b3966 + 60998fd commit c5d0b7d
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 29 deletions.
1 change: 1 addition & 0 deletions geoserver/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Provider() terraform.ResourceProvider {
"geoserver_gwc_wms_layer": resourceGwcWmsLayer(),
"geoserver_wms_store": resourceGeoserverWmsStore(),
"geoserver_wms_layer": resourceGeoserverWmsLayer(),
"geoserver_url_check": resourceGeoserverUrlCheck(),
},

DataSourcesMap: map[string]*schema.Resource{},
Expand Down
141 changes: 141 additions & 0 deletions geoserver/resource_geoserver_urlcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package geoserver

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

gs "github.com/camptocamp/go-geoserver/client"
)

func resourceGeoserverUrlCheck() *schema.Resource {
return &schema.Resource{
Create: resourceGeoserverUrlCheckCreate,
Read: resourceGeoserverUrlCheckRead,
Update: resourceGeoserverUrlCheckUpdate,
Delete: resourceGeoserverUrlCheckDelete,
Importer: &schema.ResourceImporter{
State: resourceGeoserverUrlCheckImport,
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the check. Use as resource id.",
},
"regex": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Regular expression to evaluate the URL check.",
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
ForceNew: true,
Description: "Declare the check as enabled. Default value: true.",
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: "Description of the check.",
},
},
}
}

func resourceGeoserverUrlCheckCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Creating Geoserver UrlCheck: %s", d.Id())

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

name := d.Get("name").(string)

err := client.CreateRegExUrlCheck(name, &gs.RegexUrlCheck{
Name: name,
IsEnabled: d.Get("enabled").(bool),
Description: d.Get("description").(string),
Regex: d.Get("regex").(string),
})
if err != nil {
return err
}

d.SetId(name)

return resourceGeoserverUrlCheckRead(d, meta)
}

func resourceGeoserverUrlCheckRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Refreshing Geoserver UrlCheck: %s", d.Id())

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

urlcheck, err := client.GetRegExUrlCheck(d.Id())
if err != nil && !strings.Contains(strings.ToLower(err.Error()), "not found") {
return err
}

if urlcheck == nil {
d.SetId("")
return nil
}

d.Set("name", urlcheck.Name)
d.Set("enabled", urlcheck.IsEnabled)
d.Set("description", urlcheck.Description)
d.Set("regex", urlcheck.Regex)

return nil
}

func resourceGeoserverUrlCheckDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Deleting Geoserver UrlCheck: %s", d.Id())

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

err := client.DeleteUrlCheck(d.Id())
if err != nil {
return err
}

d.SetId("")

return nil
}

func resourceGeoserverUrlCheckUpdate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Updating Geoserver UrlCheck: %s", d.Id())

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

err := client.UpdateRegExUrlCheck(d.Id(), &gs.RegexUrlCheck{
Name: d.Get("name").(string),
IsEnabled: d.Get("enabled").(bool),
Description: d.Get("description").(string),
Regex: d.Get("regex").(string),
})
if err != nil {
return err
}

return nil
}

func resourceGeoserverUrlCheckImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.SetId(d.Id())
d.Set("name", d.Id())

log.Printf("[INFO] Importing Geoserver UrlCheck `%s`", d.Id())

err := resourceGeoserverUrlCheckRead(d, meta)
if err != nil {
return []*schema.ResourceData{}, err
}

return []*schema.ResourceData{d}, nil
}
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-20240605083447-9ae81a90b5fb
github.com/camptocamp/go-geoserver v0.0.0-20240802060127-cea5297acc26
github.com/hashicorp/terraform-plugin-sdk v1.17.2
)
32 changes: 4 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,10 @@ github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1U
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/camptocamp/go-geoserver v0.0.0-20220824111235-a59739cbca06 h1:TOtHfX4C41UpxIp0FnSb+lkjJ3eub7VCsuVAubj36l8=
github.com/camptocamp/go-geoserver v0.0.0-20220824111235-a59739cbca06/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20230411111416-017d2cbe6089 h1:p3ZWJgToWhzHI8f8uFcviv3Hi2sIirEv1fvnWz8n7ZY=
github.com/camptocamp/go-geoserver v0.0.0-20230411111416-017d2cbe6089/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20230413070032-5ff18de0e31f h1:qjug77v/Ikv+n/jku2WPCpuGK8Z0qBvG2rEwmwau4q0=
github.com/camptocamp/go-geoserver v0.0.0-20230413070032-5ff18de0e31f/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20230413094816-873b554b1a63 h1:1mFuMCPl5vXd+NDyFQdgIrExBEt3ZOqPVXacuZjDfjE=
github.com/camptocamp/go-geoserver v0.0.0-20230413094816-873b554b1a63/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20231115053359-0cb9d233e47b h1:qEwm1gMIgjnWONkBW5nXkWHKg+iMvX9B9SBcoRvFxZE=
github.com/camptocamp/go-geoserver v0.0.0-20231115053359-0cb9d233e47b/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20231214134413-1f8328ca30e1 h1:OkhGBtwDPRttLDZpWud2OLla0t5z8V1uzkV0yK1+sJk=
github.com/camptocamp/go-geoserver v0.0.0-20231214134413-1f8328ca30e1/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20231215134021-3de16c4e15e6 h1:KAh6NDPaJuWMKleEhqUxi6oUbyZR4kuag95NIWKRxDM=
github.com/camptocamp/go-geoserver v0.0.0-20231215134021-3de16c4e15e6/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20231215143954-f99a84dadc4c h1:OUukvFTaOC2hb19gKGJkrZO0NmYvV4EHPtbproyScr0=
github.com/camptocamp/go-geoserver v0.0.0-20231215143954-f99a84dadc4c/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20231220144753-e3d59d348b48 h1:x8yl62xEuSkKCidZi6AtjYVcb704kiW1LAN0j3Xtufo=
github.com/camptocamp/go-geoserver v0.0.0-20231220144753-e3d59d348b48/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240205195341-221dfa93f919 h1:D+SK80n6S2aJ7zfUhwH7a0wIBLOc+YBlGCB45Q1HxZc=
github.com/camptocamp/go-geoserver v0.0.0-20240205195341-221dfa93f919/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240316093744-f4045a49a9bb h1:I1A3UCsisRxCtbJu4KtlVgjAmbHQalapTj1Vd/OAsH0=
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/camptocamp/go-geoserver v0.0.0-20240722132434-9d74f11266b4 h1:aADY17pTP0yTY9FmzgDQz41Dt9aPqsSBjJMrqmzE4DQ=
github.com/camptocamp/go-geoserver v0.0.0-20240722132434-9d74f11266b4/go.mod h1:z5s93Ll45psIP40hoVWpQPservcqeX4MOQDLV+Ys4rE=
github.com/camptocamp/go-geoserver v0.0.0-20240802060127-cea5297acc26 h1:q1g3toWpryq0Hygtk4KGWffA9VA3wlrmQHlgxtMCXyk=
github.com/camptocamp/go-geoserver v0.0.0-20240802060127-cea5297acc26/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 c5d0b7d

Please sign in to comment.