From 8353530cc72863e5362172398f6b4461377dce57 Mon Sep 17 00:00:00 2001 From: tb365 Date: Thu, 30 Sep 2021 14:51:21 +0800 Subject: [PATCH] ctyun api updates --- pkg/multicloud/ctyun/crm.go | 72 +++++++++++++++++++++++++++++++ pkg/multicloud/ctyun/region.go | 10 ++++- pkg/multicloud/ctyun/shell/crm.go | 36 ++++++++++++++++ pkg/multicloud/ctyun/shell/vpc.go | 5 ++- 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 pkg/multicloud/ctyun/crm.go create mode 100644 pkg/multicloud/ctyun/shell/crm.go diff --git a/pkg/multicloud/ctyun/crm.go b/pkg/multicloud/ctyun/crm.go new file mode 100644 index 0000000000..f0c2c371cf --- /dev/null +++ b/pkg/multicloud/ctyun/crm.go @@ -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 +} diff --git a/pkg/multicloud/ctyun/region.go b/pkg/multicloud/ctyun/region.go index 490ab65844..b1ed647bcf 100644 --- a/pkg/multicloud/ctyun/region.go +++ b/pkg/multicloud/ctyun/region.go @@ -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 diff --git a/pkg/multicloud/ctyun/shell/crm.go b/pkg/multicloud/ctyun/shell/crm.go new file mode 100644 index 0000000000..de9a1e39f6 --- /dev/null +++ b/pkg/multicloud/ctyun/shell/crm.go @@ -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 + }) +} diff --git a/pkg/multicloud/ctyun/shell/vpc.go b/pkg/multicloud/ctyun/shell/vpc.go index fa308bd820..0b527efe3e 100644 --- a/pkg/multicloud/ctyun/shell/vpc.go +++ b/pkg/multicloud/ctyun/shell/vpc.go @@ -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 }