Skip to content

Commit

Permalink
IF-9051 Support MLB in v3 (#45)
Browse files Browse the repository at this point in the history
* IF-9051 Support MLB in v3

* IF-9051 Add function ManagedLoadBalancer in v3
  • Loading branch information
ikegami-shota authored Feb 19, 2024
1 parent d0fe8cf commit d244572
Show file tree
Hide file tree
Showing 85 changed files with 13,963 additions and 0 deletions.
8 changes: 8 additions & 0 deletions v3/ecl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ func NewLoadBalancerV2(client *eclcloud.ProviderClient, eo eclcloud.EndpointOpts
return sc, err
}

// NewManagedLoadBalancerV1 creates a ServiceClient that may be used to access the v1
// managed load balancer service.
func NewManagedLoadBalancerV1(client *eclcloud.ProviderClient, eo eclcloud.EndpointOpts) (*eclcloud.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "managed-load-balancer")
sc.ResourceBase = sc.Endpoint + "v1.0/"
return sc, err
}

// NewClusteringV1 creates a ServiceClient that may be used with the v1 clustering
// package.
func NewClusteringV1(client *eclcloud.ProviderClient, eo eclcloud.EndpointOpts) (*eclcloud.ServiceClient, error) {
Expand Down
106 changes: 106 additions & 0 deletions v3/ecl/managed_load_balancer/v1/certificates/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Generated by https://github.com/tamac-io/openapi-to-eclcloud-rb
Package certificates contains functionality for working with ECL Managed Load Balancer resources.
Example to list certificates
listOpts := certificates.ListOpts{}
allPages, err := certificates.List(managedLoadBalancerClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allCertificates, err := certificates.ExtractCertificates(allPages)
if err != nil {
panic(err)
}
for _, certificate := range allCertificates {
fmt.Printf("%+v\n", certificate)
}
Example to create a certificate
var tags map[string]interface{}
tagsJson := `{"key":"value"}`
err := json.Unmarshal([]byte(tagsJson), &tags)
if err != nil {
panic(err)
}
createOpts := certificates.CreateOpts{
Name: "certificate",
Description: "description",
Tags: tags,
}
certificate, err := certificates.Create(managedLoadBalancerClient, createOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", certificate)
Example to show a certificate
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
certificate, err := certificates.Show(managedLoadBalancerClient, id).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", certificate)
Example to update a certificate
name := "certificate"
description := "description"
var tags map[string]interface{}
tagsJson := `{"key":"value"}`
err := json.Unmarshal([]byte(tagsJson), &tags)
if err != nil {
panic(err)
}
updateOpts := certificates.UpdateOpts{
Name: &name,
Description: &description,
Tags: &tags,
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
certificate, err := certificates.Update(managedLoadBalancerClient, updateOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", certificate)
Example to delete a certificate
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
err := certificates.Delete(managedLoadBalancerClient, id).ExtractErr()
if err != nil {
panic(err)
}
Example to upload a certificate file
uploadFileOpts := certificates.UploadFileOpts{
Type: "ca-cert",
Content: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCjAxMjM0NTY3ODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEKMjM0NTY3ODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMwo0NTY3ODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1CjY3ODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1NjcKODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OQpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaW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nN0dXZ3eHl6MDEyMzQ1Njc4OUFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaCmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OUFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaYWIKY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OUFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaYWJjZAplZmdoaWprbG1ub3BxcnN0dXZ3eHl6VjAxMjM0NTY3ODlBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlCmZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==",
}
id := "497f6eca-6276-4993-bfeb-53cbbbba6f08"
certificateFile, err := certificates.UploadFile(managedLoadBalancerClient, id, uploadFileOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", certificateFile)
*/
package certificates
229 changes: 229 additions & 0 deletions v3/ecl/managed_load_balancer/v1/certificates/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
Generated by https://github.com/tamac-io/openapi-to-eclcloud-rb
*/
package certificates

import (
"github.com/nttcom/eclcloud/v3"
"github.com/nttcom/eclcloud/v3/pagination"
)

/*
List Certificates
*/

// ListOpts allows the filtering and sorting of paginated collections through the API.
// Filtering is achieved by passing in struct field values that map to the certificate attributes you want to see returned.
type ListOpts struct {

// - ID of the resource
ID string `q:"id"`

// - Name of the resource
Name string `q:"name"`

// - Description of the resource
Description string `q:"description"`

// - ID of the owner tenant of the resource
TenantID string `q:"tenant_id"`

// - CA certificate file upload status of the certificate
CACertStatus string `q:"ca_cert_status"`

// - SSL certificate file upload status of the certificate
SSLCertStatus string `q:"ssl_cert_status"`

// - SSL key file upload status of the certificate
SSLKeyStatus string `q:"ssl_key_status"`
}

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

return q.String(), err
}

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

// List returns a Pager which allows you to iterate over a collection of certificates.
// It accepts a ListOpts struct, which allows you to filter and sort the returned collection for greater efficiency.
func List(c *eclcloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := listURL(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.LinkedPageBase{PageResult: r}}
})
}

/*
Create Certificate
*/

// CreateOpts represents options used to create a new certificate.
type CreateOpts struct {

// - Name of the certificate
Name string `json:"name,omitempty"`

// - Description of the certificate
Description string `json:"description,omitempty"`

// - Tags of the certificate
// - Must be specified as JSON object
Tags map[string]interface{} `json:"tags,omitempty"`
}

// ToCertificateCreateMap builds a request body from CreateOpts.
func (opts CreateOpts) ToCertificateCreateMap() (map[string]interface{}, error) {
return eclcloud.BuildRequestBody(opts, "certificate")
}

// CreateOptsBuilder allows extensions to add additional parameters to the Create request.
type CreateOptsBuilder interface {
ToCertificateCreateMap() (map[string]interface{}, error)
}

// Create accepts a CreateOpts struct and creates a new certificate using the values provided.
func Create(c *eclcloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToCertificateCreateMap()
if err != nil {
r.Err = err

return
}

_, r.Err = c.Post(createURL(c), b, &r.Body, &eclcloud.RequestOpts{
OkCodes: []int{200},
})

return
}

/*
Show Certificate
*/

// Show retrieves a specific certificate based on its unique ID.
func Show(c *eclcloud.ServiceClient, id string) (r ShowResult) {
_, r.Err = c.Get(showURL(c, id), &r.Body, &eclcloud.RequestOpts{
OkCodes: []int{200},
})

return
}

/*
Update Certificate
*/

// UpdateOpts represents options used to update a existing certificate.
type UpdateOpts struct {

// - Name of the certificate
Name *string `json:"name,omitempty"`

// - Description of the certificate
Description *string `json:"description,omitempty"`

// - Tags of the certificate
// - Must be specified as JSON object
Tags *map[string]interface{} `json:"tags,omitempty"`
}

// ToCertificateUpdateMap builds a request body from UpdateOpts.
func (opts UpdateOpts) ToCertificateUpdateMap() (map[string]interface{}, error) {
return eclcloud.BuildRequestBody(opts, "certificate")
}

// UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateOptsBuilder interface {
ToCertificateUpdateMap() (map[string]interface{}, error)
}

// Update accepts a UpdateOpts struct and updates a existing certificate using the values provided.
func Update(c *eclcloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToCertificateUpdateMap()
if err != nil {
r.Err = err

return
}

_, r.Err = c.Patch(updateURL(c, id), b, &r.Body, &eclcloud.RequestOpts{
OkCodes: []int{200},
})

return
}

/*
Delete Certificate
*/

// Delete accepts a unique ID and deletes the certificate associated with it.
func Delete(c *eclcloud.ServiceClient, id string) (r DeleteResult) {
_, r.Err = c.Delete(deleteURL(c, id), &eclcloud.RequestOpts{
OkCodes: []int{204},
})

return
}

/*
Upload Certificate File
*/

// UploadFileOpts represents options used to upload a file to a existing certificate.
type UploadFileOpts struct {

// - Type of the certificate file to be uploaded
// - Can be uploaded only once for each type
Type string `json:"type"`

// - Content of the certificate file to be uploaded
// - Size of the file before encoding by Base64 must be less than or equal to 16KB
// - Must be specified the content of the file that encoded by Base64 format
// - Format of the file before encoding by Base64 must be PEM
// - DER can be converted to PEM by using OpenSSL command
Content string `json:"content"`
}

// ToCertificateUploadFileMap builds a request body from UploadFileOpts.
func (opts UploadFileOpts) ToCertificateUploadFileMap() (map[string]interface{}, error) {
return eclcloud.BuildRequestBody(opts, "")
}

// UploadFileOptsBuilder allows extensions to add additional parameters to the UploadFile request.
type UploadFileOptsBuilder interface {
ToCertificateUploadFileMap() (map[string]interface{}, error)
}

// UploadFile accepts a UploadFileOpts struct and uploads a file to a existing certificate using the values provided.
func UploadFile(c *eclcloud.ServiceClient, id string, opts UploadFileOptsBuilder) (r UploadFileResult) {
b, err := opts.ToCertificateUploadFileMap()
if err != nil {
r.Err = err

return
}

_, r.Err = c.Post(uploadFileURL(c, id), b, nil, &eclcloud.RequestOpts{
OkCodes: []int{204},
})

return
}
Loading

0 comments on commit d244572

Please sign in to comment.