Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,47 @@ package certificates

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToCertificateListQuery() (string, error)
}

type ListOpts struct {
ID string `q:"id"`
Name string `q:"name"`
Description string `q:"description"`
Type string `q:"type"`
Domain string `q:"domain"`
PrivateKey string `q:"private_key"`
Certificate string `q:"certificate"`
Limit int `q:"limit"`
Marker string `q:"marker"`
}

// ToCertificateListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToCertificateListQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
return q.String(), err
}

func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := rootURL(c)
if opts != nil {
query, err := opts.ToCertificateListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
return CertificatePage{pagination.SinglePageBase(r)}
})
}

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package certificates

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

type Certificate struct {
Expand All @@ -16,6 +17,23 @@ type Certificate struct {
UpdateTime string `json:"update_time"`
}

// CertificatePage is the page returned by a pager when traversing over a
// collection of certificates.
type CertificatePage struct {
pagination.SinglePageBase
}

// ExtractCertificates accepts a Page struct, specifically a CertificatePage struct,
// and extracts the elements into a slice of Certificate structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractCertificates(r pagination.Page) ([]Certificate, error) {
var s struct {
Certificates []Certificate `json:"certificates"`
}
err := (r.(CertificatePage)).ExtractInto(&s)
return s.Certificates, err
}

type commonResult struct {
golangsdk.Result
}
Expand Down