diff --git a/openstack/identity/v3/catalog/requests.go b/openstack/identity/v3/catalog/requests.go new file mode 100644 index 000000000..4164cbb29 --- /dev/null +++ b/openstack/identity/v3/catalog/requests.go @@ -0,0 +1,14 @@ +package catalog + +import ( + "github.com/huaweicloud/golangsdk" + "github.com/huaweicloud/golangsdk/pagination" +) + +// List enumerates the services available to a specific user. +func List(client *golangsdk.ServiceClient) pagination.Pager { + url := listURL(client) + return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { + return CatalogPage{pagination.LinkedPageBase{PageResult: r}} + }) +} diff --git a/openstack/identity/v3/catalog/results.go b/openstack/identity/v3/catalog/results.go new file mode 100644 index 000000000..e14bce068 --- /dev/null +++ b/openstack/identity/v3/catalog/results.go @@ -0,0 +1,42 @@ +package catalog + +import ( + "github.com/huaweicloud/golangsdk/openstack/identity/v3/tokens" + "github.com/huaweicloud/golangsdk/pagination" +) + +// CatalogPage is a single page of Service results. +type CatalogPage struct { + pagination.LinkedPageBase +} + +// IsEmpty returns true if the CatalogPage contains no results. +func (p CatalogPage) IsEmpty() (bool, error) { + services, err := ExtractServiceCatalog(p) + return len(services) == 0, err +} + +// NextPageURL extracts the "next" link from the links section of the result. +func (r CatalogPage) NextPageURL() (string, error) { + var s struct { + Links struct { + Next string `json:"next"` + Previous string `json:"previous"` + } `json:"links"` + } + err := r.ExtractInto(&s) + if err != nil { + return "", err + } + return s.Links.Next, err +} + +// ExtractServiceCatalog extracts a slice of Catalog from a Collection acquired +// from List. +func ExtractServiceCatalog(r pagination.Page) ([]tokens.CatalogEntry, error) { + var s struct { + Entries []tokens.CatalogEntry `json:"catalog"` + } + err := (r.(CatalogPage)).ExtractInto(&s) + return s.Entries, err +} diff --git a/openstack/identity/v3/catalog/urls.go b/openstack/identity/v3/catalog/urls.go new file mode 100644 index 000000000..da9b15019 --- /dev/null +++ b/openstack/identity/v3/catalog/urls.go @@ -0,0 +1,7 @@ +package catalog + +import "github.com/huaweicloud/golangsdk" + +func listURL(client *golangsdk.ServiceClient) string { + return client.ServiceURL("auth/catalog") +} diff --git a/openstack/identity/v3/users/requests.go b/openstack/identity/v3/users/requests.go index 6c6f74bc0..d03e954b9 100644 --- a/openstack/identity/v3/users/requests.go +++ b/openstack/identity/v3/users/requests.go @@ -86,6 +86,9 @@ type CreateOpts struct { // Password is the password of the new user. Password string `json:"password,omitempty"` + + // Description is a description of the user. + Description string `json:"description,omitempty"` } // ToUserCreateMap formats a CreateOpts into a create request. @@ -133,6 +136,9 @@ type UpdateOpts struct { // Password is the password of the new user. Password string `json:"password,omitempty"` + + // Description is a description of the user. + Description string `json:"description,omitempty"` } // ToUserUpdateMap formats a UpdateOpts into an update request. diff --git a/openstack/identity/v3/users/results.go b/openstack/identity/v3/users/results.go index 969a9f889..ccb07657b 100644 --- a/openstack/identity/v3/users/results.go +++ b/openstack/identity/v3/users/results.go @@ -13,6 +13,9 @@ type User struct { // DefaultProjectID is the ID of the default project of the user. DefaultProjectID string `json:"default_project_id"` + // Description is a description of the user. + Description string `json:"description"` + // DomainID is the domain ID the user belongs to. DomainID string `json:"domain_id"`