From 32997dfae18a02e1d3359dad27bf247422842e30 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 28 Sep 2018 16:03:10 +0800 Subject: [PATCH] Add lbaas certificate support --- .../lbaas_v2/certificates/requests.go | 94 +++++++++++++++++++ .../lbaas_v2/certificates/results.go | 44 +++++++++ .../extensions/lbaas_v2/certificates/urls.go | 16 ++++ 3 files changed, 154 insertions(+) create mode 100644 openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go create mode 100644 openstack/networking/v2/extensions/lbaas_v2/certificates/results.go create mode 100644 openstack/networking/v2/extensions/lbaas_v2/certificates/urls.go diff --git a/openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go b/openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go new file mode 100644 index 000000000..068fadf3f --- /dev/null +++ b/openstack/networking/v2/extensions/lbaas_v2/certificates/requests.go @@ -0,0 +1,94 @@ +package certificates + +import ( + "github.com/huaweicloud/golangsdk" +) + +// 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 { + ToCertificateCreateMap() (map[string]interface{}, error) +} + +// CreateOpts is the common options struct used in this package's Create +// operation. +type CreateOpts struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` + Domain string `json:"domain,omitempty"` + PrivateKey string `json:"private_key" required:"true"` + Certificate string `json:"certificate" required:"true"` +} + +// ToCertificateCreateMap casts a CreateOpts struct to a map. +func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +// Create is an operation which provisions a new loadbalancer based on the +// configuration defined in the CreateOpts struct. Once the request is +// validated and progress has started on the provisioning process, a +// CreateResult will be returned. +// +// Users with an admin role can create loadbalancers on behalf of other tenants by +// specifying a TenantID attribute different than their own. +func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToCertificateCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) + return +} + +// Get retrieves a particular Loadbalancer based on its unique ID. +func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { + _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder is the interface options structs have to satisfy in order +// to be used in the main Update 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 UpdateOptsBuilder interface { + ToCertificateUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts is the common options struct used in this package's Update +// operation. +type UpdateOpts struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Domain string `json:"domain,omitempty"` + PrivateKey string `json:"private_key,omitempty"` + Certificate string `json:"certificate,omitempty"` +} + +// ToCertificateUpdateMap casts a UpdateOpts struct to a map. +func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) { + return golangsdk.BuildRequestBody(opts, "") +} + +// Update is an operation which modifies the attributes of the specified Certificate. +func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { + b, err := opts.ToCertificateUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Delete will permanently delete a particular Certificate based on its unique ID. +func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { + _, r.Err = c.Delete(resourceURL(c, id), nil) + return +} diff --git a/openstack/networking/v2/extensions/lbaas_v2/certificates/results.go b/openstack/networking/v2/extensions/lbaas_v2/certificates/results.go new file mode 100644 index 000000000..949fd93d8 --- /dev/null +++ b/openstack/networking/v2/extensions/lbaas_v2/certificates/results.go @@ -0,0 +1,44 @@ +package certificates + +import ( + "github.com/huaweicloud/golangsdk" +) + +type Certificate struct { + ID string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Type string `json:"type"` + Domain string `json:"domain"` + PrivateKey string `json:"private_key"` + Certificate string `json:"certificate"` + CreateTime string `json:"create_time"` + UpdateTime string `json:"update_time"` +} + +type commonResult struct { + golangsdk.Result +} + +func (r commonResult) Extract() (*Certificate, error) { + s := &Certificate{} + return s, r.ExtractInto(s) +} + +type CreateResult struct { + commonResult +} + +// GetResult represents the result of a get operation. +type GetResult struct { + commonResult +} + +type UpdateResult struct { + commonResult +} + +// DeleteResult represents the result of a delete operation. +type DeleteResult struct { + golangsdk.ErrResult +} diff --git a/openstack/networking/v2/extensions/lbaas_v2/certificates/urls.go b/openstack/networking/v2/extensions/lbaas_v2/certificates/urls.go new file mode 100644 index 000000000..bbf4b343e --- /dev/null +++ b/openstack/networking/v2/extensions/lbaas_v2/certificates/urls.go @@ -0,0 +1,16 @@ +package certificates + +import "github.com/huaweicloud/golangsdk" + +const ( + rootPath = "lbaas" + resourcePath = "certificates" +) + +func rootURL(c *golangsdk.ServiceClient) string { + return c.ServiceURL(rootPath, resourcePath) +} + +func resourceURL(c *golangsdk.ServiceClient, id string) string { + return c.ServiceURL(rootPath, resourcePath, id) +}