yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/client/modules/mod_balances.go (about) 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 15 package modules 16 17 import ( 18 "fmt" 19 20 "yunion.io/x/cloudmux/pkg/multicloud/huawei/client/manager" 21 "yunion.io/x/cloudmux/pkg/multicloud/huawei/client/responses" 22 ) 23 24 /* 25 https://support.huaweicloud.com/api-oce/zh-cn_topic_0075195195.html 26 客户运营能力API的Endpoint为“bss.cn-north-1.myhuaweicloud.com”。该Endpoint为全局Endpoint,中国站所有区域均可使用。 27 如何获取合作伙伴ID https://support.huaweicloud.com/bpconsole_faq/zh-cn_topic_0081005893.html 28 注意事项: 29 客户查询自身的账户余额的时候,只允许使用客户自身的AK/SK或者Token调用。 30 */ 31 type SBalanceManager struct { 32 domainId string // 租户ID 33 SResourceManager 34 } 35 36 type balanceCtx struct { 37 domainId string 38 } 39 40 // https://support.huaweicloud.com/api-bpconsole/zh-cn_topic_0075213309.html 41 // 这个manager非常特殊。url hardcode 42 func (self *balanceCtx) GetPath() string { 43 return fmt.Sprintf("%s/customer/account-mgr", self.domainId) 44 } 45 46 // 这个manager非常特殊。只有List 和 SetDomainId方法可用。其他方法未验证 47 func NewBalanceManager(cfg manager.IManagerConfig) *SBalanceManager { 48 return &SBalanceManager{SResourceManager: SResourceManager{ 49 SBaseManager: NewBaseManager(cfg), 50 ServiceName: ServiceNameBSS, 51 Region: "cn-north-1", 52 ProjectId: "", 53 version: "v1.0", 54 Keyword: "account_balance", 55 KeywordPlural: "account_balances", 56 57 ResourceKeyword: "balances", 58 }} 59 } 60 61 func (self *SBalanceManager) List(querys map[string]string) (*responses.ListResult, error) { 62 if len(self.domainId) == 0 { 63 return nil, fmt.Errorf("domainId is emtpy.Use SetDomainId method to set.") 64 } 65 66 ctx := &balanceCtx{domainId: self.domainId} 67 return self.ListInContext(ctx, querys) 68 } 69 70 func (self *SBalanceManager) SetDomainId(domainId string) { 71 self.domainId = domainId 72 }