mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
@@ -249,7 +249,7 @@ func (st *STimer) descChinese(createdAt time.Time, zone *time.Location) string {
|
||||
}
|
||||
}
|
||||
if st.CycleNum > 0 {
|
||||
return fmt.Sprintf("%s同步一次,开始时间: 有效时间为%s至%s", prefix, createdAt.In(zone).Format(format), st.EndTime.In(zone).Format(format))
|
||||
return fmt.Sprintf("%s同步一次,开始时间:%s,有效时间为%s至%s", prefix, createdAt.In(zone).Format(format), st.StartTime.In(zone).Format(format), st.EndTime.In(zone).Format(format))
|
||||
}
|
||||
return fmt.Sprintf("%s %s触发 有效时间为%s至%s", prefix, st.hourMinutesDesc(zone), st.StartTime.In(zone).Format(format), st.EndTime.In(zone).Format(format))
|
||||
}
|
||||
|
||||
+13
-3
@@ -804,15 +804,18 @@ func (b *SBucket) getPolicy() ([]SBucketPolicyStatementDetails, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetOssClient")
|
||||
}
|
||||
policies := []SBucketPolicyStatementDetails{}
|
||||
resStr, err := osscli.GetBucketPolicy(b.Name)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "NoSuchBucketPolicy") {
|
||||
return policies, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "GetBucketPolicy")
|
||||
}
|
||||
obj, err := jsonutils.Parse([]byte(resStr))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Parse resStr")
|
||||
}
|
||||
policies := []SBucketPolicyStatementDetails{}
|
||||
return policies, obj.Unmarshal(&policies, "Statement")
|
||||
}
|
||||
|
||||
@@ -885,10 +888,14 @@ func (b *SBucket) DeletePolicy(id []string) ([]cloudprovider.SBucketPolicyStatem
|
||||
}
|
||||
param.Statement = append(param.Statement, policy)
|
||||
}
|
||||
err = osscli.DeleteBucketPolicy(b.Name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "DeleteBucketPolicy")
|
||||
}
|
||||
if len(param.Statement) > 0 {
|
||||
err = osscli.SetBucketPolicy(b.Name, jsonutils.Marshal(param).String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "SetBucketPolicy")
|
||||
}
|
||||
}
|
||||
return b.localPolicyToCloudprovider(param.Statement), nil
|
||||
@@ -896,14 +903,17 @@ func (b *SBucket) DeletePolicy(id []string) ([]cloudprovider.SBucketPolicyStatem
|
||||
|
||||
func (b *SBucket) localPolicyToCloudprovider(policies []SBucketPolicyStatementDetails) []cloudprovider.SBucketPolicyStatement {
|
||||
res := []cloudprovider.SBucketPolicyStatement{}
|
||||
for _, policy := range policies {
|
||||
for i, policy := range policies {
|
||||
res = append(res, cloudprovider.SBucketPolicyStatement{
|
||||
Principal: map[string][]string{"acs": policy.Principal},
|
||||
PrincipalId: policy.Principal,
|
||||
Action: policy.Action,
|
||||
Effect: policy.Effect,
|
||||
Resource: b.getResourcePaths(policy.Resource),
|
||||
ResourcePath: b.getResourcePaths(policy.Resource),
|
||||
Condition: policy.Condition,
|
||||
CannedAction: b.actionToCannedAction(policy.Action),
|
||||
Id: fmt.Sprintf("%d", i),
|
||||
})
|
||||
}
|
||||
return res
|
||||
|
||||
+46
-7
@@ -821,15 +821,17 @@ func (b *SBucket) GetPolicy() ([]cloudprovider.SBucketPolicyStatement, error) {
|
||||
return nil, errors.Wrap(err, "get policy")
|
||||
}
|
||||
res := []cloudprovider.SBucketPolicyStatement{}
|
||||
for _, policy := range policies {
|
||||
for i, policy := range policies {
|
||||
temp := cloudprovider.SBucketPolicyStatement{}
|
||||
temp.Action = policy.Action
|
||||
temp.Principal = policy.Principal
|
||||
temp.PrincipalId = getLocalPrincipalId(policy.Principal["AWS"])
|
||||
temp.PrincipalNames = getLocalPrincipalNames(policy.Principal["AWS"])
|
||||
temp.Effect = policy.Effect
|
||||
temp.Resource = policy.Resource
|
||||
temp.ResourcePath = policy.Resource
|
||||
temp.CannedAction = b.actionToCannedAction(policy.Action)
|
||||
temp.Id = policy.Sid
|
||||
temp.Id = fmt.Sprintf("%d", i)
|
||||
temp.Condition = policy.Condition
|
||||
res = append(res, temp)
|
||||
}
|
||||
@@ -880,6 +882,12 @@ func (b *SBucket) SetPolicy(policy cloudprovider.SBucketPolicyStatementInput) er
|
||||
old = []SBucketPolicyStatementDetails{}
|
||||
}
|
||||
ids := []string{}
|
||||
ret := &SCallerIdentity{}
|
||||
err = b.region.client.stsRequest("GetCallerIdentity", nil, ret)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get account err")
|
||||
}
|
||||
|
||||
for i := range policy.PrincipalId {
|
||||
id := strings.Split(policy.PrincipalId[i], ":")
|
||||
if len(id) == 1 {
|
||||
@@ -888,15 +896,14 @@ func (b *SBucket) SetPolicy(policy cloudprovider.SBucketPolicyStatementInput) er
|
||||
if len(id) == 2 {
|
||||
// 没有主账号id,设为owner id
|
||||
if len(id[0]) == 0 {
|
||||
id[0] = b.region.client.accountId
|
||||
id[0] = ret.Account
|
||||
}
|
||||
// 没有子账号,默认和主账号相同
|
||||
if len(id[1]) == 0 {
|
||||
// id[1] = id[0]
|
||||
ids = append(ids, id[0])
|
||||
continue
|
||||
id[1] = "*"
|
||||
}
|
||||
ids = append(ids, fmt.Sprintf("arn:%s:iam::%s:user/%s", b.region.GetARNPartition(), id[0], id[1]))
|
||||
// ids = append(ids, fmt.Sprintf("arn:%s:iam::%s:user/%s", b.region.GetARNPartition(), id[0], id[1]))
|
||||
ids = append(ids, id[1])
|
||||
}
|
||||
if len(id) > 2 {
|
||||
return errors.Wrap(cloudprovider.ErrNotSupported, "Invalida PrincipalId Input")
|
||||
@@ -1063,3 +1070,35 @@ func (b *SBucket) actionToCannedAction(actions []string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getLocalPrincipalId(principals []string) []string {
|
||||
res := []string{}
|
||||
for _, principal := range principals {
|
||||
temp := strings.Split(principal, "::")
|
||||
temp1 := strings.Split(temp[1], ":user/")
|
||||
if len(temp1) > 1 {
|
||||
if temp1[1] == "*" {
|
||||
temp1[1] = temp1[0]
|
||||
}
|
||||
res = append(res, fmt.Sprintf("%s:%s", temp1[0], temp1[1]))
|
||||
} else {
|
||||
res = append(res, temp[1])
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func getLocalPrincipalNames(principals []string) map[string]string {
|
||||
res := map[string]string{}
|
||||
for _, principal := range principals {
|
||||
temp := strings.Split(principal, "::")
|
||||
temp1 := strings.Split(temp[1], ":user/")
|
||||
if len(temp1) > 1 {
|
||||
if temp1[1] == "*" {
|
||||
temp1[1] = temp1[0]
|
||||
}
|
||||
res[fmt.Sprintf("%s:%s", temp1[0], temp1[1])] = temp1[1]
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
+36
-7
@@ -771,6 +771,7 @@ type SBucketPolicyStatement struct {
|
||||
}
|
||||
|
||||
type SBucketPolicyStatementDetails struct {
|
||||
Id string `json:"id"`
|
||||
Sid string `json:"Sid"`
|
||||
Effect string `json:"Effect"`
|
||||
Principal map[string][]string `json:"Principal"`
|
||||
@@ -785,16 +786,17 @@ func (b *SBucket) GetPolicy() ([]cloudprovider.SBucketPolicyStatement, error) {
|
||||
return nil, errors.Wrap(err, "getPolicy")
|
||||
}
|
||||
res := []cloudprovider.SBucketPolicyStatement{}
|
||||
for _, policy := range policies {
|
||||
for i, policy := range policies {
|
||||
temp := cloudprovider.SBucketPolicyStatement{}
|
||||
temp.Action = policy.Action
|
||||
temp.Principal = policy.Principal
|
||||
temp.PrincipalId = getLocalPrincipalId(policy.Principal["ID"])
|
||||
temp.Effect = policy.Effect
|
||||
temp.Resource = policy.Resource
|
||||
temp.ResourcePath = b.getResourcePaths(policy.Resource)
|
||||
temp.CannedAction = b.actionToCannedAction(policy.Action)
|
||||
temp.Condition = policy.Condition
|
||||
temp.Id = policy.Sid
|
||||
temp.Id = fmt.Sprintf("%d", i)
|
||||
res = append(res, temp)
|
||||
}
|
||||
return res, nil
|
||||
@@ -805,14 +807,17 @@ func (b *SBucket) getPolicy() ([]SBucketPolicyStatementDetails, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetOBSClient")
|
||||
}
|
||||
policies := []SBucketPolicyStatementDetails{}
|
||||
resp, err := obscli.GetBucketPolicy(b.Name)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "NoSuchBucketPolicy") {
|
||||
return policies, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "GetPolicy")
|
||||
}
|
||||
policies := []SBucketPolicyStatementDetails{}
|
||||
obj, err := jsonutils.Parse([]byte(resp.Policy))
|
||||
if err != nil {
|
||||
log.Errorln("this is parse err:", err)
|
||||
return nil, errors.Wrap(err, "parse resp")
|
||||
}
|
||||
|
||||
return policies, obj.Unmarshal(&policies, "Statement")
|
||||
@@ -827,11 +832,18 @@ func (b *SBucket) SetPolicy(policy cloudprovider.SBucketPolicyStatementInput) er
|
||||
old = []SBucketPolicyStatementDetails{}
|
||||
}
|
||||
ids := []string{}
|
||||
domains, err := b.region.client.getEnabledDomains()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getEnabledDomains")
|
||||
}
|
||||
if len(domains) == 0 {
|
||||
return errors.Wrap(errors.ErrNotFound, "getEnabledDomains")
|
||||
}
|
||||
for i := range policy.PrincipalId {
|
||||
id := strings.Split(policy.PrincipalId[i], ":")
|
||||
if len(id) == 1 {
|
||||
if id[0] != "*" {
|
||||
ids = append(ids, fmt.Sprintf("%s/%s", id[0], id[0]))
|
||||
ids = append(ids, fmt.Sprintf("domain/%s:user/*", domains[0].ID))
|
||||
} else {
|
||||
ids = append(ids, id[0])
|
||||
}
|
||||
@@ -843,9 +855,9 @@ func (b *SBucket) SetPolicy(policy cloudprovider.SBucketPolicyStatementInput) er
|
||||
}
|
||||
// 没有子账号,默认和主账号相同
|
||||
if len(id[1]) == 0 {
|
||||
id[1] = id[0]
|
||||
id[1] = "*"
|
||||
}
|
||||
ids = append(ids, fmt.Sprintf("%s/%s", id[0], id[1]))
|
||||
ids = append(ids, fmt.Sprintf("domain/%s:user/%s", domains[0].ID, id[1]))
|
||||
}
|
||||
if len(id) > 2 {
|
||||
return errors.Wrap(cloudprovider.ErrNotSupported, "Invalida PrincipalId Input")
|
||||
@@ -991,3 +1003,20 @@ func (b *SBucket) actionToCannedAction(actions []string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getLocalPrincipalId(principals []string) []string {
|
||||
res := []string{}
|
||||
for _, principal := range principals {
|
||||
if principal == "*" {
|
||||
res = append(res, principal)
|
||||
continue
|
||||
}
|
||||
temp := strings.Split(principal, "domain:")
|
||||
temp1 := strings.Split(temp[1], ":user/")
|
||||
if temp1[1] == "*" {
|
||||
temp1[1] = temp1[0]
|
||||
}
|
||||
res = append(res, fmt.Sprintf("%s:%s", temp1[0], temp1[1]))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user