Commit Diff


commit - 001c466e0421fdbaa864cc31ba288f60dc37068a
commit + 410b374583e5172b215020f0ad3db35a8635fa59
blob - 36b12a496a825ccc2aef75a719a123d76ce3879a
blob + 3c67ea4fc33cb634ff122f5813bdfe569199371c
--- crud.go
+++ crud.go
@@ -2,7 +2,10 @@
 
 package icinga
 
-import "fmt"
+import (
+	"fmt"
+	"net/url"
+)
 
 // Hosts returns a slice of Host matching the filter expression filter.
 // If no hosts match, error wraps ErrNoMatch.
@@ -26,7 +29,7 @@ func (c *Client) Hosts(filter string) ([]Host, error) 
 // LookupHost returns the Host identified by name. If no Host is found, error
 // wraps ErrNotExist.
 func (c *Client) LookupHost(name string) (Host, error) {
-	obj, err := c.lookupObject("/objects/hosts/" + name)
+	obj, err := c.lookupObject("/objects/hosts/" + url.PathEscape(name))
 	if err != nil {
 		return Host{}, fmt.Errorf("lookup host %s: %w", name, err)
 	}
@@ -50,7 +53,7 @@ func (c *Client) CreateHost(host Host) error {
 // depending on the Host are also deleted. If no Host is found, error wraps
 // ErrNotExist.
 func (c *Client) DeleteHost(name string, cascade bool) error {
-	if err := c.deleteObject("/objects/hosts/"+name, cascade); err != nil {
+	if err := c.deleteObject("/objects/hosts/"+url.PathEscape(name), cascade); err != nil {
 		return fmt.Errorf("delete host %s: %w", name, err)
 	}
 	return nil
@@ -77,7 +80,7 @@ func (c *Client) Services(filter string) ([]Service, e
 // LookupService returns the Service identified by name. If no Service is found, error
 // wraps ErrNotExist.
 func (c *Client) LookupService(name string) (Service, error) {
-	obj, err := c.lookupObject("/objects/services/" + name)
+	obj, err := c.lookupObject("/objects/services/" + url.PathEscape(name))
 	if err != nil {
 		return Service{}, fmt.Errorf("lookup service %s: %w", name, err)
 	}
@@ -101,7 +104,7 @@ func (c *Client) CreateService(service Service) error 
 // depending on the Service are also deleted. If no Service is found, error wraps
 // ErrNotExist.
 func (c *Client) DeleteService(name string, cascade bool) error {
-	if err := c.deleteObject("/objects/services/"+name, cascade); err != nil {
+	if err := c.deleteObject("/objects/services/"+url.PathEscape(name), cascade); err != nil {
 		return fmt.Errorf("delete service %s: %w", name, err)
 	}
 	return nil
@@ -128,7 +131,7 @@ func (c *Client) Users(filter string) ([]User, error) 
 // LookupUser returns the User identified by name. If no User is found, error
 // wraps ErrNotExist.
 func (c *Client) LookupUser(name string) (User, error) {
-	obj, err := c.lookupObject("/objects/users/" + name)
+	obj, err := c.lookupObject("/objects/users/" + url.PathEscape(name))
 	if err != nil {
 		return User{}, fmt.Errorf("lookup user %s: %w", name, err)
 	}
@@ -152,7 +155,7 @@ func (c *Client) CreateUser(user User) error {
 // depending on the User are also deleted. If no User is found, error wraps
 // ErrNotExist.
 func (c *Client) DeleteUser(name string, cascade bool) error {
-	if err := c.deleteObject("/objects/users/"+name, cascade); err != nil {
+	if err := c.deleteObject("/objects/users/"+url.PathEscape(name), cascade); err != nil {
 		return fmt.Errorf("delete user %s: %w", name, err)
 	}
 	return nil
@@ -179,7 +182,7 @@ func (c *Client) HostGroups(filter string) ([]HostGrou
 // LookupHostGroup returns the HostGroup identified by name. If no HostGroup is found, error
 // wraps ErrNotExist.
 func (c *Client) LookupHostGroup(name string) (HostGroup, error) {
-	obj, err := c.lookupObject("/objects/hostgroups/" + name)
+	obj, err := c.lookupObject("/objects/hostgroups/" + url.PathEscape(name))
 	if err != nil {
 		return HostGroup{}, fmt.Errorf("lookup hostgroup %s: %w", name, err)
 	}
@@ -203,7 +206,7 @@ func (c *Client) CreateHostGroup(hostgroup HostGroup) 
 // depending on the HostGroup are also deleted. If no HostGroup is found, error wraps
 // ErrNotExist.
 func (c *Client) DeleteHostGroup(name string, cascade bool) error {
-	if err := c.deleteObject("/objects/hostgroups/"+name, cascade); err != nil {
+	if err := c.deleteObject("/objects/hostgroups/"+url.PathEscape(name), cascade); err != nil {
 		return fmt.Errorf("delete hostgroup %s: %w", name, err)
 	}
 	return nil
blob - 2bfde846644d3988f576e0136e9afe7d219c9d62
blob + 021e2c3fc98c66ff53123d27c4e80dc5272e816c
--- crud.sh
+++ crud.sh
@@ -6,7 +6,10 @@ head="// Code generated by $0 $@; DO NOT EDIT.
 
 package icinga
 
-import \"fmt\"
+import (
+	\"fmt\"
+	\"net/url\"
+)
 "
 
 args=`getopt o: $*`
blob - 98555ec48091ac0edc461dbba2a34659164d40b9
blob + 881465210f60f6d5c9fdea50ed48d10abf49c365
--- crud.skel
+++ crud.skel
@@ -20,7 +20,7 @@ func (c *Client) TYPEs(filter string) ([]TYPE, error) 
 // LookupTYPE returns the TYPE identified by name. If no TYPE is found, error
 // wraps ErrNotExist.
 func (c *Client) LookupTYPE(name string) (TYPE, error) {
-	obj, err := c.lookupObject("/objects/PLURAL/" + name)
+	obj, err := c.lookupObject("/objects/PLURAL/" + url.PathEscape(name))
 	if err != nil {
 		return TYPE{}, fmt.Errorf("lookup LOWER %s: %w", name, err)
 	}
@@ -44,7 +44,7 @@ func (c *Client) CreateTYPE(LOWER TYPE) error {
 // depending on the TYPE are also deleted. If no TYPE is found, error wraps
 // ErrNotExist.
 func (c *Client) DeleteTYPE(name string, cascade bool) error {
-	if err := c.deleteObject("/objects/PLURAL/"+name, cascade); err != nil {
+	if err := c.deleteObject("/objects/PLURAL/"+url.PathEscape(name), cascade); err != nil {
 		return fmt.Errorf("delete LOWER %s: %w", name, err)
 	}
 	return nil