Skip to content

Commit aa3008c

Browse files
committed
fixed errors of travis-ci test
1 parent da09d22 commit aa3008c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1035
-402
lines changed

cluster-autoscaler/cloudprovider/huaweicloud/huawei-cloud-sdk-go/auth/aksk/aksk_options.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package aksk
218

3-
// AKSKAuthOptions presents the required information for AK/SK auth
19+
// AKSKOptions presents the required information for AK/SK auth
420
type AKSKOptions struct {
521
IdentityEndpoint string `json:"-" required:"true"` // HTTP endpoint for identity API.
6-
ProjectID string // user project id
22+
ProjectID string // user project id
723
DomainID string `json:"-" required:"true"` // Huawei cloud account id
8-
Region string // eg. "cn-north-1" for "Beijing1", "cn-north-4" for "Beijing4"
9-
Domain string // Cloud name
10-
Cloud string // Cloud name
11-
AccessKey string // Access Key
12-
SecretKey string // Secret key
13-
SecurityToken string // If AK/SK is used, token won't be used.
24+
Region string // eg. "cn-north-1" for "Beijing1", "cn-north-4" for "Beijing4"
25+
Domain string // Cloud name
26+
Cloud string // Cloud name
27+
AccessKey string // Access Key
28+
SecretKey string // Secret key
29+
SecurityToken string // If AK/SK is used, token won't be used.
1430
}
1531

1632
// GetIdentityEndpoint implements the method of AuthOptionsProvider

cluster-autoscaler/cloudprovider/huaweicloud/huawei-cloud-sdk-go/auth/aksk/aksk_signer.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
/*
2-
Package signer providers functions for sign http request before request cloud.
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Package aksk providers functions for sign http request before request cloud.
319
*/
420
package aksk
521

@@ -21,7 +37,7 @@ import (
2137
"time"
2238
)
2339

24-
//caseInsencitiveStringArray represents string case insensitive sorting operations
40+
// caseInsencitiveStringArray represents string case insensitive sorting operations
2541
type caseInsencitiveStringArray []string
2642

2743
// noEscape specifies whether the character should be encoded or not
@@ -86,19 +102,19 @@ type signKeyCacheEntry struct {
86102
NumberOfDaysSinceEpoch int64 // number of days since epoch
87103
}
88104

89-
// The default sign algorithm
105+
// SignAlgorithmHMACSHA256 The default sign algorithm
90106
const SignAlgorithmHMACSHA256 = "SDK-HMAC-SHA256"
91107

92-
// The header key of content hash value
108+
// ContentSha256HeaderKey The header key of content hash value
93109
const ContentSha256HeaderKey = "x-sdk-content-sha256"
94110

95-
//A regular for searching empty string
111+
// A regular for searching empty string
96112
var spaceRegexp = regexp.MustCompile(`\s+`)
97113

98114
// cache sign key
99115
var cache = NewCache(300)
100116

101-
//Sign manipulates the http.Request instance with some required authentication headers for SK/SK auth.
117+
// Sign manipulates the http.Request instance with some required authentication headers for SK/SK auth.
102118
func Sign(req *http.Request, signOptions SignOptions) {
103119
signOptions.AccessKey = strings.TrimSpace(signOptions.AccessKey)
104120
signOptions.SecretKey = strings.TrimSpace(signOptions.SecretKey)
@@ -164,9 +180,9 @@ func deriveSigningKey(signParam reqSignParams) []byte {
164180
})
165181
cache.Add(cacheKey, string(signKeyStr))
166182
return signKey
167-
} else {
168-
return buildSignKey(signParam)
169183
}
184+
185+
return buildSignKey(signParam)
170186
}
171187

