From 4dc5596bc63a769c55a68efd2ead57a1ac5a3f29 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Tue, 14 Dec 2021 15:09:40 -0500 Subject: [PATCH] Remove code for CDN (poppy) OpenStack CDN (Poppy) isn't maintained anymore, last commit was 5 years ago: https://opendev.org/x/poppy/commits/branch/master This patch removes all the code that called CDN v1 API, which is not tested, and the upstream project doesn't seem to be alive anymore. This effort is made for helping to maintain Gophercloud and clean the things we don't need/use anymore. --- openstack/cdn/v1/base/doc.go | 4 - openstack/cdn/v1/base/requests.go | 21 - openstack/cdn/v1/base/results.go | 23 -- openstack/cdn/v1/base/testing/doc.go | 2 - openstack/cdn/v1/base/testing/fixtures.go | 53 --- .../cdn/v1/base/testing/requests_test.go | 46 --- openstack/cdn/v1/base/urls.go | 11 - openstack/cdn/v1/flavors/doc.go | 6 - openstack/cdn/v1/flavors/requests.go | 20 - openstack/cdn/v1/flavors/results.go | 64 --- openstack/cdn/v1/flavors/testing/doc.go | 2 - openstack/cdn/v1/flavors/testing/fixtures.go | 82 ---- .../cdn/v1/flavors/testing/requests_test.go | 90 ----- openstack/cdn/v1/flavors/urls.go | 11 - openstack/cdn/v1/serviceassets/doc.go | 7 - openstack/cdn/v1/serviceassets/requests.go | 52 --- openstack/cdn/v1/serviceassets/results.go | 8 - openstack/cdn/v1/serviceassets/testing/doc.go | 2 - .../cdn/v1/serviceassets/testing/fixtures.go | 19 - .../v1/serviceassets/testing/requests_test.go | 19 - openstack/cdn/v1/serviceassets/urls.go | 7 - openstack/cdn/v1/services/doc.go | 7 - openstack/cdn/v1/services/errors.go | 7 - openstack/cdn/v1/services/requests.go | 285 -------------- openstack/cdn/v1/services/results.go | 308 --------------- openstack/cdn/v1/services/testing/doc.go | 2 - openstack/cdn/v1/services/testing/fixtures.go | 372 ------------------ .../cdn/v1/services/testing/requests_test.go | 359 ----------------- openstack/cdn/v1/services/urls.go | 23 -- openstack/client.go | 6 - 30 files changed, 1918 deletions(-) delete mode 100644 openstack/cdn/v1/base/doc.go delete mode 100644 openstack/cdn/v1/base/requests.go delete mode 100644 openstack/cdn/v1/base/results.go delete mode 100644 openstack/cdn/v1/base/testing/doc.go delete mode 100644 openstack/cdn/v1/base/testing/fixtures.go delete mode 100644 openstack/cdn/v1/base/testing/requests_test.go delete mode 100644 openstack/cdn/v1/base/urls.go delete mode 100644 openstack/cdn/v1/flavors/doc.go delete mode 100644 openstack/cdn/v1/flavors/requests.go delete mode 100644 openstack/cdn/v1/flavors/results.go delete mode 100644 openstack/cdn/v1/flavors/testing/doc.go delete mode 100644 openstack/cdn/v1/flavors/testing/fixtures.go delete mode 100644 openstack/cdn/v1/flavors/testing/requests_test.go delete mode 100644 openstack/cdn/v1/flavors/urls.go delete mode 100644 openstack/cdn/v1/serviceassets/doc.go delete mode 100644 openstack/cdn/v1/serviceassets/requests.go delete mode 100644 openstack/cdn/v1/serviceassets/results.go delete mode 100644 openstack/cdn/v1/serviceassets/testing/doc.go delete mode 100644 openstack/cdn/v1/serviceassets/testing/fixtures.go delete mode 100644 openstack/cdn/v1/serviceassets/testing/requests_test.go delete mode 100644 openstack/cdn/v1/serviceassets/urls.go delete mode 100644 openstack/cdn/v1/services/doc.go delete mode 100644 openstack/cdn/v1/services/errors.go delete mode 100644 openstack/cdn/v1/services/requests.go delete mode 100644 openstack/cdn/v1/services/results.go delete mode 100644 openstack/cdn/v1/services/testing/doc.go delete mode 100644 openstack/cdn/v1/services/testing/fixtures.go delete mode 100644 openstack/cdn/v1/services/testing/requests_test.go delete mode 100644 openstack/cdn/v1/services/urls.go diff --git a/openstack/cdn/v1/base/doc.go b/openstack/cdn/v1/base/doc.go deleted file mode 100644 index f78d4f7355..0000000000 --- a/openstack/cdn/v1/base/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package base provides information and interaction with the base API -// resource in the OpenStack CDN service. This API resource allows for -// retrieving the Home Document and pinging the root URL. -package base diff --git a/openstack/cdn/v1/base/requests.go b/openstack/cdn/v1/base/requests.go deleted file mode 100644 index 1bb41e462c..0000000000 --- a/openstack/cdn/v1/base/requests.go +++ /dev/null @@ -1,21 +0,0 @@ -package base - -import "github.com/gophercloud/gophercloud" - -// Get retrieves the home document, allowing the user to discover the -// entire API. -func Get(c *gophercloud.ServiceClient) (r GetResult) { - resp, err := c.Get(getURL(c), &r.Body, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} - -// Ping retrieves a ping to the server. -func Ping(c *gophercloud.ServiceClient) (r PingResult) { - resp, err := c.Get(pingURL(c), nil, &gophercloud.RequestOpts{ - OkCodes: []int{204}, - MoreHeaders: map[string]string{"Accept": ""}, - }) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} diff --git a/openstack/cdn/v1/base/results.go b/openstack/cdn/v1/base/results.go deleted file mode 100644 index 2dfde7dca3..0000000000 --- a/openstack/cdn/v1/base/results.go +++ /dev/null @@ -1,23 +0,0 @@ -package base - -import "github.com/gophercloud/gophercloud" - -// HomeDocument is a resource that contains all the resources for the CDN API. -type HomeDocument map[string]interface{} - -// GetResult represents the result of a Get operation. -type GetResult struct { - gophercloud.Result -} - -// Extract is a function that accepts a result and extracts a home document resource. -func (r GetResult) Extract() (*HomeDocument, error) { - var s HomeDocument - err := r.ExtractInto(&s) - return &s, err -} - -// PingResult represents the result of a Ping operation. -type PingResult struct { - gophercloud.ErrResult -} diff --git a/openstack/cdn/v1/base/testing/doc.go b/openstack/cdn/v1/base/testing/doc.go deleted file mode 100644 index 891c69a215..0000000000 --- a/openstack/cdn/v1/base/testing/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// cdn_base_v1 -package testing diff --git a/openstack/cdn/v1/base/testing/fixtures.go b/openstack/cdn/v1/base/testing/fixtures.go deleted file mode 100644 index f1f4ac0047..0000000000 --- a/openstack/cdn/v1/base/testing/fixtures.go +++ /dev/null @@ -1,53 +0,0 @@ -package testing - -import ( - "fmt" - "net/http" - "testing" - - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -// HandleGetSuccessfully creates an HTTP handler at `/` on the test handler mux -// that responds with a `Get` response. -func HandleGetSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - th.TestHeader(t, r, "Accept", "application/json") - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, ` - { - "resources": { - "rel/cdn": { - "href-template": "services{?marker,limit}", - "href-vars": { - "marker": "param/marker", - "limit": "param/limit" - }, - "hints": { - "allow": [ - "GET" - ], - "formats": { - "application/json": {} - } - } - } - } - } - `) - - }) -} - -// HandlePingSuccessfully creates an HTTP handler at `/ping` on the test handler -// mux that responds with a `Ping` response. -func HandlePingSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - w.WriteHeader(http.StatusNoContent) - }) -} diff --git a/openstack/cdn/v1/base/testing/requests_test.go b/openstack/cdn/v1/base/testing/requests_test.go deleted file mode 100644 index 9c9517e3a0..0000000000 --- a/openstack/cdn/v1/base/testing/requests_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package testing - -import ( - "testing" - - "github.com/gophercloud/gophercloud/openstack/cdn/v1/base" - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -func TestGetHomeDocument(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - HandleGetSuccessfully(t) - - actual, err := base.Get(fake.ServiceClient()).Extract() - th.CheckNoErr(t, err) - - expected := base.HomeDocument{ - "resources": map[string]interface{}{ - "rel/cdn": map[string]interface{}{ - "href-template": "services{?marker,limit}", - "href-vars": map[string]interface{}{ - "marker": "param/marker", - "limit": "param/limit", - }, - "hints": map[string]interface{}{ - "allow": []interface{}{"GET"}, - "formats": map[string]interface{}{ - "application/json": map[string]interface{}{}, - }, - }, - }, - }, - } - th.CheckDeepEquals(t, expected, *actual) -} - -func TestPing(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - HandlePingSuccessfully(t) - - err := base.Ping(fake.ServiceClient()).ExtractErr() - th.CheckNoErr(t, err) -} diff --git a/openstack/cdn/v1/base/urls.go b/openstack/cdn/v1/base/urls.go deleted file mode 100644 index 07d892ba93..0000000000 --- a/openstack/cdn/v1/base/urls.go +++ /dev/null @@ -1,11 +0,0 @@ -package base - -import "github.com/gophercloud/gophercloud" - -func getURL(c *gophercloud.ServiceClient) string { - return c.ServiceURL() -} - -func pingURL(c *gophercloud.ServiceClient) string { - return c.ServiceURL("ping") -} diff --git a/openstack/cdn/v1/flavors/doc.go b/openstack/cdn/v1/flavors/doc.go deleted file mode 100644 index d4066985cb..0000000000 --- a/openstack/cdn/v1/flavors/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package flavors provides information and interaction with the flavors API -// resource in the OpenStack CDN service. This API resource allows for -// listing flavors and retrieving a specific flavor. -// -// A flavor is a mapping configuration to a CDN provider. -package flavors diff --git a/openstack/cdn/v1/flavors/requests.go b/openstack/cdn/v1/flavors/requests.go deleted file mode 100644 index dd16443b18..0000000000 --- a/openstack/cdn/v1/flavors/requests.go +++ /dev/null @@ -1,20 +0,0 @@ -package flavors - -import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/pagination" -) - -// List returns a single page of CDN flavors. -func List(c *gophercloud.ServiceClient) pagination.Pager { - return pagination.NewPager(c, listURL(c), func(r pagination.PageResult) pagination.Page { - return FlavorPage{pagination.SinglePageBase(r)} - }) -} - -// Get retrieves a specific flavor based on its unique ID. -func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { - resp, err := c.Get(getURL(c, id), &r.Body, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} diff --git a/openstack/cdn/v1/flavors/results.go b/openstack/cdn/v1/flavors/results.go deleted file mode 100644 index f7222c75cf..0000000000 --- a/openstack/cdn/v1/flavors/results.go +++ /dev/null @@ -1,64 +0,0 @@ -package flavors - -import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/pagination" -) - -// Provider represents a provider for a particular flavor. -type Provider struct { - // Specifies the name of the provider. The name must not exceed 64 bytes in - // length and is limited to unicode, digits, underscores, and hyphens. - Provider string `json:"provider"` - // Specifies a list with an href where rel is provider_url. - Links []gophercloud.Link `json:"links"` -} - -// Flavor represents a mapping configuration to a CDN provider. -type Flavor struct { - // Specifies the name of the flavor. The name must not exceed 64 bytes in - // length and is limited to unicode, digits, underscores, and hyphens. - ID string `json:"id"` - // Specifies the list of providers mapped to this flavor. - Providers []Provider `json:"providers"` - // Specifies the self-navigating JSON document paths. - Links []gophercloud.Link `json:"links"` -} - -// FlavorPage is the page returned by a pager when traversing over a -// collection of CDN flavors. -type FlavorPage struct { - pagination.SinglePageBase -} - -// IsEmpty returns true if a FlavorPage contains no Flavors. -func (r FlavorPage) IsEmpty() (bool, error) { - if r.StatusCode == 204 { - return true, nil - } - - flavors, err := ExtractFlavors(r) - return len(flavors) == 0, err -} - -// ExtractFlavors extracts and returns Flavors. It is used while iterating over -// a flavors.List call. -func ExtractFlavors(r pagination.Page) ([]Flavor, error) { - var s struct { - Flavors []Flavor `json:"flavors"` - } - err := (r.(FlavorPage)).ExtractInto(&s) - return s.Flavors, err -} - -// GetResult represents the result of a get operation. -type GetResult struct { - gophercloud.Result -} - -// Extract is a function that extracts a flavor from a GetResult. -func (r GetResult) Extract() (*Flavor, error) { - var s *Flavor - err := r.ExtractInto(&s) - return s, err -} diff --git a/openstack/cdn/v1/flavors/testing/doc.go b/openstack/cdn/v1/flavors/testing/doc.go deleted file mode 100644 index 567b67e237..0000000000 --- a/openstack/cdn/v1/flavors/testing/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// cdn_flavors_v1 -package testing diff --git a/openstack/cdn/v1/flavors/testing/fixtures.go b/openstack/cdn/v1/flavors/testing/fixtures.go deleted file mode 100644 index ed97247e2e..0000000000 --- a/openstack/cdn/v1/flavors/testing/fixtures.go +++ /dev/null @@ -1,82 +0,0 @@ -package testing - -import ( - "fmt" - "net/http" - "testing" - - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -// HandleListCDNFlavorsSuccessfully creates an HTTP handler at `/flavors` on the test handler mux -// that responds with a `List` response. -func HandleListCDNFlavorsSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, ` - { - "flavors": [ - { - "id": "europe", - "providers": [ - { - "provider": "Fastly", - "links": [ - { - "href": "http://www.fastly.com", - "rel": "provider_url" - } - ] - } - ], - "links": [ - { - "href": "https://www.poppycdn.io/v1.0/flavors/europe", - "rel": "self" - } - ] - } - ] - } - `) - }) -} - -// HandleGetCDNFlavorSuccessfully creates an HTTP handler at `/flavors/{id}` on the test handler mux -// that responds with a `Get` response. -func HandleGetCDNFlavorSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/flavors/asia", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, ` - { - "id" : "asia", - "providers" : [ - { - "provider" : "ChinaCache", - "links": [ - { - "href": "http://www.chinacache.com", - "rel": "provider_url" - } - ] - } - ], - "links": [ - { - "href": "https://www.poppycdn.io/v1.0/flavors/asia", - "rel": "self" - } - ] - } - `) - }) -} diff --git a/openstack/cdn/v1/flavors/testing/requests_test.go b/openstack/cdn/v1/flavors/testing/requests_test.go deleted file mode 100644 index d84b600a29..0000000000 --- a/openstack/cdn/v1/flavors/testing/requests_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package testing - -import ( - "testing" - - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/cdn/v1/flavors" - "github.com/gophercloud/gophercloud/pagination" - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -func TestList(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleListCDNFlavorsSuccessfully(t) - - count := 0 - - err := flavors.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { - count++ - actual, err := flavors.ExtractFlavors(page) - if err != nil { - t.Errorf("Failed to extract flavors: %v", err) - return false, err - } - - expected := []flavors.Flavor{ - { - ID: "europe", - Providers: []flavors.Provider{ - { - Provider: "Fastly", - Links: []gophercloud.Link{ - { - Href: "http://www.fastly.com", - Rel: "provider_url", - }, - }, - }, - }, - Links: []gophercloud.Link{ - { - Href: "https://www.poppycdn.io/v1.0/flavors/europe", - Rel: "self", - }, - }, - }, - } - - th.CheckDeepEquals(t, expected, actual) - - return true, nil - }) - th.AssertNoErr(t, err) - th.CheckEquals(t, 1, count) -} - -func TestGet(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleGetCDNFlavorSuccessfully(t) - - expected := &flavors.Flavor{ - ID: "asia", - Providers: []flavors.Provider{ - { - Provider: "ChinaCache", - Links: []gophercloud.Link{ - { - Href: "http://www.chinacache.com", - Rel: "provider_url", - }, - }, - }, - }, - Links: []gophercloud.Link{ - { - Href: "https://www.poppycdn.io/v1.0/flavors/asia", - Rel: "self", - }, - }, - } - - actual, err := flavors.Get(fake.ServiceClient(), "asia").Extract() - th.AssertNoErr(t, err) - th.AssertDeepEquals(t, expected, actual) -} diff --git a/openstack/cdn/v1/flavors/urls.go b/openstack/cdn/v1/flavors/urls.go deleted file mode 100644 index a8540a2aed..0000000000 --- a/openstack/cdn/v1/flavors/urls.go +++ /dev/null @@ -1,11 +0,0 @@ -package flavors - -import "github.com/gophercloud/gophercloud" - -func listURL(c *gophercloud.ServiceClient) string { - return c.ServiceURL("flavors") -} - -func getURL(c *gophercloud.ServiceClient, id string) string { - return c.ServiceURL("flavors", id) -} diff --git a/openstack/cdn/v1/serviceassets/doc.go b/openstack/cdn/v1/serviceassets/doc.go deleted file mode 100644 index ceecaa5a5e..0000000000 --- a/openstack/cdn/v1/serviceassets/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -// Package serviceassets provides information and interaction with the -// serviceassets API resource in the OpenStack CDN service. This API resource -// allows for deleting cached assets. -// -// A service distributes assets across the network. Service assets let you -// interrogate properties about these assets and perform certain actions on them. -package serviceassets diff --git a/openstack/cdn/v1/serviceassets/requests.go b/openstack/cdn/v1/serviceassets/requests.go deleted file mode 100644 index 36200ca37b..0000000000 --- a/openstack/cdn/v1/serviceassets/requests.go +++ /dev/null @@ -1,52 +0,0 @@ -package serviceassets - -import ( - "strings" - - "github.com/gophercloud/gophercloud" -) - -// DeleteOptsBuilder allows extensions to add additional parameters to the Delete -// request. -type DeleteOptsBuilder interface { - ToCDNAssetDeleteParams() (string, error) -} - -// DeleteOpts is a structure that holds options for deleting CDN service assets. -type DeleteOpts struct { - // If all is set to true, specifies that the delete occurs against all of the - // assets for the service. - All bool `q:"all"` - // Specifies the relative URL of the asset to be deleted. - URL string `q:"url"` -} - -// ToCDNAssetDeleteParams formats a DeleteOpts into a query string. -func (opts DeleteOpts) ToCDNAssetDeleteParams() (string, error) { - q, err := gophercloud.BuildQueryString(opts) - return q.String(), err -} - -// Delete accepts a unique service ID or URL and deletes the CDN service asset associated with -// it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and -// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" -// are valid options for idOrURL. -func Delete(c *gophercloud.ServiceClient, idOrURL string, opts DeleteOptsBuilder) (r DeleteResult) { - var url string - if strings.Contains(idOrURL, "/") { - url = idOrURL - } else { - url = deleteURL(c, idOrURL) - } - if opts != nil { - q, err := opts.ToCDNAssetDeleteParams() - if err != nil { - r.Err = err - return - } - url += q - } - resp, err := c.Delete(url, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} diff --git a/openstack/cdn/v1/serviceassets/results.go b/openstack/cdn/v1/serviceassets/results.go deleted file mode 100644 index b6114c6893..0000000000 --- a/openstack/cdn/v1/serviceassets/results.go +++ /dev/null @@ -1,8 +0,0 @@ -package serviceassets - -import "github.com/gophercloud/gophercloud" - -// DeleteResult represents the result of a Delete operation. -type DeleteResult struct { - gophercloud.ErrResult -} diff --git a/openstack/cdn/v1/serviceassets/testing/doc.go b/openstack/cdn/v1/serviceassets/testing/doc.go deleted file mode 100644 index 1adb681a28..0000000000 --- a/openstack/cdn/v1/serviceassets/testing/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// cdn_serviceassets_v1 -package testing diff --git a/openstack/cdn/v1/serviceassets/testing/fixtures.go b/openstack/cdn/v1/serviceassets/testing/fixtures.go deleted file mode 100644 index 3172d30fd1..0000000000 --- a/openstack/cdn/v1/serviceassets/testing/fixtures.go +++ /dev/null @@ -1,19 +0,0 @@ -package testing - -import ( - "net/http" - "testing" - - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -// HandleDeleteCDNAssetSuccessfully creates an HTTP handler at `/services/{id}/assets` on the test handler mux -// that responds with a `Delete` response. -func HandleDeleteCDNAssetSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0/assets", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "DELETE") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - w.WriteHeader(http.StatusAccepted) - }) -} diff --git a/openstack/cdn/v1/serviceassets/testing/requests_test.go b/openstack/cdn/v1/serviceassets/testing/requests_test.go deleted file mode 100644 index ff2073bd86..0000000000 --- a/openstack/cdn/v1/serviceassets/testing/requests_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package testing - -import ( - "testing" - - "github.com/gophercloud/gophercloud/openstack/cdn/v1/serviceassets" - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -func TestDelete(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleDeleteCDNAssetSuccessfully(t) - - err := serviceassets.Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", nil).ExtractErr() - th.AssertNoErr(t, err) -} diff --git a/openstack/cdn/v1/serviceassets/urls.go b/openstack/cdn/v1/serviceassets/urls.go deleted file mode 100644 index ce1741826a..0000000000 --- a/openstack/cdn/v1/serviceassets/urls.go +++ /dev/null @@ -1,7 +0,0 @@ -package serviceassets - -import "github.com/gophercloud/gophercloud" - -func deleteURL(c *gophercloud.ServiceClient, id string) string { - return c.ServiceURL("services", id, "assets") -} diff --git a/openstack/cdn/v1/services/doc.go b/openstack/cdn/v1/services/doc.go deleted file mode 100644 index 41f7c60dae..0000000000 --- a/openstack/cdn/v1/services/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -// Package services provides information and interaction with the services API -// resource in the OpenStack CDN service. This API resource allows for -// listing, creating, updating, retrieving, and deleting services. -// -// A service represents an application that has its content cached to the edge -// nodes. -package services diff --git a/openstack/cdn/v1/services/errors.go b/openstack/cdn/v1/services/errors.go deleted file mode 100644 index 359584c2a6..0000000000 --- a/openstack/cdn/v1/services/errors.go +++ /dev/null @@ -1,7 +0,0 @@ -package services - -import "fmt" - -func no(str string) error { - return fmt.Errorf("Required parameter %s not provided", str) -} diff --git a/openstack/cdn/v1/services/requests.go b/openstack/cdn/v1/services/requests.go deleted file mode 100644 index 1ec4810811..0000000000 --- a/openstack/cdn/v1/services/requests.go +++ /dev/null @@ -1,285 +0,0 @@ -package services - -import ( - "fmt" - "strings" - - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/pagination" -) - -// ListOptsBuilder allows extensions to add additional parameters to the -// List request. -type ListOptsBuilder interface { - ToCDNServiceListQuery() (string, error) -} - -// ListOpts allows the filtering and sorting of paginated collections through -// the API. Marker and Limit are used for pagination. -type ListOpts struct { - Marker string `q:"marker"` - Limit int `q:"limit"` -} - -// ToCDNServiceListQuery formats a ListOpts into a query string. -func (opts ListOpts) ToCDNServiceListQuery() (string, error) { - q, err := gophercloud.BuildQueryString(opts) - return q.String(), err -} - -// List returns a Pager which allows you to iterate over a collection of -// CDN services. It accepts a ListOpts struct, which allows for pagination via -// marker and limit. -func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { - url := listURL(c) - if opts != nil { - query, err := opts.ToCDNServiceListQuery() - if err != nil { - return pagination.Pager{Err: err} - } - url += query - } - return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { - p := ServicePage{pagination.MarkerPageBase{PageResult: r}} - p.MarkerPageBase.Owner = p - return p - }) -} - -// CreateOptsBuilder is the interface options structs have to satisfy in order -// to be used in the main Create operation in this package. Since many -// extensions decorate or modify the common logic, it is useful for them to -// satisfy a basic interface in order for them to be used. -type CreateOptsBuilder interface { - ToCDNServiceCreateMap() (map[string]interface{}, error) -} - -// CreateOpts is the common options struct used in this package's Create -// operation. -type CreateOpts struct { - // Specifies the name of the service. The minimum length for name is - // 3. The maximum length is 256. - Name string `json:"name" required:"true"` - // Specifies a list of domains used by users to access their website. - Domains []Domain `json:"domains" required:"true"` - // Specifies a list of origin domains or IP addresses where the - // original assets are stored. - Origins []Origin `json:"origins" required:"true"` - // Specifies the CDN provider flavor ID to use. For a list of - // flavors, see the operation to list the available flavors. The minimum - // length for flavor_id is 1. The maximum length is 256. - FlavorID string `json:"flavor_id" required:"true"` - // Specifies the TTL rules for the assets under this service. Supports wildcards for fine-grained control. - Caching []CacheRule `json:"caching,omitempty"` - // Specifies the restrictions that define who can access assets (content from the CDN cache). - Restrictions []Restriction `json:"restrictions,omitempty"` -} - -// ToCDNServiceCreateMap casts a CreateOpts struct to a map. -func (opts CreateOpts) ToCDNServiceCreateMap() (map[string]interface{}, error) { - return gophercloud.BuildRequestBody(opts, "") -} - -// Create accepts a CreateOpts struct and creates a new CDN service using the -// values provided. -func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToCDNServiceCreateMap() - if err != nil { - r.Err = err - return r - } - resp, err := c.Post(createURL(c), &b, nil, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} - -// Get retrieves a specific service based on its URL or its unique ID. For -// example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and -// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" -// are valid options for idOrURL. -func Get(c *gophercloud.ServiceClient, idOrURL string) (r GetResult) { - var url string - if strings.Contains(idOrURL, "/") { - url = idOrURL - } else { - url = getURL(c, idOrURL) - } - resp, err := c.Get(url, &r.Body, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} - -// Path is a JSON pointer location that indicates which service parameter is being added, replaced, -// or removed. -type Path struct { - baseElement string -} - -func (p Path) renderRoot() string { - return "/" + p.baseElement -} - -func (p Path) renderDash() string { - return fmt.Sprintf("/%s/-", p.baseElement) -} - -func (p Path) renderIndex(index int64) string { - return fmt.Sprintf("/%s/%d", p.baseElement, index) -} - -var ( - // PathDomains indicates that an update operation is to be performed on a Domain. - PathDomains = Path{baseElement: "domains"} - - // PathOrigins indicates that an update operation is to be performed on an Origin. - PathOrigins = Path{baseElement: "origins"} - - // PathCaching indicates that an update operation is to be performed on a CacheRule. - PathCaching = Path{baseElement: "caching"} -) - -type value interface { - toPatchValue() interface{} - appropriatePath() Path - renderRootOr(func(p Path) string) string -} - -// Patch represents a single update to an existing Service. Multiple updates to a service can be -// submitted at the same time. -type Patch interface { - ToCDNServiceUpdateMap() map[string]interface{} -} - -// Insertion is a Patch that requests the addition of a value (Domain, Origin, or CacheRule) to -// a Service at a fixed index. Use an Append instead to append the new value to the end of its -// collection. Pass it to the Update function as part of the Patch slice. -type Insertion struct { - Index int64 - Value value -} - -// ToCDNServiceUpdateMap converts an Insertion into a request body fragment suitable for the -// Update call. -func (opts Insertion) ToCDNServiceUpdateMap() map[string]interface{} { - return map[string]interface{}{ - "op": "add", - "path": opts.Value.renderRootOr(func(p Path) string { return p.renderIndex(opts.Index) }), - "value": opts.Value.toPatchValue(), - } -} - -// Append is a Patch that requests the addition of a value (Domain, Origin, or CacheRule) to a -// Service at the end of its respective collection. Use an Insertion instead to insert the value -// at a fixed index within the collection. Pass this to the Update function as part of its -// Patch slice. -type Append struct { - Value value -} - -// ToCDNServiceUpdateMap converts an Append into a request body fragment suitable for the -// Update call. -func (a Append) ToCDNServiceUpdateMap() map[string]interface{} { - return map[string]interface{}{ - "op": "add", - "path": a.Value.renderRootOr(func(p Path) string { return p.renderDash() }), - "value": a.Value.toPatchValue(), - } -} - -// Replacement is a Patch that alters a specific service parameter (Domain, Origin, or CacheRule) -// in-place by index. Pass it to the Update function as part of the Patch slice. -type Replacement struct { - Value value - Index int64 -} - -// ToCDNServiceUpdateMap converts a Replacement into a request body fragment suitable for the -// Update call. -func (r Replacement) ToCDNServiceUpdateMap() map[string]interface{} { - return map[string]interface{}{ - "op": "replace", - "path": r.Value.renderRootOr(func(p Path) string { return p.renderIndex(r.Index) }), - "value": r.Value.toPatchValue(), - } -} - -// 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 (opts Removal) ToCDNServiceUpdateMap() map[string]interface{} { - b := map[string]interface{}{"op": "remove"} - if opts.All { - b["path"] = opts.Path.renderRoot() - } else { - b["path"] = opts.Path.renderIndex(opts.Index) - } - return b -} - -// UpdateOpts is a slice of Patches used to update a CDN service -type UpdateOpts []Patch - -// Update accepts a slice of Patch operations (Insertion, Append, Replacement or Removal) and -// updates an existing CDN service using the values provided. idOrURL can be either the service's -// URL or its ID. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and -// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" -// are valid options for idOrURL. -func Update(c *gophercloud.ServiceClient, idOrURL string, opts UpdateOpts) (r UpdateResult) { - var url string - if strings.Contains(idOrURL, "/") { - url = idOrURL - } else { - url = updateURL(c, idOrURL) - } - - b := make([]map[string]interface{}, len(opts)) - for i, patch := range opts { - b[i] = patch.ToCDNServiceUpdateMap() - } - - resp, err := c.Request("PATCH", url, &gophercloud.RequestOpts{ - JSONBody: &b, - OkCodes: []int{202}, - }) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} - -// Delete accepts a service's ID or its URL and deletes the CDN service -// associated with it. For example, both "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" and -// "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" -// are valid options for idOrURL. -func Delete(c *gophercloud.ServiceClient, idOrURL string) (r DeleteResult) { - var url string - if strings.Contains(idOrURL, "/") { - url = idOrURL - } else { - url = deleteURL(c, idOrURL) - } - resp, err := c.Delete(url, nil) - _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) - return -} diff --git a/openstack/cdn/v1/services/results.go b/openstack/cdn/v1/services/results.go deleted file mode 100644 index fd77f192f8..0000000000 --- a/openstack/cdn/v1/services/results.go +++ /dev/null @@ -1,308 +0,0 @@ -package services - -import ( - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/pagination" -) - -// Domain represents a domain used by users to access their website. -type Domain struct { - // Specifies the domain used to access the assets on their website, for which - // a CNAME is given to the CDN provider. - Domain string `json:"domain" required:"true"` - // Specifies the protocol used to access the assets on this domain. Only "http" - // or "https" are currently allowed. The default is "http". - Protocol string `json:"protocol,omitempty"` -} - -func (d Domain) toPatchValue() interface{} { - r := make(map[string]interface{}) - r["domain"] = d.Domain - if d.Protocol != "" { - r["protocol"] = d.Protocol - } - return r -} - -func (d Domain) appropriatePath() Path { - return PathDomains -} - -func (d Domain) renderRootOr(render func(p Path) string) string { - return render(d.appropriatePath()) -} - -// DomainList provides a useful way to perform bulk operations in a single Patch. -type DomainList []Domain - -func (list DomainList) toPatchValue() interface{} { - r := make([]interface{}, len(list)) - for i, domain := range list { - r[i] = domain.toPatchValue() - } - return r -} - -func (list DomainList) appropriatePath() Path { - return PathDomains -} - -func (list DomainList) renderRootOr(_ func(p Path) string) string { - return list.appropriatePath().renderRoot() -} - -// OriginRule represents a rule that defines when an origin should be accessed. -type OriginRule struct { - // Specifies the name of this rule. - Name string `json:"name" required:"true"` - // Specifies the request URL this rule should match for this origin to be used. Regex is supported. - RequestURL string `json:"request_url" required:"true"` -} - -// Origin specifies a list of origin domains or IP addresses where the original assets are stored. -type Origin struct { - // Specifies the URL or IP address to pull origin content from. - Origin string `json:"origin" required:"true"` - // Specifies the port used to access the origin. The default is port 80. - Port int `json:"port,omitempty"` - // Specifies whether or not to use HTTPS to access the origin. The default - // is false. - SSL bool `json:"ssl"` - // Specifies a collection of rules that define the conditions when this origin - // should be accessed. If there is more than one origin, the rules parameter is required. - Rules []OriginRule `json:"rules,omitempty"` -} - -func (o Origin) toPatchValue() interface{} { - r := make(map[string]interface{}) - r["origin"] = o.Origin - r["port"] = o.Port - r["ssl"] = o.SSL - if len(o.Rules) > 0 { - r["rules"] = make([]map[string]interface{}, len(o.Rules)) - for index, rule := range o.Rules { - submap := r["rules"].([]map[string]interface{})[index] - submap["name"] = rule.Name - submap["request_url"] = rule.RequestURL - } - } - return r -} - -func (o Origin) appropriatePath() Path { - return PathOrigins -} - -func (o Origin) renderRootOr(render func(p Path) string) string { - return render(o.appropriatePath()) -} - -// OriginList provides a useful way to perform bulk operations in a single Patch. -type OriginList []Origin - -func (list OriginList) toPatchValue() interface{} { - r := make([]interface{}, len(list)) - for i, origin := range list { - r[i] = origin.toPatchValue() - } - return r -} - -func (list OriginList) appropriatePath() Path { - return PathOrigins -} - -func (list OriginList) renderRootOr(_ func(p Path) string) string { - return list.appropriatePath().renderRoot() -} - -// TTLRule specifies a rule that determines if a TTL should be applied to an asset. -type TTLRule struct { - // Specifies the name of this rule. - Name string `json:"name" required:"true"` - // Specifies the request URL this rule should match for this TTL to be used. Regex is supported. - RequestURL string `json:"request_url" required:"true"` -} - -// CacheRule specifies the TTL rules for the assets under this service. -type CacheRule struct { - // Specifies the name of this caching rule. Note: 'default' is a reserved name used for the default TTL setting. - Name string `json:"name" required:"true"` - // Specifies the TTL to apply. - TTL int `json:"ttl,omitempty"` - // Specifies a collection of rules that determine if this TTL should be applied to an asset. - Rules []TTLRule `json:"rules,omitempty"` -} - -func (c CacheRule) toPatchValue() interface{} { - r := make(map[string]interface{}) - r["name"] = c.Name - r["ttl"] = c.TTL - r["rules"] = make([]map[string]interface{}, len(c.Rules)) - for index, rule := range c.Rules { - submap := r["rules"].([]map[string]interface{})[index] - submap["name"] = rule.Name - submap["request_url"] = rule.RequestURL - } - return r -} - -func (c CacheRule) appropriatePath() Path { - return PathCaching -} - -func (c CacheRule) renderRootOr(render func(p Path) string) string { - return render(c.appropriatePath()) -} - -// CacheRuleList provides a useful way to perform bulk operations in a single Patch. -type CacheRuleList []CacheRule - -func (list CacheRuleList) toPatchValue() interface{} { - r := make([]interface{}, len(list)) - for i, rule := range list { - r[i] = rule.toPatchValue() - } - return r -} - -func (list CacheRuleList) appropriatePath() Path { - return PathCaching -} - -func (list CacheRuleList) renderRootOr(_ func(p Path) string) string { - return list.appropriatePath().renderRoot() -} - -// RestrictionRule specifies a rule that determines if this restriction should be applied to an asset. -type RestrictionRule struct { - // Specifies the name of this rule. - Name string `json:"name" required:"true"` - // Specifies the http host that requests must come from. - Referrer string `json:"referrer,omitempty"` -} - -// Restriction specifies a restriction that defines who can access assets (content from the CDN cache). -type Restriction struct { - // Specifies the name of this restriction. - Name string `json:"name" required:"true"` - // Specifies a collection of rules that determine if this TTL should be applied to an asset. - Rules []RestrictionRule `json:"rules,omitempty"` -} - -// Error specifies an error that occurred during the previous service action. -type Error struct { - // Specifies an error message detailing why there is an error. - Message string `json:"message"` -} - -// Service represents a CDN service resource. -type Service struct { - // Specifies the service ID that represents distributed content. The value is - // a UUID, such as 96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0, that is generated by the server. - ID string `json:"id"` - // Specifies the name of the service. - Name string `json:"name"` - // Specifies a list of domains used by users to access their website. - Domains []Domain `json:"domains"` - // Specifies a list of origin domains or IP addresses where the original assets are stored. - Origins []Origin `json:"origins"` - // Specifies the TTL rules for the assets under this service. Supports wildcards for fine grained control. - Caching []CacheRule `json:"caching"` - // Specifies the restrictions that define who can access assets (content from the CDN cache). - Restrictions []Restriction `json:"restrictions"` - // Specifies the CDN provider flavor ID to use. For a list of flavors, see the operation to list the available flavors. - FlavorID string `json:"flavor_id"` - // Specifies the current status of the service. - Status string `json:"status"` - // Specifies the list of errors that occurred during the previous service action. - Errors []Error `json:"errors"` - // Specifies the self-navigating JSON document paths. - Links []gophercloud.Link `json:"links"` -} - -// ServicePage is the page returned by a pager when traversing over a -// collection of CDN services. -type ServicePage struct { - pagination.MarkerPageBase -} - -// IsEmpty returns true if a ListResult contains no services. -func (r ServicePage) IsEmpty() (bool, error) { - if r.StatusCode == 204 { - return true, nil - } - - services, err := ExtractServices(r) - return len(services) == 0, err -} - -// LastMarker returns the last service in a ListResult. -func (r ServicePage) LastMarker() (string, error) { - services, err := ExtractServices(r) - if err != nil { - return "", err - } - if len(services) == 0 { - return "", nil - } - return (services[len(services)-1]).ID, nil -} - -// ExtractServices is a function that takes a ListResult and returns the services' information. -func ExtractServices(r pagination.Page) ([]Service, error) { - var s struct { - Services []Service `json:"services"` - } - err := (r.(ServicePage)).ExtractInto(&s) - return s.Services, err -} - -// CreateResult represents the result of a Create operation. -type CreateResult struct { - gophercloud.Result -} - -// Extract is a method that extracts the location of a newly created service. -func (r CreateResult) Extract() (string, error) { - if r.Err != nil { - return "", r.Err - } - if l, ok := r.Header["Location"]; ok && len(l) > 0 { - return l[0], nil - } - return "", nil -} - -// GetResult represents the result of a get operation. -type GetResult struct { - gophercloud.Result -} - -// Extract is a function that extracts a service from a GetResult. -func (r GetResult) Extract() (*Service, error) { - var s Service - err := r.ExtractInto(&s) - return &s, err -} - -// UpdateResult represents the result of a Update operation. -type UpdateResult struct { - gophercloud.Result -} - -// Extract is a method that extracts the location of an updated service. -func (r UpdateResult) Extract() (string, error) { - if r.Err != nil { - return "", r.Err - } - if l, ok := r.Header["Location"]; ok && len(l) > 0 { - return l[0], nil - } - return "", nil -} - -// DeleteResult represents the result of a Delete operation. -type DeleteResult struct { - gophercloud.ErrResult -} diff --git a/openstack/cdn/v1/services/testing/doc.go b/openstack/cdn/v1/services/testing/doc.go deleted file mode 100644 index c72e391afe..0000000000 --- a/openstack/cdn/v1/services/testing/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// cdn_services_v1 -package testing diff --git a/openstack/cdn/v1/services/testing/fixtures.go b/openstack/cdn/v1/services/testing/fixtures.go deleted file mode 100644 index d4093e0515..0000000000 --- a/openstack/cdn/v1/services/testing/fixtures.go +++ /dev/null @@ -1,372 +0,0 @@ -package testing - -import ( - "fmt" - "net/http" - "testing" - - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -// HandleListCDNServiceSuccessfully creates an HTTP handler at `/services` on the test handler mux -// that responds with a `List` response. -func HandleListCDNServiceSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - - r.ParseForm() - marker := r.Form.Get("marker") - switch marker { - case "": - fmt.Fprintf(w, ` - { - "links": [ - { - "rel": "next", - "href": "https://www.poppycdn.io/v1.0/services?marker=96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0&limit=20" - } - ], - "services": [ - { - "id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - "name": "mywebsite.com", - "domains": [ - { - "domain": "www.mywebsite.com" - } - ], - "origins": [ - { - "origin": "mywebsite.com", - "port": 80, - "ssl": false - } - ], - "caching": [ - { - "name": "default", - "ttl": 3600 - }, - { - "name": "home", - "ttl": 17200, - "rules": [ - { - "name": "index", - "request_url": "/index.htm" - } - ] - }, - { - "name": "images", - "ttl": 12800, - "rules": [ - { - "name": "images", - "request_url": "*.png" - } - ] - } - ], - "restrictions": [ - { - "name": "website only", - "rules": [ - { - "name": "mywebsite.com", - "referrer": "www.mywebsite.com" - } - ] - } - ], - "flavor_id": "asia", - "status": "deployed", - "errors" : [], - "links": [ - { - "href": "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - "rel": "self" - }, - { - "href": "mywebsite.com.cdn123.poppycdn.net", - "rel": "access_url" - }, - { - "href": "https://www.poppycdn.io/v1.0/flavors/asia", - "rel": "flavor" - } - ] - }, - { - "id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", - "name": "myothersite.com", - "domains": [ - { - "domain": "www.myothersite.com" - } - ], - "origins": [ - { - "origin": "44.33.22.11", - "port": 80, - "ssl": false - }, - { - "origin": "77.66.55.44", - "port": 80, - "ssl": false, - "rules": [ - { - "name": "videos", - "request_url": "^/videos/*.m3u" - } - ] - } - ], - "caching": [ - { - "name": "default", - "ttl": 3600 - } - ], - "restrictions": [ - {} - ], - "flavor_id": "europe", - "status": "deployed", - "links": [ - { - "href": "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", - "rel": "self" - }, - { - "href": "myothersite.com.poppycdn.net", - "rel": "access_url" - }, - { - "href": "https://www.poppycdn.io/v1.0/flavors/europe", - "rel": "flavor" - } - ] - } - ] - } - `) - case "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1": - fmt.Fprintf(w, `{ - "services": [] - }`) - default: - t.Fatalf("Unexpected marker: [%s]", marker) - } - }) -} - -// HandleCreateCDNServiceSuccessfully creates an HTTP handler at `/services` on the test handler mux -// that responds with a `Create` response. -func HandleCreateCDNServiceSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "POST") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - th.TestJSONRequest(t, r, ` - { - "name": "mywebsite.com", - "domains": [ - { - "domain": "www.mywebsite.com" - }, - { - "domain": "blog.mywebsite.com" - } - ], - "origins": [ - { - "origin": "mywebsite.com", - "port": 80, - "ssl": false - } - ], - "restrictions": [ - { - "name": "website only", - "rules": [ - { - "name": "mywebsite.com", - "referrer": "www.mywebsite.com" - } - ] - } - ], - "caching": [ - { - "name": "default", - "ttl": 3600 - } - ], - - "flavor_id": "cdn" - } - `) - w.Header().Add("Location", "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0") - w.WriteHeader(http.StatusAccepted) - }) -} - -// HandleGetCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux -// that responds with a `Get` response. -func HandleGetCDNServiceSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "GET") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - fmt.Fprintf(w, ` - { - "id": "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - "name": "mywebsite.com", - "domains": [ - { - "domain": "www.mywebsite.com", - "protocol": "http" - } - ], - "origins": [ - { - "origin": "mywebsite.com", - "port": 80, - "ssl": false - } - ], - "caching": [ - { - "name": "default", - "ttl": 3600 - }, - { - "name": "home", - "ttl": 17200, - "rules": [ - { - "name": "index", - "request_url": "/index.htm" - } - ] - }, - { - "name": "images", - "ttl": 12800, - "rules": [ - { - "name": "images", - "request_url": "*.png" - } - ] - } - ], - "restrictions": [ - { - "name": "website only", - "rules": [ - { - "name": "mywebsite.com", - "referrer": "www.mywebsite.com" - } - ] - } - ], - "flavor_id": "cdn", - "status": "deployed", - "errors" : [], - "links": [ - { - "href": "https://global.cdn.api.rackspacecloud.com/v1.0/110011/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - "rel": "self" - }, - { - "href": "blog.mywebsite.com.cdn1.raxcdn.com", - "rel": "access_url" - }, - { - "href": "https://global.cdn.api.rackspacecloud.com/v1.0/110011/flavors/cdn", - "rel": "flavor" - } - ] - } - `) - }) -} - -// HandleUpdateCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux -// that responds with a `Update` response. -func HandleUpdateCDNServiceSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "PATCH") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - th.TestJSONRequest(t, r, ` - [ - { - "op": "add", - "path": "/domains/-", - "value": {"domain": "appended.mocksite4.com"} - }, - { - "op": "add", - "path": "/domains/4", - "value": {"domain": "inserted.mocksite4.com"} - }, - { - "op": "add", - "path": "/domains", - "value": [ - {"domain": "bulkadded1.mocksite4.com"}, - {"domain": "bulkadded2.mocksite4.com"} - ] - }, - { - "op": "replace", - "path": "/origins/2", - "value": {"origin": "44.33.22.11", "port": 80, "ssl": false} - }, - { - "op": "replace", - "path": "/origins", - "value": [ - {"origin": "44.33.22.11", "port": 80, "ssl": false}, - {"origin": "55.44.33.22", "port": 443, "ssl": true} - ] - }, - { - "op": "remove", - "path": "/caching/8" - }, - { - "op": "remove", - "path": "/caching" - }, - { - "op": "replace", - "path": "/name", - "value": "differentServiceName" - } - ] - `) - w.Header().Add("Location", "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0") - w.WriteHeader(http.StatusAccepted) - }) -} - -// HandleDeleteCDNServiceSuccessfully creates an HTTP handler at `/services/{id}` on the test handler mux -// that responds with a `Delete` response. -func HandleDeleteCDNServiceSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", func(w http.ResponseWriter, r *http.Request) { - th.TestMethod(t, r, "DELETE") - th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) - w.WriteHeader(http.StatusAccepted) - }) -} diff --git a/openstack/cdn/v1/services/testing/requests_test.go b/openstack/cdn/v1/services/testing/requests_test.go deleted file mode 100644 index 52854163af..0000000000 --- a/openstack/cdn/v1/services/testing/requests_test.go +++ /dev/null @@ -1,359 +0,0 @@ -package testing - -import ( - "testing" - - "github.com/gophercloud/gophercloud" - "github.com/gophercloud/gophercloud/openstack/cdn/v1/services" - "github.com/gophercloud/gophercloud/pagination" - th "github.com/gophercloud/gophercloud/testhelper" - fake "github.com/gophercloud/gophercloud/testhelper/client" -) - -func TestList(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleListCDNServiceSuccessfully(t) - - count := 0 - - err := services.List(fake.ServiceClient(), &services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { - count++ - actual, err := services.ExtractServices(page) - if err != nil { - t.Errorf("Failed to extract services: %v", err) - return false, err - } - - expected := []services.Service{ - { - ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - Name: "mywebsite.com", - Domains: []services.Domain{ - { - Domain: "www.mywebsite.com", - }, - }, - Origins: []services.Origin{ - { - Origin: "mywebsite.com", - Port: 80, - SSL: false, - }, - }, - Caching: []services.CacheRule{ - { - Name: "default", - TTL: 3600, - }, - { - Name: "home", - TTL: 17200, - Rules: []services.TTLRule{ - { - Name: "index", - RequestURL: "/index.htm", - }, - }, - }, - { - Name: "images", - TTL: 12800, - Rules: []services.TTLRule{ - { - Name: "images", - RequestURL: "*.png", - }, - }, - }, - }, - Restrictions: []services.Restriction{ - { - Name: "website only", - Rules: []services.RestrictionRule{ - { - Name: "mywebsite.com", - Referrer: "www.mywebsite.com", - }, - }, - }, - }, - FlavorID: "asia", - Status: "deployed", - Errors: []services.Error{}, - Links: []gophercloud.Link{ - { - Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - Rel: "self", - }, - { - Href: "mywebsite.com.cdn123.poppycdn.net", - Rel: "access_url", - }, - { - Href: "https://www.poppycdn.io/v1.0/flavors/asia", - Rel: "flavor", - }, - }, - }, - { - ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", - Name: "myothersite.com", - Domains: []services.Domain{ - { - Domain: "www.myothersite.com", - }, - }, - Origins: []services.Origin{ - { - Origin: "44.33.22.11", - Port: 80, - SSL: false, - }, - { - Origin: "77.66.55.44", - Port: 80, - SSL: false, - Rules: []services.OriginRule{ - { - Name: "videos", - RequestURL: "^/videos/*.m3u", - }, - }, - }, - }, - Caching: []services.CacheRule{ - { - Name: "default", - TTL: 3600, - }, - }, - Restrictions: []services.Restriction{}, - FlavorID: "europe", - Status: "deployed", - Links: []gophercloud.Link{ - { - Href: "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f1", - Rel: "self", - }, - { - Href: "myothersite.com.poppycdn.net", - Rel: "access_url", - }, - { - Href: "https://www.poppycdn.io/v1.0/flavors/europe", - Rel: "flavor", - }, - }, - }, - } - - th.CheckDeepEquals(t, expected, actual) - - return true, nil - }) - th.AssertNoErr(t, err) - - if count != 1 { - t.Errorf("Expected 1 page, got %d", count) - } -} - -func TestCreate(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleCreateCDNServiceSuccessfully(t) - - createOpts := services.CreateOpts{ - Name: "mywebsite.com", - Domains: []services.Domain{ - { - Domain: "www.mywebsite.com", - }, - { - Domain: "blog.mywebsite.com", - }, - }, - Origins: []services.Origin{ - { - Origin: "mywebsite.com", - Port: 80, - SSL: false, - }, - }, - Restrictions: []services.Restriction{ - { - Name: "website only", - Rules: []services.RestrictionRule{ - { - Name: "mywebsite.com", - Referrer: "www.mywebsite.com", - }, - }, - }, - }, - Caching: []services.CacheRule{ - { - Name: "default", - TTL: 3600, - }, - }, - FlavorID: "cdn", - } - - expected := "https://global.cdn.api.rackspacecloud.com/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" - actual, err := services.Create(fake.ServiceClient(), createOpts).Extract() - th.AssertNoErr(t, err) - th.AssertEquals(t, expected, actual) -} - -func TestGet(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleGetCDNServiceSuccessfully(t) - - expected := &services.Service{ - ID: "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - Name: "mywebsite.com", - Domains: []services.Domain{ - { - Domain: "www.mywebsite.com", - Protocol: "http", - }, - }, - Origins: []services.Origin{ - { - Origin: "mywebsite.com", - Port: 80, - SSL: false, - }, - }, - Caching: []services.CacheRule{ - { - Name: "default", - TTL: 3600, - }, - { - Name: "home", - TTL: 17200, - Rules: []services.TTLRule{ - { - Name: "index", - RequestURL: "/index.htm", - }, - }, - }, - { - Name: "images", - TTL: 12800, - Rules: []services.TTLRule{ - { - Name: "images", - RequestURL: "*.png", - }, - }, - }, - }, - Restrictions: []services.Restriction{ - { - Name: "website only", - Rules: []services.RestrictionRule{ - { - Name: "mywebsite.com", - Referrer: "www.mywebsite.com", - }, - }, - }, - }, - FlavorID: "cdn", - Status: "deployed", - Errors: []services.Error{}, - Links: []gophercloud.Link{ - { - Href: "https://global.cdn.api.rackspacecloud.com/v1.0/110011/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", - Rel: "self", - }, - { - Href: "blog.mywebsite.com.cdn1.raxcdn.com", - Rel: "access_url", - }, - { - Href: "https://global.cdn.api.rackspacecloud.com/v1.0/110011/flavors/cdn", - Rel: "flavor", - }, - }, - } - - actual, err := services.Get(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0").Extract() - th.AssertNoErr(t, err) - th.AssertDeepEquals(t, expected, actual) -} - -func TestSuccessfulUpdate(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleUpdateCDNServiceSuccessfully(t) - - expected := "https://www.poppycdn.io/v1.0/services/96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0" - ops := services.UpdateOpts{ - // Append a single Domain - services.Append{Value: services.Domain{Domain: "appended.mocksite4.com"}}, - // Insert a single Domain - services.Insertion{ - Index: 4, - Value: services.Domain{Domain: "inserted.mocksite4.com"}, - }, - // Bulk addition - services.Append{ - Value: services.DomainList{ - {Domain: "bulkadded1.mocksite4.com"}, - {Domain: "bulkadded2.mocksite4.com"}, - }, - }, - // Replace a single Origin - services.Replacement{ - Index: 2, - Value: services.Origin{Origin: "44.33.22.11", Port: 80, SSL: false}, - }, - // Bulk replace Origins - services.Replacement{ - Index: 0, // Ignored - Value: services.OriginList{ - {Origin: "44.33.22.11", Port: 80, SSL: false}, - {Origin: "55.44.33.22", Port: 443, SSL: true}, - }, - }, - // Remove a single CacheRule - services.Removal{ - Index: 8, - Path: services.PathCaching, - }, - // Bulk removal - services.Removal{ - All: true, - Path: services.PathCaching, - }, - // Service name replacement - services.NameReplacement{ - NewName: "differentServiceName", - }, - } - - actual, err := services.Update(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0", ops).Extract() - th.AssertNoErr(t, err) - th.AssertEquals(t, expected, actual) -} - -func TestDelete(t *testing.T) { - th.SetupHTTP() - defer th.TeardownHTTP() - - HandleDeleteCDNServiceSuccessfully(t) - - err := services.Delete(fake.ServiceClient(), "96737ae3-cfc1-4c72-be88-5d0e7cc9a3f0").ExtractErr() - th.AssertNoErr(t, err) -} diff --git a/openstack/cdn/v1/services/urls.go b/openstack/cdn/v1/services/urls.go deleted file mode 100644 index 5bb3ca9d92..0000000000 --- a/openstack/cdn/v1/services/urls.go +++ /dev/null @@ -1,23 +0,0 @@ -package services - -import "github.com/gophercloud/gophercloud" - -func listURL(c *gophercloud.ServiceClient) string { - return c.ServiceURL("services") -} - -func createURL(c *gophercloud.ServiceClient) string { - return listURL(c) -} - -func getURL(c *gophercloud.ServiceClient, id string) string { - return c.ServiceURL("services", id) -} - -func updateURL(c *gophercloud.ServiceClient, id string) string { - return getURL(c, id) -} - -func deleteURL(c *gophercloud.ServiceClient, id string) string { - return getURL(c, id) -} diff --git a/openstack/client.go b/openstack/client.go index 87cd90f38e..8786189edf 100644 --- a/openstack/client.go +++ b/openstack/client.go @@ -418,12 +418,6 @@ func NewSharedFileSystemV2(client *gophercloud.ProviderClient, eo gophercloud.En return initClientOpts(client, eo, "sharev2") } -// NewCDNV1 creates a ServiceClient that may be used to access the OpenStack v1 -// CDN service. -func NewCDNV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { - return initClientOpts(client, eo, "cdn") -} - // NewOrchestrationV1 creates a ServiceClient that may be used to access the v1 // orchestration service. func NewOrchestrationV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {