Merge pull request #12484 from tb365/bugfix/tb-bugfix-101802

ctyun api updates
This commit is contained in:
Zexi Li
2021-10-29 11:09:11 +08:00
committed by GitHub
4 changed files with 120 additions and 3 deletions
+72
View File
@@ -0,0 +1,72 @@
package ctyun
import (
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
)
type SCrmUser struct {
LoginName string `json:"loginName"`
LoginEmail string `json:"loginEmail"`
RootUserid string `json:"rootUserid"`
CreateDate int64 `json:"createDate"`
AccountType int64 `json:"accountType"`
Status int64 `json:"status"`
Province string `json:"province"`
City string `json:"city"`
Mobilephone string `json:"mobilephone"`
Postpaid int64 `json:"postpaid"`
Channel int64 `json:"channel"`
AuditStatus string `json:"auditStatus"`
AuditMsg string `json:"auditMsg"`
}
func (self *SRegion) getCustiomInfo(t string, crmBizId string, accountId string) jsonutils.JSONObject {
if len(t) == 0 {
return nil
}
customeInfo := jsonutils.NewDict()
//customeInfo.Set("name", jsonutils.NewString(""))
//customeInfo.Set("email", jsonutils.NewString(""))
//customeInfo.Set("phone", jsonutils.NewString(""))
indentity := jsonutils.NewDict()
if len(crmBizId) > 0 {
indentity.Set("crmBizId", jsonutils.NewString(crmBizId))
}
if len(accountId) > 0 {
indentity.Set("accountId", jsonutils.NewString(accountId))
}
if len(t) > 0 {
customeInfo.Set("type", jsonutils.NewString(t))
customeInfo.Set("identity", indentity)
}
return customeInfo
}
func (self *SRegion) GetCrmUser(t string, crmBizId string, accountId string) (*SCrmUser, error) {
params := map[string]string{
"regionId": self.GetId(),
}
customInfo := self.getCustiomInfo(t, crmBizId, accountId)
if customInfo != nil {
params["customInfo"] = customInfo.String()
}
resp, err := self.client.DoGet("/apiproxy/v3/queryCRM", params)
if err != nil {
return nil, errors.Wrap(err, "Region.queryCRM.DoGet")
}
user := &SCrmUser{}
err = resp.Unmarshal(user, "returnObj")
if err != nil {
return nil, errors.Wrap(err, "Region.queryCRM.Unmarshal")
}
return user, nil
}
+8 -2
View File
@@ -48,7 +48,7 @@ type SRegion struct {
}
func (self *SRegion) fetchIVpcs() error {
vpcs, err := self.GetVpcs()
vpcs, err := self.GetVpcs("", "", "")
if err != nil {
return errors.Wrap(err, "SRegion.fetchIVpcs")
}
@@ -83,11 +83,17 @@ func (self *SRegion) fetchInfrastructure() error {
return nil
}
func (self *SRegion) GetVpcs() ([]SVpc, error) {
func (self *SRegion) GetVpcs(t string, crmBizId string, accountId string) ([]SVpc, error) {
vpcs := make([]SVpc, 0)
params := map[string]string{
"regionId": self.GetId(),
}
customInfo := self.getCustiomInfo(t, crmBizId, accountId)
if customInfo != nil {
params["customInfo"] = customInfo.String()
}
resp, err := self.client.DoGet("/apiproxy/v3/getVpcs", params)
if err != nil {
return nil, err
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shell
import (
"yunion.io/x/onecloud/pkg/multicloud/ctyun"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type VCrmUserOptions struct {
Type string `json:"type"`
CrmBizId string `json:"crm_biz_id"`
AccountId string `json:"account_id"`
}
shellutils.R(&VCrmUserOptions{}, "crm-user-show", "Show crm user", func(cli *ctyun.SRegion, args *VCrmUserOptions) error {
user, e := cli.GetCrmUser(args.Type, args.CrmBizId, args.AccountId)
if e != nil {
return e
}
printObject(user)
return nil
})
}
+4 -1
View File
@@ -21,9 +21,12 @@ import (
func init() {
type VpcListOptions struct {
Type string `json:"type"`
CrmBizId string `json:"crm_biz_id"`
AccountId string `json:"account_id"`
}
shellutils.R(&VpcListOptions{}, "vpc-list", "List vpcs", func(cli *ctyun.SRegion, args *VpcListOptions) error {
vpcs, e := cli.GetVpcs()
vpcs, e := cli.GetVpcs(args.Type, args.CrmBizId, args.AccountId)
if e != nil {
return e
}