Skip to content

Commit 6ac9775

Browse files
[Feat.] TMS providers (#864)
1 parent 6c968f5 commit 6ac9775

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package tms
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
8+
"github.com/opentelekomcloud/gophertelekomcloud/openstack/tms/v1/provider"
9+
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
10+
)
11+
12+
func TestTMSProviderList(t *testing.T) {
13+
if os.Getenv("RUN_TMS_TAGS") == "" {
14+
t.Skip("unstable test")
15+
}
16+
client, err := clients.NewTmsV1Client()
17+
th.AssertNoErr(t, err)
18+
19+
p, err := provider.List(client, provider.ListOpts{})
20+
th.AssertNoErr(t, err)
21+
th.AssertEquals(t, true, len(p) > 1)
22+
}

openstack/tms/v1/provider/List.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package provider
2+
3+
import (
4+
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
5+
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
6+
)
7+
8+
// ListOpts is the structure that used to query tags detail for specified resource.
9+
type ListOpts struct {
10+
// Specifies the display language.
11+
Locale string `q:"locale"`
12+
// The maximum queries supported. The value 10 is used by default if this parameter is not set.
13+
// The value range is 1 to 200.
14+
Limit *int `q:"limit"`
15+
// Specifies the index position, which starts from the next data record specified by offset.
16+
// The value must be a number and cannot be negative. The default value is 0.
17+
Offset *int `q:"offset"`
18+
// Specifies the cloud service name.
19+
Provider *int `q:"provider"`
20+
}
21+
22+
func List(client *golangsdk.ServiceClient, opts ListOpts) ([]Providers, error) {
23+
url, err := golangsdk.NewURLBuilder().
24+
WithEndpoints("tms", "providers").
25+
WithQueryParams(&opts).Build()
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
// GET /v1.0/tms/providers
31+
raw, err := client.Get(client.ServiceURL(url.String()), nil, &golangsdk.RequestOpts{
32+
OkCodes: []int{200},
33+
})
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
var res []Providers
39+
err = extract.IntoSlicePtr(raw.Body, &res, "providers")
40+
return res, err
41+
}
42+
43+
type Providers struct {
44+
// Specifies the cloud service name.
45+
Provider string `json:"provider"`
46+
// Specifies the display name of the resource.
47+
// You can set the language by setting the **locale** parameter.
48+
DisplayName string `json:"provider_i18n_display_name"`
49+
// Specifies the resource type.
50+
ResourceTypes []ResourceTypes `json:"resource_types"`
51+
}
52+
53+
type ResourceTypes struct {
54+
// Specifies the resource type.
55+
ResourceType string `json:"resource_type"`
56+
// Specifies the display name of the resource type.
57+
// You can set the language by setting the **locale** parameter.
58+
DisplayName string `json:"provider_i18n_display_name"`
59+
// Specifies the supported regions.
60+
Regions []string `json:"regions"`
61+
// Specifies whether the resource is a global resource.
62+
Global bool `json:"global"`
63+
}

0 commit comments

Comments
 (0)