From e153be9166161d8de23ad912fd829713b968536b Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Fri, 2 Aug 2024 08:02:59 +0200 Subject: [PATCH 1/2] update go-geoserver --- go.mod | 2 +- go.sum | 32 ++++---------------------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index 3d80625..79948b1 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index ab9e8b2..a1ad495 100644 --- a/go.sum +++ b/go.sum @@ -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= From 60998fd6b0cb448992a71261e2c7a4b82d2ea653 Mon Sep 17 00:00:00 2001 From: AlexGacon Date: Fri, 2 Aug 2024 08:03:27 +0200 Subject: [PATCH 2/2] feat: add resource for managing url checks (requires 2.26) --- geoserver/provider.go | 1 + geoserver/resource_geoserver_urlcheck.go | 141 +++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 geoserver/resource_geoserver_urlcheck.go diff --git a/geoserver/provider.go b/geoserver/provider.go index 6eaab62..4b9c3a7 100644 --- a/geoserver/provider.go +++ b/geoserver/provider.go @@ -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{}, diff --git a/geoserver/resource_geoserver_urlcheck.go b/geoserver/resource_geoserver_urlcheck.go new file mode 100644 index 0000000..cb185a2 --- /dev/null +++ b/geoserver/resource_geoserver_urlcheck.go @@ -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 +}