Skip to content

Commit

Permalink
release 0.1.100 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Huaweicloud-SDK committed Jun 13, 2024
1 parent be37135 commit a46334f
Show file tree
Hide file tree
Showing 377 changed files with 16,505 additions and 785 deletions.
504 changes: 504 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

504 changes: 504 additions & 0 deletions CHANGELOG_CN.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.99
0.1.100
32 changes: 27 additions & 5 deletions core/auth/basic/basic_icredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
ProjectIdInHeader = "X-Project-Id"
SecurityTokenInHeader = "X-Security-Token"
AuthTokenInHeader = "X-Auth-Token"
emptyAk = "EMPTY_AK"
emptySK = "EMPTY_SK"
)

var DefaultDerivedPredicate = auth.GetDefaultDerivedPredicate()
Expand Down Expand Up @@ -242,12 +244,14 @@ func (s *Credentials) getIdToken() (string, error) {

type CredentialsBuilder struct {
Credentials *Credentials
errMap map[string]string
}

func NewCredentialsBuilder() *CredentialsBuilder {
return &CredentialsBuilder{Credentials: &Credentials{
IamEndpoint: internal.GetIamEndpoint(),
}}
return &CredentialsBuilder{
Credentials: &Credentials{IamEndpoint: internal.GetIamEndpoint()},
errMap: make(map[string]string),
}
}

func (builder *CredentialsBuilder) WithIamEndpointOverride(endpoint string) *CredentialsBuilder {
Expand All @@ -256,12 +260,22 @@ func (builder *CredentialsBuilder) WithIamEndpointOverride(endpoint string) *Cre
}

func (builder *CredentialsBuilder) WithAk(ak string) *CredentialsBuilder {
builder.Credentials.AK = ak
if ak == "" {
builder.errMap[emptyAk] = "input ak cannot be an empty string"
} else {
builder.Credentials.AK = ak
delete(builder.errMap, emptyAk)
}
return builder
}

func (builder *CredentialsBuilder) WithSk(sk string) *CredentialsBuilder {
builder.Credentials.SK = sk
if sk == "" {
builder.errMap[emptySK] = "input sk cannot be an empty string"
} else {
builder.Credentials.SK = sk
delete(builder.errMap, emptySK)
}
return builder
}

Expand Down Expand Up @@ -300,6 +314,14 @@ func (builder *CredentialsBuilder) Build() *Credentials {
}

func (builder *CredentialsBuilder) SafeBuild() (*Credentials, error) {
if builder.errMap != nil && len(builder.errMap) != 0 {
errMsg := "build credentials failed: "
for _, msg := range builder.errMap {
errMsg += msg + "; "
}
return nil, sdkerr.NewCredentialsTypeError(errMsg)
}

if builder.Credentials.IdpId != "" || builder.Credentials.IdTokenFile != "" {
if builder.Credentials.IdpId == "" {
return nil, sdkerr.NewCredentialsTypeError("IdpId is required when using IdpId&IdTokenFile")
Expand Down
54 changes: 39 additions & 15 deletions core/auth/basic/basic_icredential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,50 @@ func TestCredentials_NeedUpdateAuthToken(t *testing.T) {
assert.False(t, credentials.needUpdateAuthToken())
}

func TestCredentialsBuilder_Build(t *testing.T) {
// test build with IdpId, IdTokenFile and ProjectId
func TestCredentialsBuilder_SafeBuild(t *testing.T) {
// ProjectId is missing
_, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "ProjectId is required when using IdpId&IdTokenFile")
}

func TestCredentialsBuilder_Build1(t *testing.T) {
_, err := NewCredentialsBuilder().WithIdpId("id").SafeBuild()
assert.Equal(t, "ProjectId is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// IdTokenFile is missing
_, err = NewCredentialsBuilder().WithIdpId("id").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "IdTokenFile is required when using IdpId&IdTokenFile")
}

func TestCredentialsBuilder_Build2(t *testing.T) {
_, err := NewCredentialsBuilder().WithIdTokenFile("file").SafeBuild()
assert.Equal(t, "IdTokenFile is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// IdpId is missing
_, err = NewCredentialsBuilder().WithIdTokenFile("file").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "IdpId is required when using IdpId&IdTokenFile")
assert.Equal(t, "IdpId is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// success with IdpId, IdTokenFile and ProjectId
credentials, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").WithProjectId("projectId").SafeBuild()
assert.Nil(t, err)
assert.Equal(t, "id", credentials.IdpId)
assert.Equal(t, "file", credentials.IdTokenFile)
assert.Equal(t, "projectId", credentials.ProjectId)
}

func TestCredentialsBuilder_Build3(t *testing.T) {
credentials, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").WithProjectId("projectId").SafeBuild()
// test empty ak&sk
func TestCredentialsBuilder_SafeBuild2(t *testing.T) {
// ak is empty string
_, err := NewCredentialsBuilder().WithAk("").WithSk("sk").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input ak cannot be an empty string")
// sk is empty string
_, err = NewCredentialsBuilder().WithAk("ak").WithSk("").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input sk cannot be an empty string")
// ak and sk are both empty string
_, err = NewCredentialsBuilder().WithAk("").WithSk("").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input ak cannot be an empty string")
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input sk cannot be an empty string")
// success with valid ak and sk
credentials, err := NewCredentialsBuilder().WithAk("ak").WithSk("sk").SafeBuild()
assert.Nil(t, err)
assert.Equal(t, "ak", credentials.AK)
assert.Equal(t, "sk", credentials.SK)
credentials, err = NewCredentialsBuilder().WithAk("").WithSk("").WithAk("ak").WithSk("sk").SafeBuild()
assert.Nil(t, err)
assert.IsType(t, &Credentials{}, credentials)
assert.Equal(t, "ak", credentials.AK)
assert.Equal(t, "sk", credentials.SK)
}
32 changes: 27 additions & 5 deletions core/auth/global/global_icredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
SecurityTokenInHeader = "X-Security-Token"
GlobalRegionId = "globe"
AuthTokenInHeader = "X-Auth-Token"
emptyAk = "EMPTY_AK"
emptySK = "EMPTY_SK"
)

var DefaultDerivedPredicate = auth.GetDefaultDerivedPredicate()
Expand Down Expand Up @@ -242,21 +244,33 @@ func (s *Credentials) updateAuthTokenByIdToken(client *impl.DefaultHttpClient) e

type CredentialsBuilder struct {
Credentials *Credentials
errMap map[string]string
}

func NewCredentialsBuilder() *CredentialsBuilder {
return &CredentialsBuilder{Credentials: &Credentials{
IamEndpoint: internal.GetIamEndpoint(),
}}
return &CredentialsBuilder{
Credentials: &Credentials{IamEndpoint: internal.GetIamEndpoint()},
errMap: make(map[string]string),
}
}

func (builder *CredentialsBuilder) WithAk(ak string) *CredentialsBuilder {
builder.Credentials.AK = ak
if ak == "" {
builder.errMap[emptyAk] = "input ak cannot be an empty string"
} else {
builder.Credentials.AK = ak
delete(builder.errMap, emptyAk)
}
return builder
}

func (builder *CredentialsBuilder) WithSk(sk string) *CredentialsBuilder {
builder.Credentials.SK = sk
if sk == "" {
builder.errMap[emptySK] = "input sk cannot be an empty string"
} else {
builder.Credentials.SK = sk
delete(builder.errMap, emptySK)
}
return builder
}

Expand Down Expand Up @@ -300,6 +314,14 @@ func (builder *CredentialsBuilder) Build() *Credentials {
}

func (builder *CredentialsBuilder) SafeBuild() (*Credentials, error) {
if builder.errMap != nil && len(builder.errMap) != 0 {
errMsg := "build credentials failed: "
for _, msg := range builder.errMap {
errMsg += msg + "; "
}
return nil, sdkerr.NewCredentialsTypeError(errMsg)
}

if builder.Credentials.IdpId != "" || builder.Credentials.IdTokenFile != "" {
if builder.Credentials.IdpId == "" {
return nil, sdkerr.NewCredentialsTypeError("IdpId is required when using IdpId&IdTokenFile")
Expand Down
52 changes: 38 additions & 14 deletions core/auth/global/global_icredential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,50 @@ func TestCredentials_NeedUpdateAuthToken(t *testing.T) {
assert.False(t, credentials.needUpdateAuthToken())
}

// test build with IdpId, IdTokenFile and DomainId
func TestCredentialsBuilder_Build(t *testing.T) {
// DomainId is missing
_, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "DomainId is required when using IdpId&IdTokenFile")
}

func TestCredentialsBuilder_Build1(t *testing.T) {
_, err := NewCredentialsBuilder().WithIdpId("id").SafeBuild()
assert.Equal(t, "DomainId is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// IdTokenFile is missing
_, err = NewCredentialsBuilder().WithIdpId("id").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "IdTokenFile is required when using IdpId&IdTokenFile")
}

func TestCredentialsBuilder_Build2(t *testing.T) {
_, err := NewCredentialsBuilder().WithIdTokenFile("file").SafeBuild()
assert.Equal(t, "IdTokenFile is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// IdpId is missing
_, err = NewCredentialsBuilder().WithIdTokenFile("file").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Equal(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "IdpId is required when using IdpId&IdTokenFile")
assert.Equal(t, "IdpId is required when using IdpId&IdTokenFile", err.(*sdkerr.CredentialsTypeError).ErrorMessage)
// success with IdpId, IdTokenFile and DomainId
credentials, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").WithDomainId("domainId").SafeBuild()
assert.Nil(t, err)
assert.Equal(t, "id", credentials.IdpId)
assert.Equal(t, "file", credentials.IdTokenFile)
assert.Equal(t, "domainId", credentials.DomainId)
}

func TestCredentialsBuilder_Build3(t *testing.T) {
credentials, err := NewCredentialsBuilder().WithIdpId("id").WithIdTokenFile("file").WithDomainId("domainId").SafeBuild()
// test empty ak&sk
func TestCredentialsBuilder_SafeBuild2(t *testing.T) {
// ak is empty string
_, err := NewCredentialsBuilder().WithAk("").WithSk("sk").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input ak cannot be an empty string")
// sk is empty string
_, err = NewCredentialsBuilder().WithAk("ak").WithSk("").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input sk cannot be an empty string")
// ak and sk are both empty string
_, err = NewCredentialsBuilder().WithAk("").WithSk("").SafeBuild()
assert.IsType(t, err, &sdkerr.CredentialsTypeError{})
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input ak cannot be an empty string")
assert.Contains(t, err.(*sdkerr.CredentialsTypeError).ErrorMessage, "input sk cannot be an empty string")
// success with valid ak and sk
credentials, err := NewCredentialsBuilder().WithAk("ak").WithSk("sk").SafeBuild()
assert.Nil(t, err)
assert.Equal(t, "ak", credentials.AK)
assert.Equal(t, "sk", credentials.SK)
credentials, err = NewCredentialsBuilder().WithAk("").WithSk("").WithAk("ak").WithSk("sk").SafeBuild()
assert.Nil(t, err)
assert.IsType(t, &Credentials{}, credentials)
assert.Equal(t, "ak", credentials.AK)
assert.Equal(t, "sk", credentials.SK)
}
12 changes: 12 additions & 0 deletions services/aos/v1/region/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ var (
"https://rfs.af-south-1.myhuaweicloud.com")
EU_WEST_101 = region.NewRegion("eu-west-101",
"https://aos.myhuaweicloud.eu")
NA_MEXICO_1 = region.NewRegion("na-mexico-1",
"https://rfs.na-mexico-1.myhuaweicloud.com")
CN_NORTH_11 = region.NewRegion("cn-north-11",
"https://rfs.cn-north-11.myhuaweicloud.com")
CN_EAST_5 = region.NewRegion("cn-east-5",
"https://rfs.cn-east-5.myhuaweicloud.com")
AF_NORTH_1 = region.NewRegion("af-north-1",
"https://rfs.af-north-1.myhuaweicloud.com")
)

var staticFields = map[string]*region.Region{
Expand All @@ -59,6 +67,10 @@ var staticFields = map[string]*region.Region{
"la-north-2": LA_NORTH_2,
"af-south-1": AF_SOUTH_1,
"eu-west-101": EU_WEST_101,
"na-mexico-1": NA_MEXICO_1,
"cn-north-11": CN_NORTH_11,
"cn-east-5": CN_EAST_5,
"af-north-1": AF_NORTH_1,
}

var provider = region.DefaultProviderChain("AOS")
Expand Down
2 changes: 2 additions & 0 deletions services/as/v1/model/model_create_scaling_policy_v2_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type CreateScalingPolicyV2Option struct {

ScalingPolicyAction *ScalingPolicyActionV2 `json:"scaling_policy_action,omitempty"`

IntervalAlarmActions *[]IntervalAlarmActionsV2 `json:"interval_alarm_actions,omitempty"`

// 冷却时间,取值范围0-86400,默认为300,单位是秒。
CoolDownTime *int32 `json:"cool_down_time,omitempty"`

Expand Down
33 changes: 33 additions & 0 deletions services/as/v1/model/model_interval_alarm_actions_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package model

import (
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/utils"

"strings"
)

// IntervalAlarmActionsV2 操作告警区间
type IntervalAlarmActionsV2 struct {

// 操作选项,默认为ADD。 当scaling_resource_type为SCALING_GROUP,支持如下操作: ADD:增加 REMOVE/REDUCE:减少 SET:设置为 当scaling_resource_type为BANDWIDTH,支持如下操作: ADD:增加 REDUCE:减少
Operation *string `json:"operation,omitempty"`

// 操作限制。当scaling_resource_type为BANDWIDTH,且operation不为SET时,limits参数生效,单位为Mbit/s。此时,当operation为ADD时,limits表示带宽可调整的上限;当operation为REDUCE时,limits表示带宽可调整的下限。
Limits *int32 `json:"limits,omitempty"`

// 操作大小,取值范围为0到300的整数,默认为1。当scaling_resource_type为SCALING_GROUP时,size为实例个数,取值范围为0-300的整数,默认为1。当scaling_resource_type为BANDWIDTH时,size表示带宽大小,单位为Mbit/s,取值范围为1到300的整数,默认为1。当scaling_resource_type为SCALING_GROUP时,size和percentage参数只能选其中一个进行配置。
Size *int32 `json:"size,omitempty"`

LowerBound *int32 `json:"lower_bound,omitempty"`

UpperBound *int32 `json:"upper_bound,omitempty"`
}

func (o IntervalAlarmActionsV2) String() string {
data, err := utils.Marshal(o)
if err != nil {
return "IntervalAlarmActionsV2 struct{}"
}

return strings.Join([]string{"IntervalAlarmActionsV2", string(data)}, " ")
}
2 changes: 2 additions & 0 deletions services/as/v1/model/model_scaling_all_policy_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ScalingAllPolicyDetail struct {

ScalingPolicyAction *ScalingPolicyActionV2 `json:"scaling_policy_action,omitempty"`

IntervalAlarmActions *[]IntervalAlarmActionsV2 `json:"interval_alarm_actions,omitempty"`

// 冷却时间,取值范围0-86400,默认为300,单位是秒。
CoolDownTime *int32 `json:"cool_down_time,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions services/as/v1/model/model_scaling_policies_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ScalingPoliciesV2 struct {

ScalingPolicyAction *ScalingPolicyActionV2 `json:"scaling_policy_action,omitempty"`

IntervalAlarmActions *[]IntervalAlarmActionsV2 `json:"interval_alarm_actions,omitempty"`

// 冷却时间,取值范围0-86400,默认为300,单位是秒。
CoolDownTime *int32 `json:"cool_down_time,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions services/as/v1/model/model_scaling_v2_policy_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type ScalingV2PolicyDetail struct {

ScalingPolicyAction *ScalingPolicyActionV2 `json:"scaling_policy_action,omitempty"`

IntervalAlarmActions *[]IntervalAlarmActionsV2 `json:"interval_alarm_actions,omitempty"`

// 冷却时间,取值范围0-86400,默认为300,单位是秒。
CoolDownTime *int32 `json:"cool_down_time,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions services/as/v1/model/model_update_scaling_v2_policy_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type UpdateScalingV2PolicyOption struct {

ScalingPolicyAction *ScalingPolicyActionV2 `json:"scaling_policy_action,omitempty"`

IntervalAlarmActions *[]IntervalAlarmActionsV2 `json:"interval_alarm_actions,omitempty"`

// 冷却时间,取值范围0-86400,默认为300,单位是秒。
CoolDownTime *int32 `json:"cool_down_time,omitempty"`

Expand Down
21 changes: 21 additions & 0 deletions services/cae/v1/cae_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ func (c *CaeClient) CreateComponentInvoker(request *model.CreateComponentRequest
return &CreateComponentInvoker{invoker.NewBaseInvoker(c.HcClient, request, requestDef)}
}

// CreateComponentWithConfiguration 创建、生效配置并部署组件
//
// 创建、生效配置并部署组件。
//
// Please refer to HUAWEI cloud API Explorer for details.
func (c *CaeClient) CreateComponentWithConfiguration(request *model.CreateComponentWithConfigurationRequest) (*model.CreateComponentWithConfigurationResponse, error) {
requestDef := GenReqDefForCreateComponentWithConfiguration()

if resp, err := c.HcClient.Sync(request, requestDef); err != nil {
return nil, err
} else {
return resp.(*model.CreateComponentWithConfigurationResponse), nil
}
}

// CreateComponentWithConfigurationInvoker 创建、生效配置并部署组件
func (c *CaeClient) CreateComponentWithConfigurationInvoker(request *model.CreateComponentWithConfigurationRequest) *CreateComponentWithConfigurationInvoker {
requestDef := GenReqDefForCreateComponentWithConfiguration()
return &CreateComponentWithConfigurationInvoker{invoker.NewBaseInvoker(c.HcClient, request, requestDef)}
}

// DeleteComponent 删除组件
//
// 删除组件。
Expand Down
Loading

0 comments on commit a46334f

Please sign in to comment.