Support bulk removal and name replacement.
diff --git a/openstack/cdn/v1/services/fixtures.go b/openstack/cdn/v1/services/fixtures.go
index 9fecb19..d9bc9f2 100644
--- a/openstack/cdn/v1/services/fixtures.go
+++ b/openstack/cdn/v1/services/fixtures.go
@@ -344,6 +344,15 @@
{
"op": "remove",
"path": "/caching/8"
+ },
+ {
+ "op": "remove",
+ "path": "/caching"
+ },
+ {
+ "op": "replace",
+ "path": "/name",
+ "value": "differentServiceName"
}
]
`)
diff --git a/openstack/cdn/v1/services/requests.go b/openstack/cdn/v1/services/requests.go
index 87443bf..801fd3b 100644
--- a/openstack/cdn/v1/services/requests.go
+++ b/openstack/cdn/v1/services/requests.go
@@ -303,20 +303,40 @@
}
}
+// NameReplacement specifically updates the Service name. Pass it to the Update function as part
+// of the Patch slice.
+type NameReplacement struct {
+ NewName string
+}
+
+// ToCDNServiceUpdateMap converts a NameReplacement into a request body fragment suitable for the
+// Update call.
+func (r NameReplacement) ToCDNServiceUpdateMap() map[string]interface{} {
+ return map[string]interface{}{
+ "op": "replace",
+ "path": "/name",
+ "value": r.NewName,
+ }
+}
+
// Removal is a Patch that requests the removal of a service parameter (Domain, Origin, or
// CacheRule) by index. Pass it to the Update function as part of the Patch slice.
type Removal struct {
Path Path
Index int64
+ All bool
}
// ToCDNServiceUpdateMap converts a Removal into a request body fragment suitable for the
// Update call.
func (r Removal) ToCDNServiceUpdateMap() map[string]interface{} {
- return map[string]interface{}{
- "op": "remove",
- "path": r.Path.renderIndex(r.Index),
+ result := map[string]interface{}{"op": "remove"}
+ if r.All {
+ result["path"] = r.Path.renderRoot()
+ } else {
+ result["path"] = r.Path.renderIndex(r.Index)
}
+ return result
}
// Update accepts a slice of Patch operations (Insertion, Append, Replacement or Removal) and
diff --git a/openstack/cdn/v1/services/requests_test.go b/openstack/cdn/v1/services/requests_test.go
index ca35453..2c11562 100644
--- a/openstack/cdn/v1/services/requests_test.go
+++ b/openstack/cdn/v1/services/requests_test.go
@@ -331,6 +331,15 @@
Index: 8,
Path: PathCaching,
},
+ // Bulk removal
+ Removal{
+ All: true,
+ Path: PathCaching,
+ },
+ // Service name replacement
+ NameReplacement{
+ NewName: "differentServiceName",
+ },
}
actual, err := Update(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", ops).Extract()
diff --git a/rackspace/cdn/v1/services/delegate_test.go b/rackspace/cdn/v1/services/delegate_test.go
index ad2aa81..6c48365 100644
--- a/rackspace/cdn/v1/services/delegate_test.go
+++ b/rackspace/cdn/v1/services/delegate_test.go
@@ -332,6 +332,15 @@
Index: 8,
Path: os.PathCaching,
},
+ // Bulk removal
+ os.Removal{
+ All: true,
+ Path: os.PathCaching,
+ },
+ // Service name replacement
+ os.NameReplacement{
+ NewName: "differentServiceName",
+ },
}
actual, err := Update(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", ops).Extract()