forked from kubernetes/autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#3620 from RainbowMango/pr_sdk_on_board
CA: upload huaweicloud new sdk
- Loading branch information
Showing
384 changed files
with
20,783 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
Copyright (c) Huawei Technologies Co., Ltd. 2020-present. All rights reserved. | ||
|
||
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. | ||
|
||
|
||
|
||
Copyright of core/signer/escape.go | ||
|
||
Copyright (c) 2009 The Go Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
|
||
Copyright of core/signer/signer.go | ||
|
||
Copyright (c) 2014, Xianjie | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
99 changes: 99 additions & 0 deletions
99
...aler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic/basic_icredential.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2020 Huawei Technologies Co.,Ltd. | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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 basic | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/signer" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/request" | ||
"strings" | ||
) | ||
|
||
type Credentials struct { | ||
AK string | ||
SK string | ||
ProjectId string | ||
SecurityToken string | ||
} | ||
|
||
func (s Credentials) ProcessAuthRequest(req *request.DefaultHttpRequest) (*request.DefaultHttpRequest, error) { | ||
reqBuilder := req.Builder() | ||
|
||
if s.ProjectId != "" { | ||
reqBuilder.AddAutoFilledPathParam("project_id", s.ProjectId) | ||
reqBuilder.AddHeaderParam("X-Project-Id", s.ProjectId) | ||
} | ||
|
||
if s.SecurityToken != "" { | ||
reqBuilder.AddHeaderParam("X-Security-Token", s.SecurityToken) | ||
} | ||
|
||
if _, ok := req.GetHeaderParams()["Content-Type"]; ok { | ||
if !strings.Contains(req.GetHeaderParams()["Content-Type"], "application/json") { | ||
reqBuilder.AddHeaderParam("X-Sdk-Content-Sha256", "UNSIGNED-PAYLOAD") | ||
} | ||
} | ||
|
||
r, err := reqBuilder.Build().ConvertRequest() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
headerParams, err := signer.Sign(r, s.AK, s.SK) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range headerParams { | ||
req.AddHeaderParam(key, value) | ||
} | ||
return req, nil | ||
} | ||
|
||
type CredentialsBuilder struct { | ||
Credentials Credentials | ||
} | ||
|
||
func NewCredentialsBuilder() *CredentialsBuilder { | ||
return &CredentialsBuilder{Credentials: Credentials{}} | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithAk(ak string) *CredentialsBuilder { | ||
builder.Credentials.AK = ak | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithSk(sk string) *CredentialsBuilder { | ||
builder.Credentials.SK = sk | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithProjectId(projectId string) *CredentialsBuilder { | ||
builder.Credentials.ProjectId = projectId | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithSecurityToken(token string) *CredentialsBuilder { | ||
builder.Credentials.SecurityToken = token | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) Build() Credentials { | ||
return builder.Credentials | ||
} |
97 changes: 97 additions & 0 deletions
97
...er/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global/global_icredential.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2020 Huawei Technologies Co.,Ltd. | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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 global | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/signer" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/request" | ||
"strings" | ||
) | ||
|
||
type Credentials struct { | ||
AK string | ||
SK string | ||
DomainId string | ||
SecurityToken string | ||
} | ||
|
||
func (s Credentials) ProcessAuthRequest(req *request.DefaultHttpRequest) (*request.DefaultHttpRequest, error) { | ||
reqBuilder := req.Builder() | ||
|
||
if s.DomainId != "" { | ||
reqBuilder.AddAutoFilledPathParam("domain_id", s.DomainId) | ||
reqBuilder.AddHeaderParam("X-Domain-Id", s.DomainId) | ||
} | ||
|
||
if s.SecurityToken != "" { | ||
reqBuilder.AddHeaderParam("X-Security-Token", s.SecurityToken) | ||
} | ||
|
||
if _, ok := req.GetHeaderParams()["Content-Type"]; ok { | ||
if !strings.Contains(req.GetHeaderParams()["Content-Type"], "application/json") { | ||
reqBuilder.AddHeaderParam("X-Sdk-Content-Sha256", "UNSIGNED-PAYLOAD") | ||
} | ||
} | ||
|
||
r, err := reqBuilder.Build().ConvertRequest() | ||
if err != nil { | ||
return nil, err | ||
} | ||
headerParams, err := signer.Sign(r, s.AK, s.SK) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for key, value := range headerParams { | ||
req.AddHeaderParam(key, value) | ||
} | ||
return req, nil | ||
} | ||
|
||
type CredentialsBuilder struct { | ||
Credentials Credentials | ||
} | ||
|
||
func NewCredentialsBuilder() *CredentialsBuilder { | ||
return &CredentialsBuilder{Credentials: Credentials{}} | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithAk(ak string) *CredentialsBuilder { | ||
builder.Credentials.AK = ak | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithSk(sk string) *CredentialsBuilder { | ||
builder.Credentials.SK = sk | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithDomainId(domainId string) *CredentialsBuilder { | ||
builder.Credentials.DomainId = domainId | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) WithSecurityToken(token string) *CredentialsBuilder { | ||
builder.Credentials.SecurityToken = token | ||
return builder | ||
} | ||
|
||
func (builder *CredentialsBuilder) Build() Credentials { | ||
return builder.Credentials | ||
} |
54 changes: 54 additions & 0 deletions
54
cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/icredential.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 Huawei Technologies Co.,Ltd. | ||
// | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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 auth | ||
|
||
import ( | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global" | ||
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/request" | ||
"os" | ||
) | ||
|
||
type ICredential interface { | ||
ProcessAuthRequest(httpRequest *request.DefaultHttpRequest) (*request.DefaultHttpRequest, error) | ||
} | ||
|
||
func LoadCredentialFromEnv(defaultType string) ICredential { | ||
ak := os.Getenv("HUAWEICLOUD_SDK_AK") | ||
sk := os.Getenv("HUAWEICLOUD_SDK_SK") | ||
|
||
if defaultType == "basic.Credentials" { | ||
projectId := os.Getenv("HUAWEICLOUD_SDK_PROJECT_ID") | ||
return basic.NewCredentialsBuilder(). | ||
WithAk(ak). | ||
WithSk(sk). | ||
WithProjectId(projectId). | ||
Build() | ||
} else if defaultType == "global.Credentials" { | ||
domainId := os.Getenv("HUAWEICLOUD_SDK_DOMAIN_ID") | ||
return global.NewCredentialsBuilder(). | ||
WithAk(ak). | ||
WithSk(sk). | ||
WithDomainId(domainId). | ||
Build() | ||
} else { | ||
return nil | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ter-autoscaler/cloudprovider/huaweicloud/huaweicloud-sdk-go-v3/core/auth/signer/escape.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// based on https://github.com/golang/go/blob/master/src/net/url/url.go | ||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package signer | ||
|
||
func shouldEscape(c byte) bool { | ||
if 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || '0' <= c && c <= '9' || c == '_' || c == '-' || c == '~' || c == '.' { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func escape(s string) string { | ||
hexCount := 0 | ||
for i := 0; i < len(s); i++ { | ||
c := s[i] | ||
if shouldEscape(c) { | ||
hexCount++ | ||
} | ||
} | ||
|
||
if hexCount == 0 { | ||
return s | ||
} | ||
|
||
t := make([]byte, len(s)+2*hexCount) | ||
j := 0 | ||
for i := 0; i < len(s); i++ { | ||
switch c := s[i]; { | ||
case shouldEscape(c): | ||
t[j] = '%' | ||
t[j+1] = "0123456789ABCDEF"[c>>4] | ||
t[j+2] = "0123456789ABCDEF"[c&15] | ||
j += 3 | ||
default: | ||
t[j] = s[i] | ||
j++ | ||
} | ||
} | ||
return string(t) | ||
} |
Oops, something went wrong.