fix(region): vendor update for aliyun waf (#20330)

This commit is contained in:
屈轩
2024-05-21 15:19:20 +08:00
committed by GitHub
parent 7c9db8b74a
commit 3feac61a8c
11 changed files with 320 additions and 30 deletions
+1 -1
View File
@@ -89,7 +89,7 @@ require (
k8s.io/cluster-bootstrap v0.19.3
k8s.io/cri-api v0.22.17
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240517071505-7529df019e3b
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240521070416-dbc80ff43103
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
+2 -2
View File
@@ -1213,8 +1213,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240517071505-7529df019e3b h1:PZT5822e+LhZryWbULd/rUuHoo2yWkDLoZcAUKnhQwg=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240517071505-7529df019e3b/go.mod h1:quoJjGTJ2PjAY0+3YeN5JuN136whECKmfkJQwIsXKjM=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240521070416-dbc80ff43103 h1:f5vNbU6wUTO9DfoES8QqPuPtfo1AjUU6d+W0BdNqWik=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240521070416-dbc80ff43103/go.mod h1:quoJjGTJ2PjAY0+3YeN5JuN136whECKmfkJQwIsXKjM=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
+1 -1
View File
@@ -1483,7 +1483,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240517071505-7529df019e3b
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20240521070416-dbc80ff43103
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+1
View File
@@ -73,6 +73,7 @@ const (
ALIYUN_IMS_API_VERSION = "2019-08-15"
ALIYUN_NAS_API_VERSION = "2017-06-26"
ALIYUN_WAF_API_VERSION = "2019-09-10"
ALIYUN_WAF_V2_API_VERSION = "2021-10-01"
ALIYUN_MONGO_DB_API_VERSION = "2015-12-01"
ALIYUN_ES_API_VERSION = "2017-06-13"
ALIYUN_KAFKA_API_VERSION = "2019-09-16"
+14 -1
View File
@@ -151,6 +151,19 @@ func (self *SRegion) wafRequest(apiName string, params map[string]string) (jsonu
return jsonRequest(client, endpoint, ALIYUN_WAF_API_VERSION, apiName, params, self.client.debug)
}
func (self *SRegion) wafv2Request(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
client, err := self.getSdkClient()
if err != nil {
return nil, err
}
if self.RegionId != "cn-hangzhou" && self.RegionId != "ap-southeast-1" {
return nil, cloudprovider.ErrNotSupported
}
params = self.client.SetResourceGropuId(params)
endpoint := fmt.Sprintf("wafopenapi.%s.aliyuncs.com", self.RegionId)
return jsonRequest(client, endpoint, ALIYUN_WAF_V2_API_VERSION, apiName, params, self.client.debug)
}
func (self *SRegion) esRequest(apiName string, params map[string]string, body interface{}) (jsonutils.JSONObject, error) {
client, err := self.getSdkClient()
if err != nil {
@@ -306,7 +319,7 @@ func (self *SRegion) _lbRequest(client *sdk.Client, apiName string, domain strin
return jsonRequest(client, domain, ALIYUN_API_VERSION_LB, apiName, params, self.client.debug)
}
/////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////
func (self *SRegion) GetId() string {
return self.RegionId
}
+26
View File
@@ -59,3 +59,29 @@ func (self *SRegion) DeleteInstance(id string) error {
_, err := self.wafRequest("DeleteInstance", params)
return errors.Wrapf(err, "DeleteInstance")
}
func (self *SRegion) GetICloudWafInstancesV1() ([]cloudprovider.ICloudWafInstance, error) {
ins, err := self.DescribeInstanceSpecInfo()
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound {
return []cloudprovider.ICloudWafInstance{}, nil
}
return nil, errors.Wrapf(err, "DescribeInstanceSpecInfo")
}
domains, err := self.DescribeDomainNames(ins.InstanceId)
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomainNames")
}
ret := []cloudprovider.ICloudWafInstance{}
for i := range domains {
domain, err := self.DescribeDomain(ins.InstanceId, domains[i])
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomain %s", domains[i])
}
domain.region = self
domain.insId = ins.InstanceId
domain.name = domains[i]
ret = append(ret, domain)
}
return ret, nil
}
+10 -20
View File
@@ -119,35 +119,25 @@ func (self *SRegion) DescribeDomainRuleGroup(insId, domain string) (string, erro
}
func (self *SRegion) GetICloudWafInstances() ([]cloudprovider.ICloudWafInstance, error) {
ins, err := self.DescribeInstanceSpecInfo()
wafs, err := self.GetICloudWafInstancesV1()
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound {
return []cloudprovider.ICloudWafInstance{}, nil
}
return nil, errors.Wrapf(err, "DescribeInstanceSpecInfo")
return nil, err
}
domains, err := self.DescribeDomainNames(ins.InstanceId)
wafv2, err := self.GetICloudWafInstancesV2()
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomainNames")
return nil, err
}
ret := []cloudprovider.ICloudWafInstance{}
for i := range domains {
domain, err := self.DescribeDomain(ins.InstanceId, domains[i])
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomain %s", domains[i])
}
domain.region = self
domain.insId = ins.InstanceId
domain.name = domains[i]
ret = append(ret, domain)
}
return ret, nil
return append(wafs, wafv2...), nil
}
func (self *SRegion) GetICloudWafInstanceById(id string) (cloudprovider.ICloudWafInstance, error) {
ins, err := self.DescribeInstanceSpecInfo()
if err != nil {
return nil, errors.Wrapf(err, "DescribeInstanceSpecInfo")
ins, err = self.DescribeWafInstance()
if err != nil {
return nil, err
}
return self.DescribeDomainV2(ins.InstanceId, id)
}
return self.DescribeDomain(ins.InstanceId, id)
}
+64
View File
@@ -0,0 +1,64 @@
// Copyright 2019 Yunion
//
// 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.
package aliyun
import (
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/pkg/errors"
)
func (self *SRegion) DescribeWafInstance() (*SWafInstance, error) {
params := map[string]string{
"RegionId": self.RegionId,
}
resp, err := self.wafv2Request("DescribeInstance", params)
if err != nil {
return nil, errors.Wrapf(err, "DescribeInstance")
}
ret := &SWafInstance{}
err = resp.Unmarshal(&ret)
if err != nil {
return nil, errors.Wrapf(err, "resp.Unmarshal")
}
if len(ret.InstanceId) == 0 {
return nil, cloudprovider.ErrNotFound
}
return ret, nil
}
func (self *SRegion) GetICloudWafInstancesV2() ([]cloudprovider.ICloudWafInstance, error) {
ins, err := self.DescribeWafInstance()
if err != nil {
if errors.Cause(err) == cloudprovider.ErrNotFound {
return []cloudprovider.ICloudWafInstance{}, nil
}
return nil, errors.Wrapf(err, "DescribeInstanceSpecInfo")
}
domains, err := self.DescribeWafDomains(ins.InstanceId)
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomainNames")
}
ret := []cloudprovider.ICloudWafInstance{}
for i := range domains {
domain, err := self.DescribeDomainV2(ins.InstanceId, domains[i].Domain)
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomain %s", domains[i].Domain)
}
domain.region = self
domain.insId = ins.InstanceId
ret = append(ret, domain)
}
return ret, nil
}
+195
View File
@@ -0,0 +1,195 @@
// Copyright 2019 Yunion
//
// 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.
package aliyun
import (
"fmt"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
)
type SWafDomainV2 struct {
multicloud.SResourceBase
AliyunTags
region *SRegion
insId string
Domain string
Status string
Cname string
ListenPorts struct {
Http []int
Https []int
}
Backeds struct {
Http []struct {
Backend string
}
Https []struct {
Backend string
}
}
Listen struct {
HttpPorts []int
HttpsPorts []int
Http2Enabled bool
CertId string
XffHeaderMode int
XffHeaders []string
}
Redirect struct {
Backends []struct {
Backend string
}
}
ResourceManagerResourceGroupId string
}
func (self *SWafDomainV2) GetId() string {
return self.Domain
}
func (self *SWafDomainV2) GetStatus() string {
return api.WAF_STATUS_AVAILABLE
}
func (self *SWafDomainV2) GetWafType() cloudprovider.TWafType {
return cloudprovider.WafTypeDefault
}
func (self *SWafDomainV2) GetEnabled() bool {
return true
}
func (self *SWafDomainV2) GetName() string {
return self.Domain
}
func (self *SWafDomainV2) GetGlobalId() string {
return self.Domain
}
func (self *SWafDomainV2) GetIsAccessProduct() bool {
return self.Listen.XffHeaderMode != 0
}
func (self *SWafDomainV2) GetAccessHeaders() []string {
return self.Listen.XffHeaders
}
func (self *SWafDomainV2) GetHttpPorts() []int {
return self.Listen.HttpPorts
}
func (self *SWafDomainV2) GetHttpsPorts() []int {
return self.Listen.HttpsPorts
}
func (self *SWafDomainV2) GetCname() string {
return self.Cname
}
func (self *SWafDomainV2) GetSourceIps() []string {
ret := []string{}
for _, backend := range self.Redirect.Backends {
ret = append(ret, backend.Backend)
}
return ret
}
func (self *SWafDomainV2) Delete() error {
return cloudprovider.ErrNotImplemented
}
func (self *SWafDomainV2) AddRule(opts *cloudprovider.SWafRule) (cloudprovider.ICloudWafRule, error) {
return nil, errors.Wrapf(cloudprovider.ErrNotSupported, "AddRule")
}
func (self *SWafDomainV2) Refresh() error {
domain, err := self.region.DescribeDomain(self.insId, self.Domain)
if err != nil {
return errors.Wrapf(err, "DescribeDomain")
}
return jsonutils.Update(self, domain)
}
func (self *SWafDomainV2) GetCloudResources() ([]cloudprovider.SCloudResource, error) {
return nil, cloudprovider.ErrNotImplemented
}
func (self *SWafDomainV2) GetDefaultAction() *cloudprovider.DefaultAction {
return &cloudprovider.DefaultAction{
Action: cloudprovider.WafActionAllow,
InsertHeaders: map[string]string{},
}
}
func (self *SWafDomainV2) GetRules() ([]cloudprovider.ICloudWafRule, error) {
return nil, cloudprovider.ErrNotImplemented
}
func (self *SRegion) DescribeWafDomains(insId string) ([]SWafDomainV2, error) {
params := map[string]string{
"RegionId": self.RegionId,
"InstanceId": insId,
"PageNumber": "1",
"PageSize": "50",
}
pageNum := 1
ret := []SWafDomainV2{}
for {
resp, err := self.wafv2Request("DescribeDomains", params)
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomains")
}
part := struct {
TotalCount int
Domains []SWafDomainV2
}{}
err = resp.Unmarshal(&part)
if err != nil {
return nil, err
}
ret = append(ret, part.Domains...)
if len(ret) >= part.TotalCount || len(part.Domains) == 0 {
break
}
pageNum++
params["PageNumber"] = fmt.Sprintf("%d", pageNum)
}
return ret, nil
}
func (self *SRegion) DescribeDomainV2(id, domain string) (*SWafDomainV2, error) {
params := map[string]string{
"RegionId": self.RegionId,
"InstanceId": id,
"Domain": domain,
}
resp, err := self.wafv2Request("DescribeDomainDetail", params)
if err != nil {
return nil, errors.Wrapf(err, "DescribeDomainDetail")
}
ret := &SWafDomainV2{Domain: domain, region: self, insId: id}
err = resp.Unmarshal(ret)
if err != nil {
return nil, errors.Wrapf(err, "resp.Unmarshal")
}
return ret, nil
}
+2 -4
View File
@@ -147,10 +147,8 @@ func (cli *SCephFSClient) CreateDir(fsId, path string) error {
}
func (cli *SCephFSClient) DeleteDir(fsId, path string) error {
res := fmt.Sprintf("cephfs/%s/tree", fsId)
_, err := cli.delete(res, map[string]interface{}{
"path": fmt.Sprintf("/%s", strings.TrimPrefix(path, "/")),
})
res := fmt.Sprintf("cephfs/%s/tree?path=%s", fsId, fmt.Sprintf("/%s", strings.TrimPrefix(path, "/")))
_, err := cli.delete(res, map[string]interface{}{})
return err
}
+4 -1
View File
@@ -250,7 +250,10 @@ func (self *SHuaweiClient) request(method httputils.THttpMethod, regionId, url s
}
return nil, err
}
return resp, err
if gotypes.IsNil(resp) {
return nil, fmt.Errorf("empty response return")
}
return resp, nil
}
// https://console.huaweicloud.com/apiexplorer/#/openapi/IAM/doc?api=KeystoneListRegions