fix(region): sync aws waf default action

This commit is contained in:
Qu Xuan
2021-07-22 14:14:23 +08:00
parent f266d883dd
commit 42046aaf6f
5 changed files with 38 additions and 8 deletions

View File

@@ -242,6 +242,8 @@ func (self DefaultAction) String() string {
type SCloudResource struct {
// 资源Id
Id string
// 资源名称
Name string
// 资源类型
Type string
// 资源映射端口

View File

@@ -426,6 +426,7 @@ func (self *SWafDomain) GetCloudResources() ([]cloudprovider.SCloudResource, err
if len(self.Cname) > 0 {
ret = append(ret, cloudprovider.SCloudResource{
Type: "cname",
Name: "CNAME",
Id: self.Cname,
CanDissociate: false,
})
@@ -434,11 +435,13 @@ func (self *SWafDomain) GetCloudResources() ([]cloudprovider.SCloudResource, err
if err == nil {
ret = append(ret, cloudprovider.SCloudResource{
Type: "segment_ipv4",
Name: "Segment IPv4",
Id: ipseg.Ips,
CanDissociate: false,
})
ret = append(ret, cloudprovider.SCloudResource{
Type: "segment_ipv6",
Name: "Segment IPv6",
Id: ipseg.IpV6s,
CanDissociate: false,
})

View File

@@ -205,7 +205,10 @@ func (self *SWebAcl) GetStatus() string {
func (self *SWebAcl) GetDefaultAction() *cloudprovider.DefaultAction {
ret := &cloudprovider.DefaultAction{}
if self.WebACL != nil && self.WebACL.DefaultAction != nil {
if self.WebACL.DefaultAction == nil {
self.Refresh()
}
if self.WebACL.DefaultAction != nil {
action := self.WebACL.DefaultAction
if action.Allow != nil {
ret.Action = cloudprovider.WafActionAllow
@@ -522,6 +525,9 @@ func (self *SWebAcl) AddRule(opts *cloudprovider.SWafRule) (cloudprovider.ICloud
func (self *SWebAcl) GetCloudResources() ([]cloudprovider.SCloudResource, error) {
ret := []cloudprovider.SCloudResource{}
if self.scope != SCOPE_REGIONAL {
return ret, nil
}
for _, resType := range []string{"APPLICATION_LOAD_BALANCER", "API_GATEWAY", "APPSYNC"} {
resIds, err := self.region.ListResourcesForWebACL(resType, *self.ARN)
if err != nil {
@@ -530,6 +536,7 @@ func (self *SWebAcl) GetCloudResources() ([]cloudprovider.SCloudResource, error)
for _, resId := range resIds {
ret = append(ret, cloudprovider.SCloudResource{
Id: resId,
Name: resId,
Type: resType,
})
}

View File

@@ -182,7 +182,7 @@ type SApplicationGateway struct {
multicloud.AzureTags
Name string `json:"name"`
ID string `json:"id"`
Id string `json:"id"`
Etag string `json:"etag"`
Type string `json:"type"`
Location string `json:"location"`
@@ -194,11 +194,11 @@ func (self *SApplicationGateway) GetName() string {
}
func (self *SApplicationGateway) GetId() string {
return self.ID
return self.Id
}
func (self *SApplicationGateway) GetGlobalId() string {
return strings.ToLower(self.ID)
return strings.ToLower(self.Id)
}
func (self *SRegion) ListAppGateways() ([]SApplicationGateway, error) {

View File

@@ -135,6 +135,8 @@ func wafMatchFieldAndKeyCloud2Local(v SMatchvariable) (cloudprovider.TWafMatchFi
return cloudprovider.WafMatchFieldBody, "", nil
case "RequestCookies":
return cloudprovider.WafMatchFiledCookie, v.Selector, nil
case "RemoteAddr":
return cloudprovider.WafMatchFiledHeader, v.Selector, nil
default:
return "", "", fmt.Errorf("invalid variablename %s", v.Variablename)
}
@@ -399,6 +401,9 @@ type SAppGatewayWaf struct {
HttpListeners []struct {
Id string
}
PathBasedRules []struct {
Id string
}
Resourcestate string `json:"resourceState"`
Provisioningstate string `json:"provisioningState"`
Policysettings struct {
@@ -486,7 +491,9 @@ func (self *SAppGatewayWaf) Refresh() error {
}
func (self *SAppGatewayWaf) GetDefaultAction() *cloudprovider.DefaultAction {
return &cloudprovider.DefaultAction{}
return &cloudprovider.DefaultAction{
Action: cloudprovider.TWafAction(self.Properties.Policysettings.Mode),
}
}
func (self *SRegion) ListAppWafs() ([]SAppGatewayWaf, error) {
@@ -607,17 +614,28 @@ func (self *SAppGatewayWaf) GetCloudResources() ([]cloudprovider.SCloudResource,
ret := []cloudprovider.SCloudResource{}
for _, ag := range self.Properties.ApplicationGateways {
ret = append(ret, cloudprovider.SCloudResource{
Id: ag.ID,
Type: "app_gateway",
Id: ag.Id,
Name: ag.Id[strings.LastIndex(ag.Id, "/")+1:],
Type: "Application Gateway",
CanDissociate: true,
})
}
for _, lis := range self.Properties.HttpListeners {
ret = append(ret, cloudprovider.SCloudResource{
Id: lis.Id,
Type: "http_listener",
Name: lis.Id[strings.LastIndex(lis.Id, "/")+1:],
Type: "HTTP Listener",
CanDissociate: true,
})
}
for _, route := range self.Properties.PathBasedRules {
ret = append(ret, cloudprovider.SCloudResource{
Id: route.Id,
Name: route.Id[strings.LastIndex(route.Id, "/")+1:],
Type: "Route Path",
CanDissociate: true,
})
}
return ret, nil
}