apigateway.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package huawei
  15. import (
  16. "fmt"
  17. "net/url"
  18. )
  19. type SApigateway struct {
  20. Id string
  21. InstanceName string
  22. }
  23. func (self *SRegion) ListApigateway() ([]SApigateway, error) {
  24. query := url.Values{}
  25. query.Set("limit", "500")
  26. ret := []SApigateway{}
  27. for {
  28. resp, err := self.list(SERVICE_APIG, "apigw/instances", query)
  29. if err != nil {
  30. return nil, err
  31. }
  32. part := struct {
  33. Instances []SApigateway
  34. Total int
  35. }{}
  36. err = resp.Unmarshal(&part)
  37. if err != nil {
  38. return nil, err
  39. }
  40. ret = append(ret, part.Instances...)
  41. if len(ret) >= part.Total || len(part.Instances) == 0 {
  42. break
  43. }
  44. query.Set("offset", fmt.Sprintf("%d", len(ret)))
  45. }
  46. return ret, nil
  47. }
  48. type SApigatewayApi struct {
  49. Id string
  50. Name string
  51. }
  52. func (self *SRegion) ListApigatewayApis(id string) ([]SApigatewayApi, error) {
  53. query := url.Values{}
  54. query.Set("limit", "500")
  55. ret := []SApigatewayApi{}
  56. res := fmt.Sprintf("apigw/instances/%s/apis", id)
  57. for {
  58. resp, err := self.list(SERVICE_APIG, res, query)
  59. if err != nil {
  60. return nil, err
  61. }
  62. part := struct {
  63. Apis []SApigatewayApi
  64. Total int
  65. }{}
  66. err = resp.Unmarshal(&part)
  67. if err != nil {
  68. return nil, err
  69. }
  70. ret = append(ret, part.Apis...)
  71. if len(ret) >= part.Total || len(part.Apis) == 0 {
  72. break
  73. }
  74. query.Set("offset", fmt.Sprintf("%d", len(ret)))
  75. }
  76. return ret, nil
  77. }
  78. func (self *SRegion) ListSharedApigatewayApis() ([]SApigatewayApi, error) {
  79. query := url.Values{}
  80. query.Set("limit", "500")
  81. ret := []SApigatewayApi{}
  82. for {
  83. resp, err := self.list(SERVICE_APIG_V1_0, "apigw/apis", query)
  84. if err != nil {
  85. return nil, err
  86. }
  87. part := struct {
  88. Apis []SApigatewayApi
  89. Total int
  90. }{}
  91. err = resp.Unmarshal(&part)
  92. if err != nil {
  93. return nil, err
  94. }
  95. ret = append(ret, part.Apis...)
  96. if len(ret) >= part.Total || len(part.Apis) == 0 {
  97. break
  98. }
  99. query.Set("offset", fmt.Sprintf("%d", len(ret)))
  100. }
  101. return ret, nil
  102. }