mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): input apsara organization id
This commit is contained in:
@@ -85,6 +85,9 @@ type SCloudaccountCredential struct {
|
||||
//秘钥key (Qcloud)
|
||||
SecretKey string `json:"secret_key"`
|
||||
|
||||
// 飞天允许的最高组织id, 默认为1
|
||||
OrganizationId int `json:"organization_id"`
|
||||
|
||||
// Google服务账号email (gcp)
|
||||
GCPClientEmail string `json:"gcp_client_email"`
|
||||
// Google服务账号project id (gcp)
|
||||
|
||||
@@ -435,6 +435,7 @@ func (opts *SAliyunCloudAccountUpdateCredentialOptions) Params() (jsonutils.JSON
|
||||
type SApsaraCloudAccountUpdateCredentialOptions struct {
|
||||
SCloudAccountIdOptions
|
||||
SAccessKeyCredential
|
||||
OrganizationId int
|
||||
}
|
||||
|
||||
func (opts *SApsaraCloudAccountUpdateCredentialOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -72,16 +72,21 @@ const (
|
||||
)
|
||||
|
||||
type ApsaraClientConfig struct {
|
||||
cpcfg cloudprovider.ProviderConfig
|
||||
accessKey string
|
||||
accessSecret string
|
||||
debug bool
|
||||
cpcfg cloudprovider.ProviderConfig
|
||||
accessKey string
|
||||
accessSecret string
|
||||
organizationId string
|
||||
debug bool
|
||||
}
|
||||
|
||||
func NewApsaraClientConfig(accessKey, accessSecret string, endpoint string) *ApsaraClientConfig {
|
||||
cfg := &ApsaraClientConfig{
|
||||
accessKey: accessKey,
|
||||
accessSecret: accessSecret,
|
||||
accessKey: accessKey,
|
||||
accessSecret: accessSecret,
|
||||
organizationId: "1",
|
||||
}
|
||||
if info := strings.Split(accessKey, "/"); len(info) == 2 {
|
||||
cfg.accessKey, cfg.organizationId = info[0], info[1]
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
@@ -414,6 +419,9 @@ func (self *SApsaraClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
|
||||
subAccount := cloudprovider.SSubAccount{}
|
||||
subAccount.Name = self.cpcfg.Name
|
||||
subAccount.Account = self.accessKey
|
||||
if self.organizationId != "1" {
|
||||
subAccount.Account = fmt.Sprintf("%s/%s", self.accessKey, self.organizationId)
|
||||
}
|
||||
subAccount.HealthStatus = api.CLOUD_PROVIDER_HEALTH_NORMAL
|
||||
return []cloudprovider.SSubAccount{subAccount}, nil
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func (r *SRegion) fetchMetricData(department string, name string, ns string, sin
|
||||
|
||||
func (r *SRegion) FetchMetricData(name string, ns string, since time.Time, until time.Time) ([]jsonutils.JSONObject, error) {
|
||||
data := make([]jsonutils.JSONObject, 0)
|
||||
part, err := r.fetchMetricData("1", name, ns, since, until)
|
||||
part, err := r.fetchMetricData(r.client.organizationId, name, ns, since, until)
|
||||
if err == nil {
|
||||
return part, nil
|
||||
}
|
||||
|
||||
@@ -98,12 +98,12 @@ func (self *SOrganizationTree) GetProject(tags []string) []SProject {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) GetOrganizationTree(id int) (*SOrganizationTree, error) {
|
||||
if id == 0 {
|
||||
id = 1
|
||||
func (self *SApsaraClient) GetOrganizationTree(id string) (*SOrganizationTree, error) {
|
||||
if len(id) == 0 {
|
||||
id = "1"
|
||||
}
|
||||
params := map[string]string{
|
||||
"Id": fmt.Sprintf("%d", id),
|
||||
"Id": id,
|
||||
}
|
||||
resp, err := self.ascmRequest("GetOrganizationTree", params)
|
||||
if err != nil {
|
||||
@@ -118,7 +118,7 @@ func (self *SApsaraClient) GetOrganizationTree(id int) (*SOrganizationTree, erro
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) GetOrganizationList() ([]SOrganization, error) {
|
||||
params := map[string]string{"Id": "1"}
|
||||
params := map[string]string{"Id": self.organizationId}
|
||||
resp, err := self.ascmRequest("GetOrganizationList", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -185,7 +185,7 @@ func (self *SProject) GetTags() (map[string]string, error) {
|
||||
}
|
||||
|
||||
func (self *SApsaraClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
tree, err := self.GetOrganizationTree(1)
|
||||
tree, err := self.GetOrganizationTree(self.organizationId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetOrganizationTree")
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -56,6 +57,9 @@ func (self *SApsaraProviderFactory) ValidateCreateCloudaccountData(ctx context.C
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, "access_key_secret")
|
||||
}
|
||||
output.Account = input.AccessKeyId
|
||||
if input.OrganizationId > 0 {
|
||||
output.Account = fmt.Sprintf("%s/%d", input.AccessKeyId, input.OrganizationId)
|
||||
}
|
||||
output.Secret = input.AccessKeySecret
|
||||
if len(input.Endpoint) == 0 {
|
||||
return output, httperrors.NewMissingParameterError("endpoint")
|
||||
@@ -75,8 +79,12 @@ func (self *SApsaraProviderFactory) ValidateUpdateCloudaccountCredential(ctx con
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, "access_key_secret")
|
||||
}
|
||||
account := input.AccessKeyId
|
||||
if input.OrganizationId > 0 {
|
||||
account = fmt.Sprintf("%s/%d", input.AccessKeyId, input.OrganizationId)
|
||||
}
|
||||
output = cloudprovider.SCloudaccount{
|
||||
Account: input.AccessKeyId,
|
||||
Account: account,
|
||||
Secret: input.AccessKeySecret,
|
||||
}
|
||||
return output, nil
|
||||
@@ -100,11 +108,15 @@ func (self *SApsaraProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig
|
||||
}
|
||||
|
||||
func (self *SApsaraProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) (map[string]string, error) {
|
||||
region := ""
|
||||
if info.Options != nil {
|
||||
region, _ = info.Options.GetString("default_region")
|
||||
}
|
||||
return map[string]string{
|
||||
"APSARA_ACCESS_KEY": info.Account,
|
||||
"APSARA_SECRET": info.Secret,
|
||||
"APSARA_ENDPOINT": info.Url,
|
||||
"APSARA_REGION": "",
|
||||
"APSARA_REGION": region,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ func init() {
|
||||
})
|
||||
|
||||
type OrganizationListOptions struct {
|
||||
Id int
|
||||
Id string
|
||||
}
|
||||
|
||||
shellutils.R(&OrganizationListOptions{}, "organization-tree", "List organization tree", func(cli *apsara.SRegion, args *OrganizationListOptions) error {
|
||||
|
||||
Reference in New Issue
Block a user