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
63 changes: 63 additions & 0 deletions openstack/dns/v2/tags/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package tags

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

//ActionOptsBuilder is an interface from which can build the request of creating/deleting tags
type ActionOptsBuilder interface {
ToTagsActionMap() (map[string]interface{}, error)
}

//ActionOpts is a struct contains the parameters of creating/deleting tags
type ActionOpts struct {
Action string `json:"action" required:"ture"`
Tags []ResourceTag `json:"tags" required:"true"`
}

//ToTagsActionMap build the action request in json format
func (opts ActionOpts) ToTagsActionMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

func doAction(client *golangsdk.ServiceClient, srvType, id string, opts ActionOptsBuilder) (r ActionResult) {
b, err := opts.ToTagsActionMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(actionURL(client, srvType, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200, 204},
})
return
}

//Create is a method of creating tags by id
func Create(client *golangsdk.ServiceClient, srvType, id string, tags []ResourceTag) (r ActionResult) {
opts := ActionOpts{
Tags: tags,
Action: "create",
}
return doAction(client, srvType, id, opts)
}

//Delete is a method of deleting tags by id
func Delete(client *golangsdk.ServiceClient, srvType, id string, tags []ResourceTag) (r ActionResult) {
opts := ActionOpts{
Tags: tags,
Action: "delete",
}
return doAction(client, srvType, id, opts)
}

//Get is a method of getting the tags by id
func Get(client *golangsdk.ServiceClient, srvType, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, srvType, id), &r.Body, nil)
return
}

//List is a method of getting the tags of all service
func List(client *golangsdk.ServiceClient, srvType string) (r ListResult) {
_, r.Err = client.Get(listURL(client, srvType), &r.Body, nil)
return
}
45 changes: 45 additions & 0 deletions openstack/dns/v2/tags/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tags

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

//ResourceTags represents the tags response
type ResourceTags struct {
Tags []ResourceTag `json:"tags"`
}

//ResourceTag is in key-value format
type ResourceTag struct {
Key string `json:"key" required:"ture"`
Value string `json:"value,omitempty"`
}

//ActionResult is the action result which is the result of create or delete operations
type ActionResult struct {
golangsdk.ErrResult
}

//GetResult contains the body of getting detailed tags request
type GetResult struct {
golangsdk.Result
}

//Extract method will parse the result body into ResourceTags struct
func (r GetResult) Extract() (ResourceTags, error) {
var tags ResourceTags
err := r.Result.ExtractInto(&tags)
return tags, err
}

//ListResult contains the body of getting all tags request
type ListResult struct {
golangsdk.Result
}

//Extract method will parse the result body into ResourceTags struct
func (r ListResult) Extract() (ResourceTags, error) {
var tags ResourceTags
err := r.Result.ExtractInto(&tags)
return tags, err
}
19 changes: 19 additions & 0 deletions openstack/dns/v2/tags/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tags

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

// supported resourceType: "DNS-public_zone", "DNS-private_zone",
// "DNS-public_recordset", "DNS-private_recordset", "DNS-ptr_record"
func actionURL(c *golangsdk.ServiceClient, resourceType, id string) string {
return c.ServiceURL(c.ProjectID, resourceType, id, "tags/action")
}

func getURL(c *golangsdk.ServiceClient, resourceType, id string) string {
return c.ServiceURL(c.ProjectID, resourceType, id, "tags")
}

func listURL(c *golangsdk.ServiceClient, resourceType string) string {
return c.ServiceURL(c.ProjectID, resourceType, "tags")
}
63 changes: 63 additions & 0 deletions openstack/networking/v1/tags/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package tags

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

//ActionOptsBuilder is an interface from which can build the request of creating/deleting tags
type ActionOptsBuilder interface {
ToTagsActionMap() (map[string]interface{}, error)
}

//ActionOpts is a struct contains the parameters of creating/deleting tags
type ActionOpts struct {
Action string `json:"action" required:"ture"`
Tags []ResourceTag `json:"tags" required:"true"`
}

//ToTagsActionMap build the action request in json format
func (opts ActionOpts) ToTagsActionMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

func doAction(client *golangsdk.ServiceClient, srvType, id string, opts ActionOptsBuilder) (r ActionResult) {
b, err := opts.ToTagsActionMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(actionURL(client, srvType, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200, 204},
})
return
}

//Create is a method of creating tags by id
func Create(client *golangsdk.ServiceClient, srvType, id string, tags []ResourceTag) (r ActionResult) {
opts := ActionOpts{
Tags: tags,
Action: "create",
}
return doAction(client, srvType, id, opts)
}

//Delete is a method of deleting tags by id
func Delete(client *golangsdk.ServiceClient, srvType, id string, tags []ResourceTag) (r ActionResult) {
opts := ActionOpts{
Tags: tags,
Action: "delete",
}
return doAction(client, srvType, id, opts)
}

//Get is a method of getting the tags by id
func Get(client *golangsdk.ServiceClient, srvType, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, srvType, id), &r.Body, nil)
return
}

//List is a method of getting the tags of all service
func List(client *golangsdk.ServiceClient, srvType string) (r ListResult) {
_, r.Err = client.Get(listURL(client, srvType), &r.Body, nil)
return
}
45 changes: 45 additions & 0 deletions openstack/networking/v1/tags/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tags

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

//ResourceTags represents the tags response
type ResourceTags struct {
Tags []ResourceTag `json:"tags"`
}

//ResourceTag is in key-value format
type ResourceTag struct {
Key string `json:"key" required:"ture"`
Value string `json:"value,omitempty"`
}

//ActionResult is the action result which is the result of create or delete operations
type ActionResult struct {
golangsdk.ErrResult
}

//GetResult contains the body of getting detailed tags request
type GetResult struct {
golangsdk.Result
}

//Extract method will parse the result body into ResourceTags struct
func (r GetResult) Extract() (ResourceTags, error) {
var tags ResourceTags
err := r.Result.ExtractInto(&tags)
return tags, err
}

//ListResult contains the body of getting all tags request
type ListResult struct {
golangsdk.Result
}

//Extract method will parse the result body into ResourceTags struct
func (r ListResult) Extract() (ResourceTags, error) {
var tags ResourceTags
err := r.Result.ExtractInto(&tags)
return tags, err
}
18 changes: 18 additions & 0 deletions openstack/networking/v1/tags/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tags

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

// supported resourceType: "vpcs", "subnets", "publicips"
func actionURL(c *golangsdk.ServiceClient, resourceType, id string) string {
return c.ServiceURL(c.ProjectID, resourceType, id, "tags/action")
}

func getURL(c *golangsdk.ServiceClient, resourceType, id string) string {
return c.ServiceURL(c.ProjectID, resourceType, id, "tags")
}

func listURL(c *golangsdk.ServiceClient, resourceType string) string {
return c.ServiceURL(c.ProjectID, resourceType, "tags")
}