172188
func buildSignKey(signParam reqSignParams) []byte {
@@ -179,7 +195,7 @@ func buildSignKey(signParam reqSignParams) []byte {
179195
return computeSignature("sdk_request", kService, signParam.SignAlgorithm)
180196
}
181197

182-
//HmacSha256 implements the Keyed-Hash Message Authentication Code computation.
198+
// HmacSha256 implements the Keyed-Hash Message Authentication Code computation.
183199
func HmacSha256(data string, key []byte) []byte {
184200
mac := hmac.New(sha256.New, key)
185201
mac.Write([]byte(data))
@@ -215,10 +231,9 @@ func buildAuthorizationHeader(signParam reqSignParams, signature []byte) string
215231
func computeSignature(signData string, key []byte, algorithm string) []byte {
216232
if algorithm == SignAlgorithmHMACSHA256 {
217233
return HmacSha256(signData, key)
218-
} else {
219-
log.Fatalf("Unsupported algorithm %s, please use %s and try again", algorithm, SignAlgorithmHMACSHA256)
220-
return nil
221234
}
235+
log.Fatalf("Unsupported algorithm %s, please use %s and try again", algorithm, SignAlgorithmHMACSHA256)
236+
return nil
222237
}
223238

224239
// createStringToSign build the need to be signed string
@@ -278,7 +293,7 @@ func encodeQueryString(queryValues url.Values) string {
278293

279294
i := 0
280295

281-
for k, _ := range queryValues {
296+
for k := range queryValues {
282297
keys[i] = urlEncode(k, false)
283298
encodedVals[keys[i]] = k
284299
i++
@@ -302,9 +317,8 @@ func encodeQueryString(queryValues url.Values) string {
302317
func getCanonicalizedQueryString(signParas reqSignParams) string {
303318
if usePayloadForQueryParameters(signParas.Req) {
304319
return ""
305-
} else {
306-
return encodeQueryString(signParas.Req.URL.Query())
307320
}
321+
return encodeQueryString(signParas.Req.URL.Query())
308322
}
309323

310324
// createCanonicalRequest builds canonical string depends the official document for signing
@@ -352,7 +366,7 @@ func getCanonicalizedHeaderString(req *http.Request) string {
352366
var headers StringBuilder
353367

354368
keys := make([]string, 0)
355-
for k, _ := range req.Header {
369+
for k := range req.Header {
356370
keys = append(keys, strings.TrimSpace(k))
357371
}
358372

@@ -379,7 +393,7 @@ func getSignedHeadersString(req *http.Request) string {
379393
var headers StringBuilder
380394

381395
keys := make([]string, 0)
382-
for k, _ := range req.Header {
396+
for k := range req.Header {
383397
keys = append(keys, strings.TrimSpace(k))
384398
}
385399

@@ -445,15 +459,18 @@ func (signParas *reqSignParams) getScope() string {
445459
}, "/")
446460
}
447461

462+
// Write ...
448463
func (buff *StringBuilder) Write(s string) *StringBuilder {
449464
buff.builder.WriteString(s)
450465
return buff
451466
}
452467

468+
// ToString ...
453469
func (buff *StringBuilder) ToString() string {
454470
return buff.builder.String()
455471
}
456472

473+
// GetBytes ...
457474
func (buff *StringBuilder) GetBytes() []byte {
458475
return []byte(buff.ToString())
459476
}

cluster-autoscaler/cloudprovider/huaweicloud/huawei-cloud-sdk-go/auth/aksk/cache.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package aksk
218

319
import "sync"

cluster-autoscaler/cloudprovider/huaweicloud/huawei-cloud-sdk-go/auth/base_options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package auth
218

319
// AuthOptionsProvider presents the base of an auth options implementation

cluster-autoscaler/cloudprovider/huaweicloud/huawei-cloud-sdk-go/auth/token/tokenID_options.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package token
218

319
// TokenIdOptions presents the required information for token ID auth
@@ -19,20 +35,19 @@ type TokenIdOptions struct {
1935
ProjectID string
2036

2137
DomainID string `json:"-" required:"true"`
22-
2338
}
2439

25-
// GetIdentityEndpoint,Implements the method of AuthOptionsProvider
40+
// GetIdentityEndpoint Implements the method of AuthOptionsProvider
2641
func (opts TokenIdOptions) GetIdentityEndpoint() string {
2742
return opts.IdentityEndpoint
2843
}
2944

30-
//GetProjectId, Implements the method of AuthOptionsProvider
45+
//GetProjectId Implements the method of AuthOptionsProvider
3146
func (opts TokenIdOptions) GetProjectId() string {
3247
return opts.ProjectID
3348
}
3449

35-
// GetDomainId,Implements the method of AuthOptionsProvider
50+
// GetDomainId Implements the method of AuthOptionsProvider
3651
func (opts TokenIdOptions) GetDomainId() string {
3752
return opts.DomainID
3853
}

0 commit comments

Comments
 (0)