From a778220204765cb3fd79037e3cf1aee891c74187 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 10:47:02 +0200 Subject: [PATCH 01/26] Move Test --- .../openstack/antiddos}/fixtures.go | 2 +- .../openstack/antiddos}/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/API-en.md | 167 ------------------ openstack/antiddos/v1/antiddos/doc.go | 160 +++++++++-------- openstack/antiddos/v1/antiddos/testing/doc.go | 1 - 5 files changed, 89 insertions(+), 243 deletions(-) rename {openstack/antiddos/v1/antiddos/testing => acceptance/openstack/antiddos}/fixtures.go (99%) rename {openstack/antiddos/v1/antiddos/testing => acceptance/openstack/antiddos}/requests_test.go (99%) delete mode 100644 openstack/antiddos/v1/antiddos/API-en.md delete mode 100644 openstack/antiddos/v1/antiddos/testing/doc.go diff --git a/openstack/antiddos/v1/antiddos/testing/fixtures.go b/acceptance/openstack/antiddos/fixtures.go similarity index 99% rename from openstack/antiddos/v1/antiddos/testing/fixtures.go rename to acceptance/openstack/antiddos/fixtures.go index f7c0b0d8b..4ff177af4 100644 --- a/openstack/antiddos/v1/antiddos/testing/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -1,4 +1,4 @@ -package testing +package antiddos import ( "fmt" diff --git a/openstack/antiddos/v1/antiddos/testing/requests_test.go b/acceptance/openstack/antiddos/requests_test.go similarity index 99% rename from openstack/antiddos/v1/antiddos/testing/requests_test.go rename to acceptance/openstack/antiddos/requests_test.go index b09c49372..199045cd8 100644 --- a/openstack/antiddos/v1/antiddos/testing/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -1,4 +1,4 @@ -package testing +package antiddos import ( "testing" diff --git a/openstack/antiddos/v1/antiddos/API-en.md b/openstack/antiddos/v1/antiddos/API-en.md deleted file mode 100644 index c51a0c8ac..000000000 --- a/openstack/antiddos/v1/antiddos/API-en.md +++ /dev/null @@ -1,167 +0,0 @@ -# Package antiddos - import "github.com/opentelekomcloud/gophertelekomcloud/openstack/antiddos/v1/antiddos" -**[Overview](#overview)** - -**[Index](#index)** - -**[API Mapping](#api-mapping)** - -**[Content](#content)** - -## Overview -The Anti-DDoS traffic cleaning service (Anti-DDoS for short) defends resources (Elastic Cloud Servers (ECSs), Elastic Load Balance (ELB) instances, and Bare Metal Servers (BMSs)) on OpenTelekomCloud against network- and application-layer distributed denial of service (DDoS) attacks and sends alarms immediately when detecting an attack. In addition, Anti-DDoS improves the utilization of bandwidth and ensures the stable running of users' services. - -Example to update the Anti-DDoS defense policy of a specified EIP. - - updateOpt := antiddos.UpdateOpts{ - EnableL7: true, - TrafficPosId: 1, - HttpRequestPosId: 2, - CleaningAccessPosId: 3, - AppTypeId: 1, - } - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract() - if err != nil { - panic(err) - } -Example to enable the Anti-DDoS traffic cleaning defense. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract() - if err != nil { - panic(err) - } -Example to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } -Example to disable the Anti-DDoS traffic cleaning defense. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } -Example to query configured Anti-DDoS defense policies. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } -Example to query the defense status of a specified EIP. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } -Example to query the execution status of a specified Anti-DDoS configuration task. - - actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{ - TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", - }).Extract() - if err != nil { - panic(err) - } -Example to query optional Anti-DDoS defense policies. - - actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract() - if err != nil { - panic(err) - } -Example to query events of a specified EIP in the last 24 hours. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{ - Limit: 2, - Offset: 1, - SortDir: "asc", - }).Extract() - if err != nil { - panic(err) - } -Example to query the defense statuses of all EIPs. - - listOpt := antiddos.ListStatusOpts{ - Limit: 2, - Offset: 1, - Status: "notConfig", - Ip: "49.", - } - - actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt).Extract() - if err != nil { - panic(err) - } -Example to query weekly defense statistics about all your EIPs. - - actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{}).Extract() - if err != nil { - panic(err) - } -## Index -**[func Create(*golangsdk.ServiceClient, string, CreateOptsBuilder) (CreateResult)](#func-create)** -**[func DailyReport(*golangsdk.ServiceClient, string) (DailyReportResult)](#func-dailyreport)** -**[func Delete(*golangsdk.ServiceClient, string) (DeleteResult)](#func-delete)** -**[func Get(*golangsdk.ServiceClient, string) (GetResult)](#func-get)** -**[func GetStatus(*golangsdk.ServiceClient, string) (GetStatusResult)](#func-getstatus)** -**[func GetTask(*golangsdk.ServiceClient, GetTaskOptsBuilder) (GetTaskResult)](#func-gettask)** -**[func ListConfigs(*golangsdk.ServiceClient) (ListConfigsResult)](#func-listconfigs)** -**[func ListLogs(*golangsdk.ServiceClient, string, ListLogsOptsBuilder) (ListLogsResult)](#func-listlogs)** -**[func ListStatus(*golangsdk.ServiceClient, ListStatusOptsBuilder) (ListStatusResult)](#func-liststatus)** -**[func Update(*golangsdk.ServiceClient, string, UpdateOptsBuilder) (UpdateResult)](#func-update)** -**[func WeeklyReport(*golangsdk.ServiceClient, WeeklyReportOptsBuilder) (WeeklyReportResult)](#func-weeklyreport)** -## API Mapping -|Catalog|API|EndPoint| -|----|---|--------| -|antiddos|func Create(*golangsdk.ServiceClient, string, CreateOptsBuilder) (CreateResult)|POST /v1/{project_id}/antiddos/{floating_ip_id}| -|antiddos|func DailyReport(*golangsdk.ServiceClient, string) (DailyReportResult)|GET /v1/{project_id}/antiddos/{floating_ip_id}/daily| -|antiddos|func Delete(*golangsdk.ServiceClient, string) (DeleteResult)|DELETE /v1/{project_id}/antiddos/{floating_ip_id}| -|antiddos|func Get(*golangsdk.ServiceClient, string) (GetResult)|GET /v1/{project_id}/antiddos/{floating_ip_id}| -|antiddos|func GetStatus(*golangsdk.ServiceClient, string) (GetStatusResult)|GET /v1/{project_id}/antiddos/{floating_ip_id}/status| -|antiddos|func GetTask(*golangsdk.ServiceClient, GetTaskOptsBuilder) (GetTaskResult)|GET /v1/{project_id}/query_task_status| -|antiddos|func ListConfigs(*golangsdk.ServiceClient) (ListConfigsResult)|GET /v1/{project_id}/antiddos/query_config_list| -|antiddos|func ListLogs(*golangsdk.ServiceClient, string, ListLogsOptsBuilder) (ListLogsResult)|GET /v1/{project_id}/antiddos/{floating_ip_id}/logs| -|antiddos|func ListStatus(*golangsdk.ServiceClient, ListStatusOptsBuilder) (ListStatusResult)|GET /v1/{project_id}/antiddos| -|antiddos|func Update(*golangsdk.ServiceClient, string, UpdateOptsBuilder) (UpdateResult)|PUT /v1/{project_id}/antiddos/{floating_ip_id}| -|antiddos|func WeeklyReport(*golangsdk.ServiceClient, WeeklyReportOptsBuilder) (WeeklyReportResult)|GET /v1/{project_id}/antiddos/weekly| -## Content -## func Create - func Create(*golangsdk.ServiceClient, string, CreateOptsBuilder) (CreateResult) -This asynchronous API allows you to enable the Anti-DDoS traffic cleaning defense. Successfully invoking this API only means that the service node has received the enabling request. You need to use the task querying API to check the task execution status. -## func DailyReport - func DailyReport(*golangsdk.ServiceClient, string) (DailyReportResult) -This API allows you to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals. -## func Delete - func Delete(*golangsdk.ServiceClient, string) (DeleteResult) -This asynchronous API allows you to disable the Anti-DDoS traffic cleaning defense. Successfully invoking this API only means that the service node has received the disabling request. You need to use the task querying API to check the task execution status. -## func Get - func Get(*golangsdk.ServiceClient, string) (GetResult) -This API enables you to query configured Anti-DDoS defense policies. You can query the policy of a specified EIP. -## func GetStatus - func GetStatus(*golangsdk.ServiceClient, string) (GetStatusResult) -This API allows you to query the defense status of a specified EIP. -## func GetTask - func GetTask(*golangsdk.ServiceClient, GetTaskOptsBuilder) (GetTaskResult) -This API enables you to query the execution status of a specified Anti-DDoS configuration task. -## func ListConfigs - func ListConfigs(*golangsdk.ServiceClient) (ListConfigsResult) -This API allows you to query optional Anti-DDoS defense policies. Based on your service, you can select a policy for Anti-DDoS traffic cleaning. -## func ListLogs - func ListLogs(*golangsdk.ServiceClient, string, ListLogsOptsBuilder) (ListLogsResult) -This API allows you to query events of a specified EIP in the last 24 hours. Events include cleaning and blackhole events, and the query delay is within five minutes. -## func ListStatus - func ListStatus(*golangsdk.ServiceClient, ListStatusOptsBuilder) (ListStatusResult) -This API enables you to query the defense statuses of all EIPs, regardless whether an EIP has been bound to an Elastic Cloud Server (ECS) or not. -## func Update - func Update(*golangsdk.ServiceClient, string, UpdateOptsBuilder) (UpdateResult) -This API enables you to update the Anti-DDoS defense policy of a specified EIP. Successfully invoking this API only means that the service node has received the update request. You need to use the task querying API to check the task execution status. -## func WeeklyReport - func WeeklyReport(*golangsdk.ServiceClient, WeeklyReportOptsBuilder) (WeeklyReportResult) -This API allows you to query weekly defense statistics about all your EIPs, including the number of intercepted DDoS attacks, number of attacks, and ranking by the number of attacks. Currently, you can query weekly statistics up to four weeks before the current time. Data older than four weeks cannot be queried. diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 8da73898f..89f29eff1 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -1,99 +1,113 @@ /* -The Anti-DDoS traffic cleaning service (Anti-DDoS for short) defends resources (Elastic Cloud Servers (ECSs), Elastic Load Balance (ELB) instances, and Bare Metal Servers (BMSs)) on OpenTelekomCloud against network- and application-layer distributed denial of service (DDoS) attacks and sends alarms immediately when detecting an attack. In addition, Anti-DDoS improves the utilization of bandwidth and ensures the stable running of users' services. +Package antiddos +The Anti-DDoS traffic cleaning service (Anti-DDoS for short) defends resources (Elastic Cloud Servers (ECSs), +Elastic Load Balance (ELB) instances, and Bare Metal Servers (BMSs)) on OpenTelekomCloud against network- +and application-layer distributed denial of service (DDoS) attacks and sends alarms immediately when detecting an attack. +In addition, Anti-DDoS improves the utilization of bandwidth and ensures the stable running of users' services. Example to update the Anti-DDoS defense policy of a specified EIP. - updateOpt := antiddos.UpdateOpts{ - EnableL7: true, - TrafficPosId: 1, - HttpRequestPosId: 2, - CleaningAccessPosId: 3, - AppTypeId: 1, - } - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract() - if err != nil { - panic(err) - } + updateOpt := antiddos.UpdateOpts{ + EnableL7: true, + TrafficPosId: 1, + HttpRequestPosId: 2, + CleaningAccessPosId: 3, + AppTypeId: 1, + } + + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract() + if err != nil { + panic(err) + } + Example to enable the Anti-DDoS traffic cleaning defense. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract() + if err != nil { + panic(err) + } + Example to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract() + if err != nil { + panic(err) + } + Example to disable the Anti-DDoS traffic cleaning defense. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract() + if err != nil { + panic(err) + } + Example to query configured Anti-DDoS defense policies. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract() + if err != nil { + panic(err) + } + Example to query the defense status of a specified EIP. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract() + if err != nil { + panic(err) + } + Example to query the execution status of a specified Anti-DDoS configuration task. - actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{ - TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", - }).Extract() - if err != nil { - panic(err) - } + actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{ + TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", + }).Extract() + if err != nil { + panic(err) + } + Example to query optional Anti-DDoS defense policies. - actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract() - if err != nil { - panic(err) - } + actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract() + if err != nil { + panic(err) + } + Example to query events of a specified EIP in the last 24 hours. - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{ - Limit: 2, - Offset: 1, - SortDir: "asc", - }).Extract() - if err != nil { - panic(err) - } + floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" + actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{ + Limit: 2, + Offset: 1, + SortDir: "asc", + }).Extract() + if err != nil { + panic(err) + } + Example to query the defense statuses of all EIPs. - listOpt := antiddos.ListStatusOpts{ - Limit: 2, - Offset: 1, - Status: "notConfig", - Ip: "49.", - } - - actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt).Extract() - if err != nil { - panic(err) - } + listOpt := antiddos.ListStatusOpts{ + Limit: 2, + Offset: 1, + Status: "notConfig", + Ip: "49.", + } + + actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt).Extract() + if err != nil { + panic(err) + } + Example to query weekly defense statistics about all your EIPs. - actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{}).Extract() - if err != nil { - panic(err) - } + actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{}).Extract() + if err != nil { + panic(err) + } */ package antiddos diff --git a/openstack/antiddos/v1/antiddos/testing/doc.go b/openstack/antiddos/v1/antiddos/testing/doc.go deleted file mode 100644 index 7603f836a..000000000 --- a/openstack/antiddos/v1/antiddos/testing/doc.go +++ /dev/null @@ -1 +0,0 @@ -package testing From c651ed7ac1103c345100ceaec899f6c576d51517 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:33:26 +0200 Subject: [PATCH 02/26] ListDailyLogs --- .../openstack/antiddos/requests_test.go | 6 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- .../antiddos/v1/antiddos/list_daily_logs.go | 62 +++++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 40 ------------ openstack/antiddos/v1/antiddos/results.go | 40 ------------ openstack/antiddos/v1/antiddos/url.go | 4 -- provider_client.go | 2 +- service_client.go | 16 ++--- 8 files changed, 75 insertions(+), 97 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/list_daily_logs.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 199045cd8..34cad1f37 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -111,13 +111,13 @@ func TestListLogs(t *testing.T) { HandleListLogsSuccessfully(t) floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{ + actual, err := antiddos.ListDailyLogs(client.ServiceClient(), floatingIpId, antiddos.ListDailyLogsOps{ Limit: 2, Offset: 1, SortDir: "asc", - }).Extract() + }) th.AssertNoErr(t, err) - th.CheckDeepEquals(t, ListLogsResponse, actual) + th.CheckDeepEquals(t, ListLogsResponse, actual.Logs) } func TestGetStatus(t *testing.T) { diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 89f29eff1..a5fb520fb 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -80,7 +80,7 @@ Example to query optional Anti-DDoS defense policies. Example to query events of a specified EIP in the last 24 hours. floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListLogs(client.ServiceClient(), floatingIpId, antiddos.ListLogsOpts{ + actual, err := antiddos.ListDailyLogs(client.ServiceClient(), floatingIpId, antiddos.ListDailyLogsOps{ Limit: 2, Offset: 1, SortDir: "asc", diff --git a/openstack/antiddos/v1/antiddos/list_daily_logs.go b/openstack/antiddos/v1/antiddos/list_daily_logs.go new file mode 100644 index 000000000..3cedc2197 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/list_daily_logs.go @@ -0,0 +1,62 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListDailyLogsOps struct { + // Limit of number of returned results or the maximum number of returned results of a query. + // The value ranges from 1 to 100, and this parameter is used together with the offset parameter. + // If neither limit nor offset is used, query results of all ECSs are returned. + Limit int `q:"limit"` + // This parameter is valid only when used together with the limit parameter. + Offset int `q:"offset"` + // Possible values: + // desc: indicates that query results are given and sorted by time in descending order. + // asc: indicates that query results are given and sorted by time in ascending order. + // The default value is desc. + SortDir string `q:"sort_dir"` +} + +func ListDailyLogs(client *golangsdk.ServiceClient, floatingIpId string, opts ListDailyLogsOps) (*ListDailyLogsResponse, error) { + query, err := golangsdk.BuildQueryString(opts) + if err != nil { + return nil, err + } + + // GET /v1/{project_id}/antiddos/{floating_ip_id}/logs + raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId, "logs")+query.String(), nil, nil) + + var res ListDailyLogsResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type ListDailyLogsResponse struct { + // Total number of EIPs + Total int `json:"total,"` + // List of events + Logs []Logs `json:"logs,"` +} + +type Logs struct { + // Start time + StartTime int `json:"start_time,"` + // End time + EndTime int `json:"end_time,"` + // Defense status, the possible value of which is one of the following: + // 1: indicates that traffic cleaning is underway. + // 2: indicates that traffic is discarded. + Status int `json:"status,"` + // Traffic at the triggering point. + TriggerBps int `json:"trigger_bps,"` + // Packet rate at the triggering point + TriggerPps int `json:"trigger_pps,"` + // HTTP request rate at the triggering point + TriggerHttpPps int `json:"trigger_http_pps,"` +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index 706d3e3d2..861f4562e 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -125,46 +125,6 @@ func ListConfigs(client *golangsdk.ServiceClient) (r ListConfigsResult) { return } -type ListLogsOpts struct { - // Limit of number of returned results or the maximum number of returned results of a query. The value ranges from 1 to 100, and this parameter is used together with the offset parameter. If neither limit nor offset is used, query results of all ECSs are returned. - Limit int `q:"limit"` - - // Offset. This parameter is valid only when used together with the limit parameter. - Offset int `q:"offset"` - - // Possible values: desc: indicates that query results are given and sorted by time in descending order. asc: indicates that query results are given and sorted by time in ascending order.The default value is desc. - SortDir string `q:"sort_dir"` -} - -type ListLogsOptsBuilder interface { - ToListLogsQuery() (string, error) -} - -func (opts ListLogsOpts) ToListLogsQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), err -} - -func ListLogs(client *golangsdk.ServiceClient, floatingIpId string, opts ListLogsOptsBuilder) (r ListLogsResult) { - url := ListLogsURL(client, floatingIpId) - if opts != nil { - query, err := opts.ToListLogsQuery() - if err != nil { - r.Err = err - return - } - url += query - } - - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - type ListStatusOpts struct { // ID of an EIP FloatingIpId string diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index 950dc97a8..be0a56c14 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -198,46 +198,6 @@ type ListConfigsResponse struct { } `json:"connection_limited_list,"` } -type ListLogsResult struct { - commonResult -} - -func (r ListLogsResult) Extract() ([]Logs, error) { - var s ListLogsResponse - err := r.ExtractInto(&s) - if err != nil { - return nil, err - } - return s.Logs, nil -} - -type ListLogsResponse struct { - // Total number of EIPs - Total int `json:"total,"` - - // List of events - Logs []Logs `json:"logs,"` -} - -type Logs struct { - // Start time - StartTime int `json:"start_time,"` - - // End time - EndTime int `json:"end_time,"` - - // Defense status, the possible value of which is one of the following: 1: indicates that traffic cleaning is underway. 2: indicates that traffic is discarded. - Status int `json:"status,"` - - // Traffic at the triggering point. - TriggerBps int `json:"trigger_bps,"` - - // Packet rate at the triggering point - TriggerPps int `json:"trigger_pps,"` - - // HTTP request rate at the triggering point - TriggerHttpPps int `json:"trigger_http_pps,"` -} type ListStatusResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 7fa5f69c2..43f1a4c57 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -30,10 +30,6 @@ func ListConfigsURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("antiddos", "query_config_list") } -func ListLogsURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId, "logs") -} - func ListStatusURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("antiddos") } diff --git a/provider_client.go b/provider_client.go index 74938d92a..06904a14e 100644 --- a/provider_client.go +++ b/provider_client.go @@ -228,7 +228,7 @@ func (client *ProviderClient) Request(method, url string, options *RequestOpts) } } - // get latest token from client + // get the latest token from client for k, v := range client.AuthenticatedHeaders() { req.Header.Set(k, v) } diff --git a/service_client.go b/service_client.go index dfdd0c86a..fff874a94 100644 --- a/service_client.go +++ b/service_client.go @@ -63,7 +63,7 @@ func (client *ServiceClient) initReqOpts(_ string, JSONBody interface{}, JSONRes } } -// Get calls `Request` with the "GET" HTTP verb. +// Get calls `Request` with the "GET" HTTP verb. def 200 func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -72,7 +72,7 @@ func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *Req return client.Request("GET", url, opts) } -// Post calls `Request` with the "POST" HTTP verb. +// Post calls `Request` with the "POST" HTTP verb. def 201, 202 func (client *ServiceClient) Post(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -81,7 +81,7 @@ func (client *ServiceClient) Post(url string, JSONBody interface{}, JSONResponse return client.Request("POST", url, opts) } -// Put calls `Request` with the "PUT" HTTP verb. +// Put calls `Request` with the "PUT" HTTP verb. def 201, 202 func (client *ServiceClient) Put(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -90,7 +90,7 @@ func (client *ServiceClient) Put(url string, JSONBody interface{}, JSONResponse return client.Request("PUT", url, opts) } -// Patch calls `Request` with the "PATCH" HTTP verb. +// Patch calls `Request` with the "PATCH" HTTP verb. def 200, 204 func (client *ServiceClient) Patch(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -99,7 +99,7 @@ func (client *ServiceClient) Patch(url string, JSONBody interface{}, JSONRespons return client.Request("PATCH", url, opts) } -// Delete calls `Request` with the "DELETE" HTTP verb. +// Delete calls `Request` with the "DELETE" HTTP verb. def 202, 204 func (client *ServiceClient) Delete(url string, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -108,7 +108,7 @@ func (client *ServiceClient) Delete(url string, opts *RequestOpts) (*http.Respon return client.Request("DELETE", url, opts) } -// DeleteWithBody calls `Request` with the "DELETE" HTTP verb. +// DeleteWithBody calls `Request` with the "DELETE" HTTP verb. def 202, 204 func (client *ServiceClient) DeleteWithBody(url string, JSONBody interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -117,7 +117,7 @@ func (client *ServiceClient) DeleteWithBody(url string, JSONBody interface{}, op return client.Request("DELETE", url, opts) } -// Delete calls `Request` with the "DELETE" HTTP verb. +// DeleteWithResponse calls `Request` with the "DELETE" HTTP verb. def 202, 204 func (client *ServiceClient) DeleteWithResponse(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -126,7 +126,7 @@ func (client *ServiceClient) DeleteWithResponse(url string, JSONResponse interfa return client.Request("DELETE", url, opts) } -// DeleteWithBodyResp calls `Request` with the "DELETE" HTTP verb. +// DeleteWithBodyResp calls `Request` with the "DELETE" HTTP verb. def 202, 204 func (client *ServiceClient) DeleteWithBodyResp(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) From 2e307cc3ce619c1c07b4e80b45c2255f9c0bafde Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:41:49 +0200 Subject: [PATCH 03/26] ListDailyReport --- .../openstack/antiddos/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- .../antiddos/v1/antiddos/list_daily_report.go | 36 +++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 8 ---- openstack/antiddos/v1/antiddos/results.go | 40 ------------------- openstack/antiddos/v1/antiddos/url.go | 4 -- 6 files changed, 38 insertions(+), 54 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/list_daily_report.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 34cad1f37..21a4870be 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -137,7 +137,7 @@ func TestDailyReport(t *testing.T) { HandleDailyReportSuccessfully(t) floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ListDailyReport(client.ServiceClient(), floatingIpId) th.AssertNoErr(t, err) th.CheckDeepEquals(t, DailyReportResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index a5fb520fb..824699c2a 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -32,7 +32,7 @@ Example to enable the Anti-DDoS traffic cleaning defense. Example to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals. floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.DailyReport(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ListDailyReport(client.ServiceClient(), floatingIpId).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/list_daily_report.go b/openstack/antiddos/v1/antiddos/list_daily_report.go new file mode 100644 index 000000000..08d372054 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/list_daily_report.go @@ -0,0 +1,36 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListDailyReport(client *golangsdk.ServiceClient, floatingIpId string) ([]Data, error) { + // GET /v1/{project_id}/antiddos/{floating_ip_id}/daily + raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId, "daily"), nil, nil) + + var res []Data + err = extract.IntoSlicePtr(raw, &res, "data") + if err != nil { + return nil, err + } + + return res, nil +} + +type Data struct { + // Start time + PeriodStart int `json:"period_start,"` + // Inbound traffic (bit/s) + BpsIn int `json:"bps_in,"` + // Attack traffic (bit/s) + BpsAttack int `json:"bps_attack,"` + // Total traffic + TotalBps int `json:"total_bps,"` + // Inbound packet rate (number of packets per second) + PpsIn int `json:"pps_in,"` + // Attack packet rate (number of packets per second) + PpsAttack int `json:"pps_attack,"` + // Total packet rate + TotalPps int `json:"total_pps,"` +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index 861f4562e..0221e6bd2 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -50,14 +50,6 @@ func Create(client *golangsdk.ServiceClient, floatingIpId string, opts CreateOpt return } -func DailyReport(client *golangsdk.ServiceClient, floatingIpId string) (r DailyReportResult) { - url := DailyReportURL(client, floatingIpId) - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResult) { url := DeleteURL(client, floatingIpId) _, r.Err = client.Delete(url, &golangsdk.RequestOpts{ diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index be0a56c14..ac24facd3 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -32,46 +32,6 @@ type CreateResponse struct { TaskId string `json:"task_id,"` } -type DailyReportResult struct { - commonResult -} - -func (r DailyReportResult) Extract() ([]Data, error) { - var s DailyReportResponse - err := r.ExtractInto(&s) - if err != nil { - return nil, err - } - return s.Data, nil -} - -type DailyReportResponse struct { - // Traffic in the last 24 hours - Data []Data `json:"data"` -} -type Data struct { - // Start time - PeriodStart int `json:"period_start,"` - - // Inbound traffic (bit/s) - BpsIn int `json:"bps_in,"` - - // Attack traffic (bit/s) - BpsAttack int `json:"bps_attack,"` - - // Total traffic - TotalBps int `json:"total_bps,"` - - // Inbound packet rate (number of packets per second) - PpsIn int `json:"pps_in,"` - - // Attack packet rate (number of packets per second) - PpsAttack int `json:"pps_attack,"` - - // Total packet rate - TotalPps int `json:"total_pps,"` -} - type DeleteResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 43f1a4c57..54dae6c18 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -6,10 +6,6 @@ func CreateURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } -func DailyReportURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId, "daily") -} - func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } From 3b0eff457cefb38169e702fa612dee12841c4a1d Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 13:49:27 +0200 Subject: [PATCH 04/26] ListDDosStatus --- acceptance/openstack/antiddos/fixtures.go | 2 +- .../openstack/antiddos/requests_test.go | 4 +- openstack/antiddos/v1/antiddos/doc.go | 4 +- .../antiddos/v1/antiddos/list_ddos_status.go | 88 +++++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 72 +-------------- openstack/antiddos/v1/antiddos/results.go | 37 -------- openstack/antiddos/v1/antiddos/url.go | 4 - 7 files changed, 94 insertions(+), 117 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/list_ddos_status.go diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index 4ff177af4..5a02a5f5e 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -133,7 +133,7 @@ func HandleUpdateSuccessfully(t *testing.T) { }) } -var ListStatusResponse = []antiddos.DdosStatus{ +var ListStatusResponse = []antiddos.DDosStatus{ { FloatingIpId: "4d60bba4-0791-4e82-8262-9bdffaeb1d14", FloatingIpAddress: "49.4.4.36", diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 21a4870be..562d09fe5 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -73,14 +73,14 @@ func TestListStatus(t *testing.T) { defer th.TeardownHTTP() HandleListStatusSuccessfully(t) - listOpt := antiddos.ListStatusOpts{ + listOpt := antiddos.ListDDosStatusOpts{ Limit: 2, Offset: 1, Status: "notConfig", Ip: "49.", } - actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt) + actual, err := antiddos.ListDDosStatus(client.ServiceClient(), listOpt) th.AssertNoErr(t, err) th.CheckDeepEquals(t, ListStatusResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 824699c2a..343b1b24b 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -91,14 +91,14 @@ Example to query events of a specified EIP in the last 24 hours. Example to query the defense statuses of all EIPs. - listOpt := antiddos.ListStatusOpts{ + listOpt := antiddos.ListDDosStatusOpts{ Limit: 2, Offset: 1, Status: "notConfig", Ip: "49.", } - actual, err := antiddos.ListStatus(client.ServiceClient(), listOpt).Extract() + actual, err := antiddos.ListDDosStatus(client.ServiceClient(), listOpt).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go new file mode 100644 index 000000000..7750afec2 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -0,0 +1,88 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListDDosStatusOpts struct { + // ID of an EIP + FloatingIpId string + // If this parameter is not used, + // the defense statuses of all ECSs are displayed in the Neutron-queried order by default. + Status string `q:"status"` + // Limit of number of returned results + Limit int `q:"limit"` + // Offset + Offset int `q:"offset"` + // IP address. Both IPv4 and IPv6 addresses are supported. + // For example, if you enter ?ip=192.168, + // the defense status of EIPs corresponding to 192.168.111.1 and 10.192.168.8 is returned. + Ip string `q:"ip"` +} + +type DDosStatus struct { + // Floating IP address + FloatingIpAddress string `json:"floating_ip_address,"` + // ID of an EIP + FloatingIpId string `json:"floating_ip_id,"` + // EIP type. + NetworkType string `json:"network_type,"` + // Defense status + Status string `json:"status,"` +} + +func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([]DDosStatus, error) { + q, err := golangsdk.BuildQueryString(&opts) + if err != nil { + return nil, err + } + + // GET /v1/{project_id}/antiddos + raw, err := client.Get(client.ServiceURL("antiddos")+q.String(), nil, nil) + + var res ListStatusResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return FilterDdosStatus(res.DDosStatus, opts) +} + +type ListStatusResponse struct { + // Total number of EIPs + Total int `json:"total,"` + // List of defense statuses + DDosStatus []DDosStatus `json:"ddosStatus,"` +} + +func FilterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosStatus, error) { + var refinedDdosStatus []DDosStatus + var matched bool + m := map[string]interface{}{} + + if opts.FloatingIpId != "" { + m["FloatingIpId"] = opts.FloatingIpId + } + + if len(m) > 0 && len(ddosStatus) > 0 { + for _, ddosStatus := range ddosStatus { + matched = true + + for key, value := range m { + if sVal := getStructField(&ddosStatus, key); !(sVal == value) { + matched = false + } + } + + if matched { + refinedDdosStatus = append(refinedDdosStatus, ddosStatus) + } + } + } else { + refinedDdosStatus = ddosStatus + } + + return refinedDdosStatus, nil +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index 0221e6bd2..2b45ab6d0 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -117,77 +117,7 @@ func ListConfigs(client *golangsdk.ServiceClient) (r ListConfigsResult) { return } -type ListStatusOpts struct { - // ID of an EIP - FloatingIpId string - - // If this parameter is not used, the defense statuses of all ECSs are displayed in the Neutron-queried order by default. - Status string `q:"status"` - - // Limit of number of returned results - Limit int `q:"limit"` - - // Offset - Offset int `q:"offset"` - - // IP address. Both IPv4 and IPv6 addresses are supported. For example, if you enter ?ip=192.168, the defense status of EIPs corresponding to 192.168.111.1 and 10.192.168.8 is returned. - Ip string `q:"ip"` -} - -// ListStatus returns collection of DdosStatus. It accepts a ListStatusOpts struct, which allows you to filter and sort -// the returned collection for greater efficiency. -func ListStatus(client *golangsdk.ServiceClient, opts ListStatusOpts) ([]DdosStatus, error) { - var r ListStatusResult - - q, err := golangsdk.BuildQueryString(&opts) - if err != nil { - return nil, err - } - u := ListStatusURL(client) + q.String() - - _, r.Err = client.Get(u, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - - allStatus, err := r.Extract() - if err != nil { - return nil, err - } - - return FilterDdosStatus(allStatus, opts) -} - -func FilterDdosStatus(ddosStatus []DdosStatus, opts ListStatusOpts) ([]DdosStatus, error) { - - var refinedDdosStatus []DdosStatus - var matched bool - m := map[string]interface{}{} - - if opts.FloatingIpId != "" { - m["FloatingIpId"] = opts.FloatingIpId - } - - if len(m) > 0 && len(ddosStatus) > 0 { - for _, ddosStatus := range ddosStatus { - matched = true - - for key, value := range m { - if sVal := getStructField(&ddosStatus, key); !(sVal == value) { - matched = false - } - } - - if matched { - refinedDdosStatus = append(refinedDdosStatus, ddosStatus) - } - } - } else { - refinedDdosStatus = ddosStatus - } - return refinedDdosStatus, nil -} - -func getStructField(v *DdosStatus, field string) string { +func getStructField(v *DDosStatus, field string) string { r := reflect.ValueOf(v) f := reflect.Indirect(r).FieldByName(field) return f.String() diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index ac24facd3..a1c914af3 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -158,43 +158,6 @@ type ListConfigsResponse struct { } `json:"connection_limited_list,"` } -type ListStatusResult struct { - commonResult -} - -// Extract is a function that accepts a ListStatusOpts struct, which allows you to filter and sort -// the returned collection for greater efficiency. -func (r commonResult) Extract() ([]DdosStatus, error) { - var s ListStatusResponse - err := r.ExtractInto(&s) - if err != nil { - return nil, err - } - return s.DdosStatus, nil -} - -type ListStatusResponse struct { - // Total number of EIPs - Total int `json:"total,"` - - // List of defense statuses - DdosStatus []DdosStatus `json:"ddosStatus,"` -} - -type DdosStatus struct { - // Floating IP address - FloatingIpAddress string `json:"floating_ip_address,"` - - // ID of an EIP - FloatingIpId string `json:"floating_ip_id,"` - - // EIP type. - NetworkType string `json:"network_type,"` - - // Defense status - Status string `json:"status,"` -} - type UpdateResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 54dae6c18..17d36c288 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -26,10 +26,6 @@ func ListConfigsURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("antiddos", "query_config_list") } -func ListStatusURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL("antiddos") -} - func UpdateURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } From 1326ad331372b7f04404c8751ee89d8558e686e7 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 15:56:12 +0200 Subject: [PATCH 05/26] ListNewConfigs --- .../openstack/antiddos/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- .../antiddos/v1/antiddos/list_new_configs.go | 49 +++++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 8 --- openstack/antiddos/v1/antiddos/results.go | 45 ----------------- openstack/antiddos/v1/antiddos/url.go | 4 -- 6 files changed, 51 insertions(+), 59 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/list_new_configs.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 562d09fe5..ef1772c2c 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -90,7 +90,7 @@ func TestListConfigs(t *testing.T) { defer th.TeardownHTTP() HandleListConfigsSuccessfully(t) - actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract() + actual, err := antiddos.ListNewConfigs(client.ServiceClient()) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &ListConfigsResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 343b1b24b..50aa96ba0 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -72,7 +72,7 @@ Example to query the execution status of a specified Anti-DDoS configuration tas Example to query optional Anti-DDoS defense policies. - actual, err := antiddos.ListConfigs(client.ServiceClient()).Extract() + actual, err := antiddos.ListNewConfigs(client.ServiceClient()).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go new file mode 100644 index 000000000..7e74499b2 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -0,0 +1,49 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListNewConfigs(client *golangsdk.ServiceClient) (*ListConfigsResponse, error) { + // GET /v1/{project_id}/antiddos/query_config_list + raw, err := client.Get(client.ServiceURL("antiddos", "query_config_list"), nil, nil) + + var response ListConfigsResponse + err = extract.Into(raw, &response) + if err != nil { + return nil, err + } + + return &response, nil +} + +type ListConfigsResponse struct { + // List of traffic limits + TrafficLimitedList []struct { + // Position ID of traffic + TrafficPosId int `json:"traffic_pos_id,"` + // Threshold of traffic per second (Mbit/s) + TrafficPerSecond int `json:"traffic_per_second,"` + // Threshold of number of packets per second + PacketPerSecond int `json:"packet_per_second,"` + } `json:"traffic_limited_list,"` + + // List of HTTP limits + HttpLimitedList []struct { + // Position ID of number of HTTP requests + HttpRequestPosId int `json:"http_request_pos_id,"` + // Threshold of number of HTTP requests per second + HttpPacketPerSecond int `json:"http_packet_per_second,"` + } `json:"http_limited_list,"` + + // List of limits of numbers of connections + ConnectionLimitedList []struct { + // Position ID of access limit during cleaning + CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + // Position ID of access limit during cleaning + NewConnectionLimited int `json:"new_connection_limited,"` + // Position ID of access limit during cleaning + TotalConnectionLimited int `json:"total_connection_limited,"` + } `json:"connection_limited_list,"` +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index 2b45ab6d0..c131f574b 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -109,14 +109,6 @@ func GetTask(client *golangsdk.ServiceClient, opts GetTaskOptsBuilder) (r GetTas return } -func ListConfigs(client *golangsdk.ServiceClient) (r ListConfigsResult) { - url := ListConfigsURL(client) - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - func getStructField(v *DDosStatus, field string) string { r := reflect.ValueOf(v) f := reflect.Indirect(r).FieldByName(field) diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index a1c914af3..814f1dfe4 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -113,51 +113,6 @@ type GetTaskResponse struct { TaskMsg string `json:"task_msg,"` } -type ListConfigsResult struct { - commonResult -} - -func (r ListConfigsResult) Extract() (*ListConfigsResponse, error) { - var response ListConfigsResponse - err := r.ExtractInto(&response) - return &response, err -} - -type ListConfigsResponse struct { - // List of traffic limits - TrafficLimitedList []struct { - // Position ID of traffic - TrafficPosId int `json:"traffic_pos_id,"` - - // Threshold of traffic per second (Mbit/s) - TrafficPerSecond int `json:"traffic_per_second,"` - - // Threshold of number of packets per second - PacketPerSecond int `json:"packet_per_second,"` - } `json:"traffic_limited_list,"` - - // List of HTTP limits - HttpLimitedList []struct { - // Position ID of number of HTTP requests - HttpRequestPosId int `json:"http_request_pos_id,"` - - // Threshold of number of HTTP requests per second - HttpPacketPerSecond int `json:"http_packet_per_second,"` - } `json:"http_limited_list,"` - - // List of limits of numbers of connections - ConnectionLimitedList []struct { - // Position ID of access limit during cleaning - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - - // Position ID of access limit during cleaning - NewConnectionLimited int `json:"new_connection_limited,"` - - // Position ID of access limit during cleaning - TotalConnectionLimited int `json:"total_connection_limited,"` - } `json:"connection_limited_list,"` -} - type UpdateResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 17d36c288..3cb72b8b7 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -22,10 +22,6 @@ func GetTaskURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("query_task_status") } -func ListConfigsURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL("antiddos", "query_config_list") -} - func UpdateURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } From e46c6ce87f2b964d0cfb762816c433d57422fe2c Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:06:49 +0200 Subject: [PATCH 06/26] ListWeeklyReports --- acceptance/openstack/antiddos/fixtures.go | 32 +++++------ .../openstack/antiddos/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- .../v1/antiddos/list_weekly_reports.go | 50 +++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 33 ------------ openstack/antiddos/v1/antiddos/results.go | 54 ++----------------- openstack/antiddos/v1/antiddos/url.go | 4 -- 7 files changed, 73 insertions(+), 104 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/list_weekly_reports.go diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index 5a02a5f5e..fa3329ea0 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -533,54 +533,54 @@ var WeeklyReportOutput = ` // init the loc var responsePeriodTime = time.Date(2018, 3, 1, 0, 0, 0, 0, time.UTC) -var WeeklyReportResponse = antiddos.WeeklyReportResponse{ - DdosInterceptTimes: 0, +var WeeklyReportResponse = antiddos.ListWeeklyReportsResponse{ + DDosInterceptTimes: 0, Weekdata: []antiddos.WeekData{ { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, }, { - DdosInterceptTimes: 0, - DdosBlackholeTimes: 0, + DDosInterceptTimes: 0, + DDosBlackholeTimes: 0, MaxAttackBps: 0, MaxAttackConns: 0, PeriodStartDate: responsePeriodTime, diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index ef1772c2c..73b9e6322 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -100,7 +100,7 @@ func TestWeeklyReport(t *testing.T) { defer th.TeardownHTTP() HandleWeeklyReportSuccessfully(t) - actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{PeriodStartDate: responsePeriodTime}).Extract() + actual, err := antiddos.ListWeeklyReports(client.ServiceClient(), responsePeriodTime) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &WeeklyReportResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 50aa96ba0..b124b031e 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -105,7 +105,7 @@ Example to query the defense statuses of all EIPs. Example to query weekly defense statistics about all your EIPs. - actual, err := antiddos.WeeklyReport(client.ServiceClient(), antiddos.WeeklyReportOpts{}).Extract() + actual, err := antiddos.ListWeeklyReports(client.ServiceClient(), antiddos.ListWeeklyReportsOpts{}).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go new file mode 100644 index 000000000..e15da7104 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -0,0 +1,50 @@ +package antiddos + +import ( + "strconv" + "time" + + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Time) (*ListWeeklyReportsResponse, error) { + raw, err := client.Get( + client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate.Unix()*1000, 10), + nil, nil) + + var res ListWeeklyReportsResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type ListWeeklyReportsResponse struct { + // Number of DDoS attacks intercepted in a week + DDosInterceptTimes int `json:"ddos_intercept_times,"` + // Number of DDoS attacks intercepted in a week + Weekdata []WeekData `json:"-"` + // Top 10 attacked IP addresses + Top10 []struct { + // EIP + FloatingIpAddress string `json:"floating_ip_address,"` + // Number of DDoS attacks intercepted, including cleaning operations and blackholes + Times int `json:"times,"` + } `json:"top10,"` +} + +type WeekData struct { + // Number of DDoS attacks intercepted + DDosInterceptTimes int `json:"ddos_intercept_times,"` + // Number of DDoS blackholes + DDosBlackholeTimes int `json:"ddos_blackhole_times,"` + // Maximum attack traffic + MaxAttackBps int `json:"max_attack_bps,"` + // Maximum number of attack connections + MaxAttackConns int `json:"max_attack_conns,"` + // Start date + PeriodStartDate time.Time `json:"period_start_date,"` +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index c131f574b..ffad7e13f 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -2,8 +2,6 @@ package antiddos import ( "reflect" - "strconv" - "time" "github.com/opentelekomcloud/gophertelekomcloud" ) @@ -156,34 +154,3 @@ func Update(client *golangsdk.ServiceClient, floatingIpId string, opts UpdateOpt }) return } - -type WeeklyReportOpts struct { - // Start date of a seven-day period - PeriodStartDate time.Time `q:""` - // PeriodStartDate string `q:"period_start_date"` -} - -type WeeklyReportOptsBuilder interface { - ToWeeklyReportQuery() (string, error) -} - -func (opts WeeklyReportOpts) ToWeeklyReportQuery() (string, error) { - return "?period_start_date=" + strconv.FormatInt(opts.PeriodStartDate.Unix()*1000, 10), nil // q.String(), err -} - -func WeeklyReport(client *golangsdk.ServiceClient, opts WeeklyReportOptsBuilder) (r WeeklyReportResult) { - url := WeeklyReportURL(client) - if opts != nil { - query, err := opts.ToWeeklyReportQuery() - if err != nil { - r.Err = err - return - } - url += query - } - - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index 814f1dfe4..632a9821c 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -134,52 +134,8 @@ type UpdateResponse struct { TaskId string `json:"task_id,"` } -type WeeklyReportResult struct { - commonResult -} - -func (r WeeklyReportResult) Extract() (*WeeklyReportResponse, error) { - var response WeeklyReportResponse - err := r.ExtractInto(&response) - return &response, err -} - -type WeekData struct { - // Number of DDoS attacks intercepted - DdosInterceptTimes int `json:"ddos_intercept_times,"` - - // Number of DDoS blackholes - DdosBlackholeTimes int `json:"ddos_blackhole_times,"` - - // Maximum attack traffic - MaxAttackBps int `json:"max_attack_bps,"` - - // Maximum number of attack connections - MaxAttackConns int `json:"max_attack_conns,"` - - // Start date - PeriodStartDate time.Time `json:"period_start_date,"` -} - -type WeeklyReportResponse struct { - // Number of DDoS attacks intercepted in a week - DdosInterceptTimes int `json:"ddos_intercept_times,"` - - // Number of DDoS attacks intercepted in a week - Weekdata []WeekData `json:"-"` - - // Top 10 attacked IP addresses - Top10 []struct { - // EIP - FloatingIpAddress string `json:"floating_ip_address,"` - - // Number of DDoS attacks intercepted, including cleaning operations and blackholes - Times int `json:"times,"` - } `json:"top10,"` -} - -func (r *WeeklyReportResponse) UnmarshalJSON(b []byte) error { - type tmp WeeklyReportResponse +func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { + type tmp ListWeeklyReportsResponse var s struct { tmp Weekdata []struct { @@ -204,13 +160,13 @@ func (r *WeeklyReportResponse) UnmarshalJSON(b []byte) error { return err } - *r = WeeklyReportResponse(s.tmp) + *r = ListWeeklyReportsResponse(s.tmp) r.Weekdata = make([]WeekData, len(s.Weekdata)) for idx, val := range s.Weekdata { r.Weekdata[idx] = WeekData{ - DdosInterceptTimes: val.DdosBlackholeTimes, - DdosBlackholeTimes: val.DdosBlackholeTimes, + DDosInterceptTimes: val.DdosBlackholeTimes, + DDosBlackholeTimes: val.DdosBlackholeTimes, MaxAttackBps: val.MaxAttackBps, MaxAttackConns: val.MaxAttackConns, PeriodStartDate: time.Unix(val.PeriodStartDate/1000, 0).UTC(), diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 3cb72b8b7..1763eb49a 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -25,7 +25,3 @@ func GetTaskURL(c *golangsdk.ServiceClient) string { func UpdateURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } - -func WeeklyReportURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL("antiddos", "weekly") -} From 7aa6f9f4f6963ea9e50f8a2110244bfcb8ff9ec9 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:24:51 +0200 Subject: [PATCH 07/26] ShowDDos --- acceptance/openstack/antiddos/fixtures.go | 2 +- .../openstack/antiddos/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- openstack/antiddos/v1/antiddos/requests.go | 8 ----- openstack/antiddos/v1/antiddos/results.go | 27 -------------- openstack/antiddos/v1/antiddos/show_ddos.go | 35 +++++++++++++++++++ 6 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/show_ddos.go diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index fa3329ea0..a0d870bab 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -70,7 +70,7 @@ func HandleDeleteSuccessfully(t *testing.T) { }) } -var GetResponse = antiddos.GetResponse{ +var GetResponse = antiddos.ShowDDosResponse{ EnableL7: true, TrafficPosId: 1, HttpRequestPosId: 2, diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 73b9e6322..99ed3331f 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -44,7 +44,7 @@ func TestGet(t *testing.T) { HandleGetSuccessfully(t) floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ShowDDos(client.ServiceClient(), floatingIpId) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &GetResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index b124b031e..6fe2f7e5a 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -48,7 +48,7 @@ Example to disable the Anti-DDoS traffic cleaning defense. Example to query configured Anti-DDoS defense policies. floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Get(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ShowDDos(client.ServiceClient(), floatingIpId).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index ffad7e13f..ca5638030 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -57,14 +57,6 @@ func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResul return } -func Get(client *golangsdk.ServiceClient, floatingIpId string) (r GetResult) { - url := GetURL(client, floatingIpId) - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - func GetStatus(client *golangsdk.ServiceClient, floatingIpId string) (r GetStatusResult) { url := GetStatusURL(client, floatingIpId) _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index 632a9821c..5003a3f44 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -53,33 +53,6 @@ type DeleteResponse struct { TaskId string `json:"task_id,"` } -type GetResult struct { - commonResult -} - -func (r GetResult) Extract() (*GetResponse, error) { - var response GetResponse - err := r.ExtractInto(&response) - return &response, err -} - -type GetResponse struct { - // Whether L7 defense has been enabled - EnableL7 bool `json:"enable_L7,"` - - // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` - - // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` - - // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - - // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` -} - type GetStatusResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/show_ddos.go b/openstack/antiddos/v1/antiddos/show_ddos.go new file mode 100644 index 000000000..e562717cc --- /dev/null +++ b/openstack/antiddos/v1/antiddos/show_ddos.go @@ -0,0 +1,35 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ShowDDosResponse, error) { + // GET /v1/{project_id}/antiddos/{floating_ip_id} + raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId), nil, nil) + if err != nil { + return nil, err + } + + var res ShowDDosResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type ShowDDosResponse struct { + // Whether L7 defense has been enabled + EnableL7 bool `json:"enable_L7,"` + // Position ID of traffic. The value ranges from 1 to 9. + TrafficPosId int `json:"traffic_pos_id,"` + // Position ID of number of HTTP requests. The value ranges from 1 to 15. + HttpRequestPosId int `json:"http_request_pos_id,"` + // Position ID of access limit during cleaning. The value ranges from 1 to 8. + CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + // Application type ID. Possible values: 0 1 + AppTypeId int `json:"app_type_id,"` +} From 653eed07314e80e990cc00c5c42325946925efee Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:35:42 +0200 Subject: [PATCH 08/26] ShowDDosStatus --- .../openstack/antiddos/requests_test.go | 2 +- openstack/antiddos/v1/antiddos/doc.go | 2 +- openstack/antiddos/v1/antiddos/requests.go | 8 ------- openstack/antiddos/v1/antiddos/results.go | 15 ------------ .../antiddos/v1/antiddos/show_ddos_status.go | 24 +++++++++++++++++++ openstack/antiddos/v1/antiddos/url.go | 8 ------- 6 files changed, 26 insertions(+), 33 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/show_ddos_status.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 99ed3331f..efe6fed68 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -126,7 +126,7 @@ func TestGetStatus(t *testing.T) { HandleGetStatusSuccessfully(t) floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ShowDDosStatus(client.ServiceClient(), floatingIpId) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &GetStatusResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go index 6fe2f7e5a..74c345690 100644 --- a/openstack/antiddos/v1/antiddos/doc.go +++ b/openstack/antiddos/v1/antiddos/doc.go @@ -56,7 +56,7 @@ Example to query configured Anti-DDoS defense policies. Example to query the defense status of a specified EIP. floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.GetStatus(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.ShowDDosStatus(client.ServiceClient(), floatingIpId).Extract() if err != nil { panic(err) } diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index ca5638030..403cdafdf 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -57,14 +57,6 @@ func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResul return } -func GetStatus(client *golangsdk.ServiceClient, floatingIpId string) (r GetStatusResult) { - url := GetStatusURL(client, floatingIpId) - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - type GetTaskOpts struct { // Task ID (nonnegative integer) character string TaskId string `q:"task_id"` diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index 5003a3f44..ab7290b60 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -53,21 +53,6 @@ type DeleteResponse struct { TaskId string `json:"task_id,"` } -type GetStatusResult struct { - commonResult -} - -func (r GetStatusResult) Extract() (*GetStatusResponse, error) { - var response GetStatusResponse - err := r.ExtractInto(&response) - return &response, err -} - -type GetStatusResponse struct { - // Defense status - Status string `json:"status,"` -} - type GetTaskResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/show_ddos_status.go b/openstack/antiddos/v1/antiddos/show_ddos_status.go new file mode 100644 index 000000000..16afe9d34 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/show_ddos_status.go @@ -0,0 +1,24 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowDDosStatus(client *golangsdk.ServiceClient, floatingIpId string) (string, error) { + // GET /v1/{project_id}/antiddos/{floating_ip_id}/status + raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId, "status"), nil, nil) + if err != nil { + return "", err + } + + var res struct { + Status string `json:"status"` + } + err = extract.Into(raw, &res) + if err != nil { + return "", err + } + + return res.Status, err +} diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index 1763eb49a..f70b8026c 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -10,14 +10,6 @@ func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } -func GetURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId) -} - -func GetStatusURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId, "status") -} - func GetTaskURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("query_task_status") } From cfa844ba8d249861f34b6741509986958bfe3a87 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:39:41 +0200 Subject: [PATCH 09/26] UpdateDDos --- .../openstack/antiddos/requests_test.go | 4 +- openstack/antiddos/v1/antiddos/doc.go | 113 ------------------ openstack/antiddos/v1/antiddos/requests.go | 42 ------- openstack/antiddos/v1/antiddos/results.go | 21 ---- openstack/antiddos/v1/antiddos/update_ddos.go | 49 ++++++++ openstack/antiddos/v1/antiddos/url.go | 4 - 6 files changed, 51 insertions(+), 182 deletions(-) delete mode 100644 openstack/antiddos/v1/antiddos/doc.go create mode 100644 openstack/antiddos/v1/antiddos/update_ddos.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index efe6fed68..9e8bb3b38 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -54,7 +54,7 @@ func TestUpdate(t *testing.T) { defer th.TeardownHTTP() HandleUpdateSuccessfully(t) - updateOpt := antiddos.UpdateOpts{ + updateOpt := antiddos.UpdateDDosOpts{ EnableL7: true, TrafficPosId: 1, HttpRequestPosId: 2, @@ -63,7 +63,7 @@ func TestUpdate(t *testing.T) { } floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract() + actual, err := antiddos.UpdateDDos(client.ServiceClient(), floatingIpId, updateOpt) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &UpdateResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/doc.go b/openstack/antiddos/v1/antiddos/doc.go deleted file mode 100644 index 74c345690..000000000 --- a/openstack/antiddos/v1/antiddos/doc.go +++ /dev/null @@ -1,113 +0,0 @@ -/* -Package antiddos -The Anti-DDoS traffic cleaning service (Anti-DDoS for short) defends resources (Elastic Cloud Servers (ECSs), -Elastic Load Balance (ELB) instances, and Bare Metal Servers (BMSs)) on OpenTelekomCloud against network- -and application-layer distributed denial of service (DDoS) attacks and sends alarms immediately when detecting an attack. -In addition, Anti-DDoS improves the utilization of bandwidth and ensures the stable running of users' services. - -Example to update the Anti-DDoS defense policy of a specified EIP. - - updateOpt := antiddos.UpdateOpts{ - EnableL7: true, - TrafficPosId: 1, - HttpRequestPosId: 2, - CleaningAccessPosId: 3, - AppTypeId: 1, - } - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Update(client.ServiceClient(), floatingIpId, updateOpt).Extract() - if err != nil { - panic(err) - } - -Example to enable the Anti-DDoS traffic cleaning defense. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract() - if err != nil { - panic(err) - } - -Example to query the traffic of a specified EIP in the last 24 hours. Traffic is detected in five-minute intervals. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListDailyReport(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } - -Example to disable the Anti-DDoS traffic cleaning defense. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } - -Example to query configured Anti-DDoS defense policies. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ShowDDos(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } - -Example to query the defense status of a specified EIP. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ShowDDosStatus(client.ServiceClient(), floatingIpId).Extract() - if err != nil { - panic(err) - } - -Example to query the execution status of a specified Anti-DDoS configuration task. - - actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{ - TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", - }).Extract() - if err != nil { - panic(err) - } - -Example to query optional Anti-DDoS defense policies. - - actual, err := antiddos.ListNewConfigs(client.ServiceClient()).Extract() - if err != nil { - panic(err) - } - -Example to query events of a specified EIP in the last 24 hours. - - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.ListDailyLogs(client.ServiceClient(), floatingIpId, antiddos.ListDailyLogsOps{ - Limit: 2, - Offset: 1, - SortDir: "asc", - }).Extract() - if err != nil { - panic(err) - } - -Example to query the defense statuses of all EIPs. - - listOpt := antiddos.ListDDosStatusOpts{ - Limit: 2, - Offset: 1, - Status: "notConfig", - Ip: "49.", - } - - actual, err := antiddos.ListDDosStatus(client.ServiceClient(), listOpt).Extract() - if err != nil { - panic(err) - } - -Example to query weekly defense statistics about all your EIPs. - - actual, err := antiddos.ListWeeklyReports(client.ServiceClient(), antiddos.ListWeeklyReportsOpts{}).Extract() - if err != nil { - panic(err) - } -*/ -package antiddos diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index 403cdafdf..b901c0ea6 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -96,45 +96,3 @@ func getStructField(v *DDosStatus, field string) string { f := reflect.Indirect(r).FieldByName(field) return f.String() } - -type UpdateOpts struct { - // Whether to enable L7 defense - EnableL7 bool `json:"enable_L7,"` - - // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` - - // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` - - // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - - // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` -} - -type UpdateOptsBuilder interface { - ToUpdateMap() (map[string]interface{}, error) -} - -func (opts UpdateOpts) ToUpdateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "") - if err != nil { - return nil, err - } - return b, nil -} - -func Update(client *golangsdk.ServiceClient, floatingIpId string, opts UpdateOptsBuilder) (r UpdateResult) { - b, err := opts.ToUpdateMap() - if err != nil { - r.Err = err - return - } - - _, r.Err = client.Put(UpdateURL(client, floatingIpId), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index ab7290b60..ef57fbf9e 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -71,27 +71,6 @@ type GetTaskResponse struct { TaskMsg string `json:"task_msg,"` } -type UpdateResult struct { - commonResult -} - -func (r UpdateResult) Extract() (*UpdateResponse, error) { - var response UpdateResponse - err := r.ExtractInto(&response) - return &response, err -} - -type UpdateResponse struct { - // Internal error code - ErrorCode string `json:"error_code,"` - - // Internal error description - ErrorDescription string `json:"error_description,"` - - // ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused. - TaskId string `json:"task_id,"` -} - func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { type tmp ListWeeklyReportsResponse var s struct { diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go new file mode 100644 index 000000000..be4d5c41a --- /dev/null +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -0,0 +1,49 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type UpdateDDosOpts struct { + // Whether to enable L7 defense + EnableL7 bool `json:"enable_L7,"` + // Position ID of traffic. The value ranges from 1 to 9. + TrafficPosId int `json:"traffic_pos_id,"` + // Position ID of number of HTTP requests. The value ranges from 1 to 15. + HttpRequestPosId int `json:"http_request_pos_id,"` + // Position ID of access limit during cleaning. The value ranges from 1 to 8. + CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + // Application type ID. Possible values: 0 1 + AppTypeId int `json:"app_type_id,"` +} + +func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts UpdateDDosOpts) (*UpdateResponse, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + // PUT /v1/{project_id}/antiddos/{floating_ip_id} + raw, err := client.Put(client.ServiceURL("antiddos", floatingIpId), b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + + var res UpdateResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type UpdateResponse struct { + // Internal error code + ErrorCode string `json:"error_code,"` + // Internal error description + ErrorDescription string `json:"error_description,"` + // ID of a task. This ID can be used to query the status of the task. + // This field is reserved for use in task auditing later. It is temporarily unused. + TaskId string `json:"task_id,"` +} diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index f70b8026c..d35a89d9f 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -13,7 +13,3 @@ func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string { func GetTaskURL(c *golangsdk.ServiceClient) string { return c.ServiceURL("query_task_status") } - -func UpdateURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId) -} From 9a35deb3eb51a2cbeb80302d0ae870e5392d2be3 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:49:05 +0200 Subject: [PATCH 10/26] ShowAlertConfig --- .../v2/warnalert/show_alert_config.go | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 openstack/antiddos/v2/warnalert/show_alert_config.go diff --git a/openstack/antiddos/v2/warnalert/show_alert_config.go b/openstack/antiddos/v2/warnalert/show_alert_config.go new file mode 100644 index 000000000..2359f264f --- /dev/null +++ b/openstack/antiddos/v2/warnalert/show_alert_config.go @@ -0,0 +1,49 @@ +package warnalert + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowAlertConfig(client *golangsdk.ServiceClient) (*ShowAlertConfigResponse, error) { + // GET /v2/{project_id}/warnalert/alertconfig/query + raw, err := client.Get(client.ServiceURL("warnalert", "alertconfig", "query"), nil, nil) + + var res ShowAlertConfigResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type ShowAlertConfigResponse struct { + // ID of an alarm group + TopicUrn *string `json:"topic_urn"` + // Description of an alarm group + DisplayName *string `json:"display_name"` + // Alarm configuration + WarnConfig AlertConfigRespWarnConfig `json:"warn_config"` +} + +type AlertConfigRespWarnConfig struct { + // DDoS attacks + AntiDDoS bool `json:"antiDDoS"` + // Web shells + BackDoors bool `json:"back_doors"` + // Brute force cracking (system logins, FTP, and DB) + BruceForce bool `json:"bruce_force"` + // Overly high rights of a database process + HighPrivilege bool `json:"high_privilege"` + // Alarms about remote logins + RemoteLogin bool `json:"remote_login"` + // Possible values: + // 0: indicates that alarms are sent once a day. + // 1: indicates that alarms are sent once every half hour. + SendFrequency int `json:"send_frequency"` + // Reserved field + Waf bool `json:"waf,omitempty"` + // Weak passwords (system and database) + WeakPassword bool `json:"weak_password"` +} From 3c23073a05ddf9ba90fad743c7afa1683782a671 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 16:55:43 +0200 Subject: [PATCH 11/26] CreateDefaultConfig --- .../openstack/antiddos/requests_test.go | 6 +-- .../v1/antiddos/create_default_config.go | 49 +++++++++++++++++++ openstack/antiddos/v1/antiddos/requests.go | 42 ---------------- openstack/antiddos/v1/antiddos/results.go | 21 -------- openstack/antiddos/v1/antiddos/show_ddos.go | 17 +------ openstack/antiddos/v1/antiddos/update_ddos.go | 15 +----- openstack/antiddos/v1/antiddos/url.go | 4 -- 7 files changed, 55 insertions(+), 99 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/create_default_config.go diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 9e8bb3b38..5cc4a4d87 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -13,7 +13,7 @@ func TestCreate(t *testing.T) { defer th.TeardownHTTP() HandleCreateSuccessfully(t) - createOpt := antiddos.CreateOpts{ + createOpt := antiddos.ConfigOpts{ EnableL7: true, TrafficPosId: 1, HttpRequestPosId: 2, @@ -22,7 +22,7 @@ func TestCreate(t *testing.T) { } floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Create(client.ServiceClient(), floatingIpId, createOpt).Extract() + actual, err := antiddos.CreateDefaultConfig(client.ServiceClient(), floatingIpId, createOpt) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &CreateResponse, actual) } @@ -54,7 +54,7 @@ func TestUpdate(t *testing.T) { defer th.TeardownHTTP() HandleUpdateSuccessfully(t) - updateOpt := antiddos.UpdateDDosOpts{ + updateOpt := antiddos.ConfigOpts{ EnableL7: true, TrafficPosId: 1, HttpRequestPosId: 2, diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go new file mode 100644 index 000000000..852986c08 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -0,0 +1,49 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ConfigOpts struct { + // Whether to enable L7 defense + EnableL7 bool `json:"enable_L7,"` + // Position ID of traffic. The value ranges from 1 to 9. + TrafficPosId int `json:"traffic_pos_id,"` + // Position ID of number of HTTP requests. The value ranges from 1 to 15. + HttpRequestPosId int `json:"http_request_pos_id,"` + // Position ID of access limit during cleaning. The value ranges from 1 to 8. + CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + // Application type ID. Possible values: 0 1 + AppTypeId int `json:"app_type_id,"` +} + +func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*CreateResponse, error) { + b, err := golangsdk.BuildRequestBody(opts, "") + if err != nil { + return nil, err + } + + // POST /v1/{project_id}/antiddos/default-config + raw, err := client.Post(client.ServiceURL("antiddos", floatingIpId), b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + + var res CreateResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type CreateResponse struct { + // Internal error code + ErrorCode string `json:"error_code,"` + // Internal error description + ErrorDescription string `json:"error_description,"` + // ID of a task. This ID can be used to query the status of the task. + // This field is reserved for use in task auditing later. It is temporarily unused. + TaskId string `json:"task_id,"` +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go index b901c0ea6..2c50fb4ac 100644 --- a/openstack/antiddos/v1/antiddos/requests.go +++ b/openstack/antiddos/v1/antiddos/requests.go @@ -6,48 +6,6 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud" ) -type CreateOpts struct { - // Whether to enable L7 defense - EnableL7 bool `json:"enable_L7,"` - - // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` - - // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` - - // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - - // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` -} - -type CreateOptsBuilder interface { - ToCreateMap() (map[string]interface{}, error) -} - -func (opts CreateOpts) ToCreateMap() (map[string]interface{}, error) { - b, err := golangsdk.BuildRequestBody(opts, "") - if err != nil { - return nil, err - } - return b, nil -} - -func Create(client *golangsdk.ServiceClient, floatingIpId string, opts CreateOptsBuilder) (r CreateResult) { - b, err := opts.ToCreateMap() - if err != nil { - r.Err = err - return - } - - _, r.Err = client.Post(CreateURL(client, floatingIpId), b, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResult) { url := DeleteURL(client, floatingIpId) _, r.Err = client.Delete(url, &golangsdk.RequestOpts{ diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index ef57fbf9e..f59b3e99a 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -11,27 +11,6 @@ type commonResult struct { golangsdk.Result } -type CreateResult struct { - commonResult -} - -func (r CreateResult) Extract() (*CreateResponse, error) { - var response CreateResponse - err := r.ExtractInto(&response) - return &response, err -} - -type CreateResponse struct { - // Internal error code - ErrorCode string `json:"error_code,"` - - // Internal error description - ErrorDescription string `json:"error_description,"` - - // ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused. - TaskId string `json:"task_id,"` -} - type DeleteResult struct { commonResult } diff --git a/openstack/antiddos/v1/antiddos/show_ddos.go b/openstack/antiddos/v1/antiddos/show_ddos.go index e562717cc..15664e5ad 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos.go +++ b/openstack/antiddos/v1/antiddos/show_ddos.go @@ -5,14 +5,14 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ShowDDosResponse, error) { +func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ConfigOpts, error) { // GET /v1/{project_id}/antiddos/{floating_ip_id} raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId), nil, nil) if err != nil { return nil, err } - var res ShowDDosResponse + var res ConfigOpts err = extract.Into(raw, &res) if err != nil { return nil, err @@ -20,16 +20,3 @@ func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ShowDDosRe return &res, nil } - -type ShowDDosResponse struct { - // Whether L7 defense has been enabled - EnableL7 bool `json:"enable_L7,"` - // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` - // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` - // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` -} diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index be4d5c41a..fc26452b2 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -5,20 +5,7 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -type UpdateDDosOpts struct { - // Whether to enable L7 defense - EnableL7 bool `json:"enable_L7,"` - // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` - // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` - // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` -} - -func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts UpdateDDosOpts) (*UpdateResponse, error) { +func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*UpdateResponse, error) { b, err := golangsdk.BuildRequestBody(opts, "") if err != nil { return nil, err diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go index d35a89d9f..7790eba0d 100644 --- a/openstack/antiddos/v1/antiddos/url.go +++ b/openstack/antiddos/v1/antiddos/url.go @@ -2,10 +2,6 @@ package antiddos import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -func CreateURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId) -} - func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string { return c.ServiceURL("antiddos", floatingIpId) } From 33194646aa96b85cd702bd503bc2df98488f9c8c Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 17:17:44 +0200 Subject: [PATCH 12/26] ShowNewTaskStatus --- acceptance/openstack/antiddos/fixtures.go | 6 +- .../openstack/antiddos/requests_test.go | 4 +- .../v1/antiddos/create_default_config.go | 8 +- .../v1/antiddos/delete_default_config.go | 24 +++++ .../antiddos/v1/antiddos/list_ddos_status.go | 8 ++ .../v1/antiddos/list_weekly_reports.go | 42 ++++++++- openstack/antiddos/v1/antiddos/requests.go | 56 ----------- openstack/antiddos/v1/antiddos/results.go | 92 ------------------- .../v1/antiddos/show_new_task_status.go | 39 ++++++++ openstack/antiddos/v1/antiddos/update_ddos.go | 14 +-- openstack/antiddos/v1/antiddos/url.go | 11 --- service_client.go | 7 ++ 12 files changed, 130 insertions(+), 181 deletions(-) create mode 100644 openstack/antiddos/v1/antiddos/delete_default_config.go delete mode 100644 openstack/antiddos/v1/antiddos/requests.go create mode 100644 openstack/antiddos/v1/antiddos/show_new_task_status.go delete mode 100644 openstack/antiddos/v1/antiddos/url.go diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index a0d870bab..3e075eac7 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -29,7 +29,7 @@ const CreateRequest string = ` } ` -var CreateResponse = antiddos.CreateResponse{ +var CreateResponse = antiddos.TaskResponse{ ErrorCode: "10000000", ErrorDescription: "The task has been received and is being handled", TaskId: "82463800-70fe-4cba-9a96-06175e246ab3", @@ -46,7 +46,7 @@ func HandleCreateSuccessfully(t *testing.T) { }) } -var DeleteResponse = antiddos.DeleteResponse{ +var DeleteResponse = antiddos.TaskResponse{ ErrorCode: "10000000", ErrorDescription: "The task has been received and is being handled", TaskId: "f732e7f1-26b2-40f1-85e9-a8a4d3a43038", @@ -738,7 +738,7 @@ var GetTaskOutput = ` } ` -var GetTaskResponse = antiddos.GetTaskResponse{ +var GetTaskResponse = antiddos.ShowNewTaskStatusResponse{ TaskStatus: "running", TaskMsg: "ABC", } diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index 5cc4a4d87..acbed9c6f 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -33,7 +33,7 @@ func TestDelete(t *testing.T) { HandleDeleteSuccessfully(t) floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.Delete(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.DeleteDefaultConfig(client.ServiceClient(), floatingIpId).Extract() th.AssertNoErr(t, err) th.CheckDeepEquals(t, &DeleteResponse, actual) } @@ -147,7 +147,7 @@ func TestGetTask(t *testing.T) { defer th.TeardownHTTP() HandleGetTaskSuccessfully(t) - actual, err := antiddos.GetTask(client.ServiceClient(), antiddos.GetTaskOpts{ + actual, err := antiddos.ShowNewTaskStatus(client.ServiceClient(), antiddos.ShowNewTaskStatusOpts{ TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", }).Extract() th.AssertNoErr(t, err) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 852986c08..5d09cc844 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -18,18 +18,18 @@ type ConfigOpts struct { AppTypeId int `json:"app_type_id,"` } -func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*CreateResponse, error) { +func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*TaskResponse, error) { b, err := golangsdk.BuildRequestBody(opts, "") if err != nil { return nil, err } - // POST /v1/{project_id}/antiddos/default-config + // POST /v1/{project_id}/antiddos/default/config raw, err := client.Post(client.ServiceURL("antiddos", floatingIpId), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) - var res CreateResponse + var res TaskResponse err = extract.Into(raw, &res) if err != nil { return nil, err @@ -38,7 +38,7 @@ func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, o return &res, nil } -type CreateResponse struct { +type TaskResponse struct { // Internal error code ErrorCode string `json:"error_code,"` // Internal error description diff --git a/openstack/antiddos/v1/antiddos/delete_default_config.go b/openstack/antiddos/v1/antiddos/delete_default_config.go new file mode 100644 index 000000000..656b2f366 --- /dev/null +++ b/openstack/antiddos/v1/antiddos/delete_default_config.go @@ -0,0 +1,24 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func DeleteDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string) (*TaskResponse, error) { + // DELETE /v1/{project_id}/antiddos/default-config + raw, err := client.Delete(client.ServiceURL("antiddos", floatingIpId), &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + if err != nil { + return nil, err + } + + var res TaskResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index 7750afec2..1f41c865e 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -1,6 +1,8 @@ package antiddos import ( + "reflect" + "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) @@ -86,3 +88,9 @@ func FilterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosS return refinedDdosStatus, nil } + +func getStructField(v *DDosStatus, field string) string { + r := reflect.ValueOf(v) + f := reflect.Indirect(r).FieldByName(field) + return f.String() +} diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index e15da7104..7ea0d5191 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -1,6 +1,7 @@ package antiddos import ( + "encoding/json" "strconv" "time" @@ -9,6 +10,7 @@ import ( ) func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Time) (*ListWeeklyReportsResponse, error) { + // GET /v1/{project_id}/antiddos/weekly raw, err := client.Get( client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate.Unix()*1000, 10), nil, nil) @@ -31,7 +33,7 @@ type ListWeeklyReportsResponse struct { Top10 []struct { // EIP FloatingIpAddress string `json:"floating_ip_address,"` - // Number of DDoS attacks intercepted, including cleaning operations and blackholes + // Number of DDoS attacks intercepted, including cleaning operations and black-holes Times int `json:"times,"` } `json:"top10,"` } @@ -48,3 +50,41 @@ type WeekData struct { // Start date PeriodStartDate time.Time `json:"period_start_date,"` } + +func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { + type tmp ListWeeklyReportsResponse + var s struct { + tmp + Weekdata []struct { + // Number of DDoS attacks intercepted + DDosInterceptTimes int `json:"ddos_intercept_times,"` + // Number of DDoS blackholes + DDosBlackholeTimes int `json:"ddos_blackhole_times,"` + // Maximum attack traffic + MaxAttackBps int `json:"max_attack_bps,"` + // Maximum number of attack connections + MaxAttackConns int `json:"max_attack_conns,"` + // Start date + PeriodStartDate int64 `json:"period_start_date,"` + } `json:"weekdata,"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + *r = ListWeeklyReportsResponse(s.tmp) + r.Weekdata = make([]WeekData, len(s.Weekdata)) + + for idx, val := range s.Weekdata { + r.Weekdata[idx] = WeekData{ + DDosInterceptTimes: val.DDosBlackholeTimes, + DDosBlackholeTimes: val.DDosBlackholeTimes, + MaxAttackBps: val.MaxAttackBps, + MaxAttackConns: val.MaxAttackConns, + PeriodStartDate: time.Unix(val.PeriodStartDate/1000, 0).UTC(), + } + } + + return nil +} diff --git a/openstack/antiddos/v1/antiddos/requests.go b/openstack/antiddos/v1/antiddos/requests.go deleted file mode 100644 index 2c50fb4ac..000000000 --- a/openstack/antiddos/v1/antiddos/requests.go +++ /dev/null @@ -1,56 +0,0 @@ -package antiddos - -import ( - "reflect" - - "github.com/opentelekomcloud/gophertelekomcloud" -) - -func Delete(client *golangsdk.ServiceClient, floatingIpId string) (r DeleteResult) { - url := DeleteURL(client, floatingIpId) - _, r.Err = client.Delete(url, &golangsdk.RequestOpts{ - JSONResponse: &r.Body, - OkCodes: []int{200}, - }) - return -} - -type GetTaskOpts struct { - // Task ID (nonnegative integer) character string - TaskId string `q:"task_id"` -} - -type GetTaskOptsBuilder interface { - ToGetTaskQuery() (string, error) -} - -func (opts GetTaskOpts) ToGetTaskQuery() (string, error) { - q, err := golangsdk.BuildQueryString(opts) - if err != nil { - return "", err - } - return q.String(), err -} - -func GetTask(client *golangsdk.ServiceClient, opts GetTaskOptsBuilder) (r GetTaskResult) { - url := GetTaskURL(client) - if opts != nil { - query, err := opts.ToGetTaskQuery() - if err != nil { - r.Err = err - return - } - url += query - } - - _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ - OkCodes: []int{200}, - }) - return -} - -func getStructField(v *DDosStatus, field string) string { - r := reflect.ValueOf(v) - f := reflect.Indirect(r).FieldByName(field) - return f.String() -} diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go index f59b3e99a..e8b76c18b 100644 --- a/openstack/antiddos/v1/antiddos/results.go +++ b/openstack/antiddos/v1/antiddos/results.go @@ -1,93 +1 @@ package antiddos - -import ( - "encoding/json" - "time" - - golangsdk "github.com/opentelekomcloud/gophertelekomcloud" -) - -type commonResult struct { - golangsdk.Result -} - -type DeleteResult struct { - commonResult -} - -func (r DeleteResult) Extract() (*DeleteResponse, error) { - var response DeleteResponse - err := r.ExtractInto(&response) - return &response, err -} - -type DeleteResponse struct { - // Internal error code - ErrorCode string `json:"error_code,"` - - // Internal error description - ErrorDescription string `json:"error_description,"` - - // ID of a task. This ID can be used to query the status of the task. This field is reserved for use in task auditing later. It is temporarily unused. - TaskId string `json:"task_id,"` -} - -type GetTaskResult struct { - commonResult -} - -func (r GetTaskResult) Extract() (*GetTaskResponse, error) { - var response GetTaskResponse - err := r.ExtractInto(&response) - return &response, err -} - -type GetTaskResponse struct { - // Status of a task, which can be one of the following: success, failed, waiting, running, preprocess, ready - TaskStatus string `json:"task_status,"` - - // Additional information about a task - TaskMsg string `json:"task_msg,"` -} - -func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { - type tmp ListWeeklyReportsResponse - var s struct { - tmp - Weekdata []struct { - // Number of DDoS attacks intercepted - DdosInterceptTimes int `json:"ddos_intercept_times,"` - - // Number of DDoS blackholes - DdosBlackholeTimes int `json:"ddos_blackhole_times,"` - - // Maximum attack traffic - MaxAttackBps int `json:"max_attack_bps,"` - - // Maximum number of attack connections - MaxAttackConns int `json:"max_attack_conns,"` - - // Start date - PeriodStartDate int64 `json:"period_start_date,"` - } `json:"weekdata,"` - } - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - *r = ListWeeklyReportsResponse(s.tmp) - r.Weekdata = make([]WeekData, len(s.Weekdata)) - - for idx, val := range s.Weekdata { - r.Weekdata[idx] = WeekData{ - DDosInterceptTimes: val.DdosBlackholeTimes, - DDosBlackholeTimes: val.DdosBlackholeTimes, - MaxAttackBps: val.MaxAttackBps, - MaxAttackConns: val.MaxAttackConns, - PeriodStartDate: time.Unix(val.PeriodStartDate/1000, 0).UTC(), - } - } - - return nil -} diff --git a/openstack/antiddos/v1/antiddos/show_new_task_status.go b/openstack/antiddos/v1/antiddos/show_new_task_status.go new file mode 100644 index 000000000..93ac3de5b --- /dev/null +++ b/openstack/antiddos/v1/antiddos/show_new_task_status.go @@ -0,0 +1,39 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ShowNewTaskStatusOpts struct { + // Task ID (non-negative integer) character string + TaskId string `q:"task_id"` +} + +func ShowNewTaskStatus(client *golangsdk.ServiceClient, opts ShowNewTaskStatusOpts) (*ShowNewTaskStatusResponse, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return nil, err + } + + // GET /v1/{project_id}/query_task_status + raw, err := client.Get(client.ServiceURL("query_task_status")+q.String(), nil, nil) + if err != nil { + return nil, err + } + + var res ShowNewTaskStatusResponse + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} + +type ShowNewTaskStatusResponse struct { + // Status of a task, which can be one of the following: success, failed, waiting, running, preprocess, ready + TaskStatus string `json:"task_status,"` + // Additional information about a task + TaskMsg string `json:"task_msg,"` +} diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index fc26452b2..1740c7e76 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -5,7 +5,7 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*UpdateResponse, error) { +func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*TaskResponse, error) { b, err := golangsdk.BuildRequestBody(opts, "") if err != nil { return nil, err @@ -16,7 +16,7 @@ func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts Confi OkCodes: []int{200}, }) - var res UpdateResponse + var res TaskResponse err = extract.Into(raw, &res) if err != nil { return nil, err @@ -24,13 +24,3 @@ func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts Confi return &res, nil } - -type UpdateResponse struct { - // Internal error code - ErrorCode string `json:"error_code,"` - // Internal error description - ErrorDescription string `json:"error_description,"` - // ID of a task. This ID can be used to query the status of the task. - // This field is reserved for use in task auditing later. It is temporarily unused. - TaskId string `json:"task_id,"` -} diff --git a/openstack/antiddos/v1/antiddos/url.go b/openstack/antiddos/v1/antiddos/url.go deleted file mode 100644 index 7790eba0d..000000000 --- a/openstack/antiddos/v1/antiddos/url.go +++ /dev/null @@ -1,11 +0,0 @@ -package antiddos - -import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" - -func DeleteURL(c *golangsdk.ServiceClient, floatingIpId string) string { - return c.ServiceURL("antiddos", floatingIpId) -} - -func GetTaskURL(c *golangsdk.ServiceClient) string { - return c.ServiceURL("query_task_status") -} diff --git a/service_client.go b/service_client.go index fff874a94..1b493cdc7 100644 --- a/service_client.go +++ b/service_client.go @@ -64,6 +64,7 @@ func (client *ServiceClient) initReqOpts(_ string, JSONBody interface{}, JSONRes } // Get calls `Request` with the "GET" HTTP verb. def 200 +// JSONResponse Deprecated func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -73,6 +74,7 @@ func (client *ServiceClient) Get(url string, JSONResponse interface{}, opts *Req } // Post calls `Request` with the "POST" HTTP verb. def 201, 202 +// JSONResponse Deprecated func (client *ServiceClient) Post(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -82,6 +84,7 @@ func (client *ServiceClient) Post(url string, JSONBody interface{}, JSONResponse } // Put calls `Request` with the "PUT" HTTP verb. def 201, 202 +// JSONResponse Deprecated func (client *ServiceClient) Put(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -91,6 +94,7 @@ func (client *ServiceClient) Put(url string, JSONBody interface{}, JSONResponse } // Patch calls `Request` with the "PATCH" HTTP verb. def 200, 204 +// JSONResponse Deprecated func (client *ServiceClient) Patch(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -109,6 +113,7 @@ func (client *ServiceClient) Delete(url string, opts *RequestOpts) (*http.Respon } // DeleteWithBody calls `Request` with the "DELETE" HTTP verb. def 202, 204 +// Deprecated func (client *ServiceClient) DeleteWithBody(url string, JSONBody interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -118,6 +123,7 @@ func (client *ServiceClient) DeleteWithBody(url string, JSONBody interface{}, op } // DeleteWithResponse calls `Request` with the "DELETE" HTTP verb. def 202, 204 +// Deprecated func (client *ServiceClient) DeleteWithResponse(url string, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) @@ -127,6 +133,7 @@ func (client *ServiceClient) DeleteWithResponse(url string, JSONResponse interfa } // DeleteWithBodyResp calls `Request` with the "DELETE" HTTP verb. def 202, 204 +// Deprecated func (client *ServiceClient) DeleteWithBodyResp(url string, JSONBody interface{}, JSONResponse interface{}, opts *RequestOpts) (*http.Response, error) { if opts == nil { opts = new(RequestOpts) From 828316076fa6c04bfa5912ca8b46fcd16a38dd39 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 18:04:31 +0200 Subject: [PATCH 13/26] https://github.com/opentelekomcloud/gophertelekomcloud/issues/394 --- acceptance/openstack/antiddos/fixtures.go | 8 ++----- .../openstack/antiddos/requests_test.go | 10 ++++----- .../v1/antiddos/create_default_config.go | 22 +++++++++---------- .../v1/antiddos/delete_default_config.go | 4 ++-- openstack/antiddos/v1/antiddos/results.go | 1 - .../v1/antiddos/show_default_config.go | 22 +++++++++++++++++++ .../v1/antiddos/show_new_task_status.go | 4 ++-- 7 files changed, 43 insertions(+), 28 deletions(-) delete mode 100644 openstack/antiddos/v1/antiddos/results.go create mode 100644 openstack/antiddos/v1/antiddos/show_default_config.go diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index 3e075eac7..1ec8d52a4 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -70,7 +70,7 @@ func HandleDeleteSuccessfully(t *testing.T) { }) } -var GetResponse = antiddos.ShowDDosResponse{ +var GetResponse = antiddos.ConfigOpts{ EnableL7: true, TrafficPosId: 1, HttpRequestPosId: 2, @@ -116,7 +116,7 @@ const UpdateRequest string = ` } ` -var UpdateResponse = antiddos.UpdateResponse{ +var UpdateResponse = antiddos.TaskResponse{ ErrorCode: "10000000", ErrorDescription: "The task has been received and is being handled", TaskId: "82463800-70fe-4cba-9a96-06175e246ab3", @@ -641,10 +641,6 @@ func HandleListLogsSuccessfully(t *testing.T) { var GetStatusOutput = `{"status":"normal"}` -var GetStatusResponse = antiddos.GetStatusResponse{ - Status: "normal", -} - func HandleGetStatusSuccessfully(t *testing.T) { th.Mux.HandleFunc("/antiddos/82abaa86-8518-47db-8d63-ddf152824635/status", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "GET") diff --git a/acceptance/openstack/antiddos/requests_test.go b/acceptance/openstack/antiddos/requests_test.go index acbed9c6f..0a603f1f5 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/acceptance/openstack/antiddos/requests_test.go @@ -21,8 +21,7 @@ func TestCreate(t *testing.T) { AppTypeId: 1, } - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.CreateDefaultConfig(client.ServiceClient(), floatingIpId, createOpt) + actual, err := antiddos.CreateDefaultConfig(client.ServiceClient(), createOpt) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &CreateResponse, actual) } @@ -32,8 +31,7 @@ func TestDelete(t *testing.T) { defer th.TeardownHTTP() HandleDeleteSuccessfully(t) - floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" - actual, err := antiddos.DeleteDefaultConfig(client.ServiceClient(), floatingIpId).Extract() + actual, err := antiddos.DeleteDefaultConfig(client.ServiceClient()) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &DeleteResponse, actual) } @@ -128,7 +126,7 @@ func TestGetStatus(t *testing.T) { floatingIpId := "82abaa86-8518-47db-8d63-ddf152824635" actual, err := antiddos.ShowDDosStatus(client.ServiceClient(), floatingIpId) th.AssertNoErr(t, err) - th.CheckDeepEquals(t, &GetStatusResponse, actual) + th.CheckDeepEquals(t, "normal", actual) } func TestDailyReport(t *testing.T) { @@ -149,7 +147,7 @@ func TestGetTask(t *testing.T) { actual, err := antiddos.ShowNewTaskStatus(client.ServiceClient(), antiddos.ShowNewTaskStatusOpts{ TaskId: "4a4fefe7-34a1-40e2-a87c-16932af3ac4a", - }).Extract() + }) th.AssertNoErr(t, err) th.CheckDeepEquals(t, &GetTaskResponse, actual) } diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 5d09cc844..9d2d3ef84 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -7,25 +7,25 @@ import ( type ConfigOpts struct { // Whether to enable L7 defense - EnableL7 bool `json:"enable_L7,"` + EnableL7 bool `json:"enable_L7"` // Position ID of traffic. The value ranges from 1 to 9. - TrafficPosId int `json:"traffic_pos_id,"` + TrafficPosId int `json:"traffic_pos_id"` // Position ID of number of HTTP requests. The value ranges from 1 to 15. - HttpRequestPosId int `json:"http_request_pos_id,"` + HttpRequestPosId int `json:"http_request_pos_id"` // Position ID of access limit during cleaning. The value ranges from 1 to 8. - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + CleaningAccessPosId int `json:"cleaning_access_pos_id"` // Application type ID. Possible values: 0 1 - AppTypeId int `json:"app_type_id,"` + AppTypeId int `json:"app_type_id"` } -func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*TaskResponse, error) { +func CreateDefaultConfig(client *golangsdk.ServiceClient, opts ConfigOpts) (*TaskResponse, error) { b, err := golangsdk.BuildRequestBody(opts, "") if err != nil { return nil, err } - // POST /v1/{project_id}/antiddos/default/config - raw, err := client.Post(client.ServiceURL("antiddos", floatingIpId), b, nil, &golangsdk.RequestOpts{ + // POST /v1/{project_id}/antiddos/default-config + raw, err := client.Post(client.ServiceURL("antiddos", "default-config"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) @@ -40,10 +40,10 @@ func CreateDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string, o type TaskResponse struct { // Internal error code - ErrorCode string `json:"error_code,"` + ErrorCode string `json:"error_code"` // Internal error description - ErrorDescription string `json:"error_description,"` + ErrorDescription string `json:"error_description"` // ID of a task. This ID can be used to query the status of the task. // This field is reserved for use in task auditing later. It is temporarily unused. - TaskId string `json:"task_id,"` + TaskId string `json:"task_id"` } diff --git a/openstack/antiddos/v1/antiddos/delete_default_config.go b/openstack/antiddos/v1/antiddos/delete_default_config.go index 656b2f366..e70a2ee1e 100644 --- a/openstack/antiddos/v1/antiddos/delete_default_config.go +++ b/openstack/antiddos/v1/antiddos/delete_default_config.go @@ -5,9 +5,9 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -func DeleteDefaultConfig(client *golangsdk.ServiceClient, floatingIpId string) (*TaskResponse, error) { +func DeleteDefaultConfig(client *golangsdk.ServiceClient) (*TaskResponse, error) { // DELETE /v1/{project_id}/antiddos/default-config - raw, err := client.Delete(client.ServiceURL("antiddos", floatingIpId), &golangsdk.RequestOpts{ + raw, err := client.Delete(client.ServiceURL("antiddos", "default-config"), &golangsdk.RequestOpts{ OkCodes: []int{200}, }) if err != nil { diff --git a/openstack/antiddos/v1/antiddos/results.go b/openstack/antiddos/v1/antiddos/results.go deleted file mode 100644 index e8b76c18b..000000000 --- a/openstack/antiddos/v1/antiddos/results.go +++ /dev/null @@ -1 +0,0 @@ -package antiddos diff --git a/openstack/antiddos/v1/antiddos/show_default_config.go b/openstack/antiddos/v1/antiddos/show_default_config.go new file mode 100644 index 000000000..ae2bd8eaf --- /dev/null +++ b/openstack/antiddos/v1/antiddos/show_default_config.go @@ -0,0 +1,22 @@ +package antiddos + +import ( + "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowDefaultConfig(client *golangsdk.ServiceClient) (*ConfigOpts, error) { + // GET /v1/{project_id}/antiddos/default-config + raw, err := client.Get(client.ServiceURL("antiddos", "default-config"), nil, nil) + if err != nil { + return nil, err + } + + var res ConfigOpts + err = extract.Into(raw, &res) + if err != nil { + return nil, err + } + + return &res, nil +} diff --git a/openstack/antiddos/v1/antiddos/show_new_task_status.go b/openstack/antiddos/v1/antiddos/show_new_task_status.go index 93ac3de5b..a02522bb1 100644 --- a/openstack/antiddos/v1/antiddos/show_new_task_status.go +++ b/openstack/antiddos/v1/antiddos/show_new_task_status.go @@ -33,7 +33,7 @@ func ShowNewTaskStatus(client *golangsdk.ServiceClient, opts ShowNewTaskStatusOp type ShowNewTaskStatusResponse struct { // Status of a task, which can be one of the following: success, failed, waiting, running, preprocess, ready - TaskStatus string `json:"task_status,"` + TaskStatus string `json:"task_status"` // Additional information about a task - TaskMsg string `json:"task_msg,"` + TaskMsg string `json:"task_msg"` } From 74ec8ff891b5314caca816a5d883c3fb7ab85473 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 15 Aug 2022 18:12:50 +0200 Subject: [PATCH 14/26] if err != nil { return nil, err } --- openstack/antiddos/v1/antiddos/create_default_config.go | 3 +++ openstack/antiddos/v1/antiddos/list_daily_logs.go | 3 +++ openstack/antiddos/v1/antiddos/list_daily_report.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 9d2d3ef84..3f724f642 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -28,6 +28,9 @@ func CreateDefaultConfig(client *golangsdk.ServiceClient, opts ConfigOpts) (*Tas raw, err := client.Post(client.ServiceURL("antiddos", "default-config"), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) + if err != nil { + return nil, err + } var res TaskResponse err = extract.Into(raw, &res) diff --git a/openstack/antiddos/v1/antiddos/list_daily_logs.go b/openstack/antiddos/v1/antiddos/list_daily_logs.go index 3cedc2197..5cc7c02d3 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_logs.go +++ b/openstack/antiddos/v1/antiddos/list_daily_logs.go @@ -27,6 +27,9 @@ func ListDailyLogs(client *golangsdk.ServiceClient, floatingIpId string, opts Li // GET /v1/{project_id}/antiddos/{floating_ip_id}/logs raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId, "logs")+query.String(), nil, nil) + if err != nil { + return nil, err + } var res ListDailyLogsResponse err = extract.Into(raw, &res) diff --git a/openstack/antiddos/v1/antiddos/list_daily_report.go b/openstack/antiddos/v1/antiddos/list_daily_report.go index 08d372054..44c803b99 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_report.go +++ b/openstack/antiddos/v1/antiddos/list_daily_report.go @@ -8,6 +8,9 @@ import ( func ListDailyReport(client *golangsdk.ServiceClient, floatingIpId string) ([]Data, error) { // GET /v1/{project_id}/antiddos/{floating_ip_id}/daily raw, err := client.Get(client.ServiceURL("antiddos", floatingIpId, "daily"), nil, nil) + if err != nil { + return nil, err + } var res []Data err = extract.IntoSlicePtr(raw, &res, "data") From 6bc7240718c3a8d11e8cfc4bd3fe476afdc03737 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 Aug 2022 09:57:21 +0200 Subject: [PATCH 15/26] if err != nil { return nil, err } --- openstack/antiddos/v1/antiddos/list_ddos_status.go | 3 +++ openstack/antiddos/v1/antiddos/list_new_configs.go | 3 +++ openstack/antiddos/v1/antiddos/list_weekly_reports.go | 3 +++ openstack/antiddos/v1/antiddos/show_ddos_status.go | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index 1f41c865e..c0dff104b 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -42,6 +42,9 @@ func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([ // GET /v1/{project_id}/antiddos raw, err := client.Get(client.ServiceURL("antiddos")+q.String(), nil, nil) + if err != nil { + return nil, err + } var res ListStatusResponse err = extract.Into(raw, &res) diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go index 7e74499b2..a6836a428 100644 --- a/openstack/antiddos/v1/antiddos/list_new_configs.go +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -8,6 +8,9 @@ import ( func ListNewConfigs(client *golangsdk.ServiceClient) (*ListConfigsResponse, error) { // GET /v1/{project_id}/antiddos/query_config_list raw, err := client.Get(client.ServiceURL("antiddos", "query_config_list"), nil, nil) + if err != nil { + return nil, err + } var response ListConfigsResponse err = extract.Into(raw, &response) diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index 7ea0d5191..2b68c6872 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -14,6 +14,9 @@ func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Tim raw, err := client.Get( client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate.Unix()*1000, 10), nil, nil) + if err != nil { + return nil, err + } var res ListWeeklyReportsResponse err = extract.Into(raw, &res) diff --git a/openstack/antiddos/v1/antiddos/show_ddos_status.go b/openstack/antiddos/v1/antiddos/show_ddos_status.go index 16afe9d34..c43d79898 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/show_ddos_status.go @@ -20,5 +20,5 @@ func ShowDDosStatus(client *golangsdk.ServiceClient, floatingIpId string) (strin return "", err } - return res.Status, err + return res.Status, nil } From 5cc03576dfb92dd11639a8d297817b33d35c8647 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:08:19 +0200 Subject: [PATCH 16/26] .Body --- openstack/antiddos/v1/antiddos/create_default_config.go | 2 +- openstack/antiddos/v1/antiddos/delete_default_config.go | 2 +- openstack/antiddos/v1/antiddos/list_daily_logs.go | 2 +- openstack/antiddos/v1/antiddos/list_daily_report.go | 2 +- openstack/antiddos/v1/antiddos/list_ddos_status.go | 2 +- openstack/antiddos/v1/antiddos/list_new_configs.go | 2 +- openstack/antiddos/v1/antiddos/list_weekly_reports.go | 2 +- openstack/antiddos/v1/antiddos/show_ddos.go | 2 +- openstack/antiddos/v1/antiddos/show_ddos_status.go | 2 +- openstack/antiddos/v1/antiddos/show_default_config.go | 2 +- openstack/antiddos/v1/antiddos/show_new_task_status.go | 2 +- openstack/antiddos/v1/antiddos/update_ddos.go | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 3f724f642..836179aee 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -33,7 +33,7 @@ func CreateDefaultConfig(client *golangsdk.ServiceClient, opts ConfigOpts) (*Tas } var res TaskResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/delete_default_config.go b/openstack/antiddos/v1/antiddos/delete_default_config.go index e70a2ee1e..8f2dcbc69 100644 --- a/openstack/antiddos/v1/antiddos/delete_default_config.go +++ b/openstack/antiddos/v1/antiddos/delete_default_config.go @@ -15,7 +15,7 @@ func DeleteDefaultConfig(client *golangsdk.ServiceClient) (*TaskResponse, error) } var res TaskResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_daily_logs.go b/openstack/antiddos/v1/antiddos/list_daily_logs.go index 5cc7c02d3..4c997d633 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_logs.go +++ b/openstack/antiddos/v1/antiddos/list_daily_logs.go @@ -32,7 +32,7 @@ func ListDailyLogs(client *golangsdk.ServiceClient, floatingIpId string, opts Li } var res ListDailyLogsResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_daily_report.go b/openstack/antiddos/v1/antiddos/list_daily_report.go index 44c803b99..3d428fb7d 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_report.go +++ b/openstack/antiddos/v1/antiddos/list_daily_report.go @@ -13,7 +13,7 @@ func ListDailyReport(client *golangsdk.ServiceClient, floatingIpId string) ([]Da } var res []Data - err = extract.IntoSlicePtr(raw, &res, "data") + err = extract.IntoSlicePtr(raw.Body, &res, "data") if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index c0dff104b..6278ba4af 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -47,7 +47,7 @@ func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([ } var res ListStatusResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go index a6836a428..7cce09947 100644 --- a/openstack/antiddos/v1/antiddos/list_new_configs.go +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -13,7 +13,7 @@ func ListNewConfigs(client *golangsdk.ServiceClient) (*ListConfigsResponse, erro } var response ListConfigsResponse - err = extract.Into(raw, &response) + err = extract.Into(raw.Body, &response) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index 2b68c6872..f39171d71 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -19,7 +19,7 @@ func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Tim } var res ListWeeklyReportsResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/show_ddos.go b/openstack/antiddos/v1/antiddos/show_ddos.go index 15664e5ad..df1ecca8b 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos.go +++ b/openstack/antiddos/v1/antiddos/show_ddos.go @@ -13,7 +13,7 @@ func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ConfigOpts } var res ConfigOpts - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/show_ddos_status.go b/openstack/antiddos/v1/antiddos/show_ddos_status.go index c43d79898..e7c971853 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/show_ddos_status.go @@ -15,7 +15,7 @@ func ShowDDosStatus(client *golangsdk.ServiceClient, floatingIpId string) (strin var res struct { Status string `json:"status"` } - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return "", err } diff --git a/openstack/antiddos/v1/antiddos/show_default_config.go b/openstack/antiddos/v1/antiddos/show_default_config.go index ae2bd8eaf..89353c865 100644 --- a/openstack/antiddos/v1/antiddos/show_default_config.go +++ b/openstack/antiddos/v1/antiddos/show_default_config.go @@ -13,7 +13,7 @@ func ShowDefaultConfig(client *golangsdk.ServiceClient) (*ConfigOpts, error) { } var res ConfigOpts - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/show_new_task_status.go b/openstack/antiddos/v1/antiddos/show_new_task_status.go index a02522bb1..dca18ed12 100644 --- a/openstack/antiddos/v1/antiddos/show_new_task_status.go +++ b/openstack/antiddos/v1/antiddos/show_new_task_status.go @@ -23,7 +23,7 @@ func ShowNewTaskStatus(client *golangsdk.ServiceClient, opts ShowNewTaskStatusOp } var res ShowNewTaskStatusResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index 1740c7e76..65301cf76 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -17,7 +17,7 @@ func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts Confi }) var res TaskResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } From e86a672cfb9bfb1605a6773b3ee54bfe9119cb47 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:14:58 +0200 Subject: [PATCH 17/26] .Body --- openstack/antiddos/v1/antiddos/update_ddos.go | 3 +++ openstack/antiddos/v2/warnalert/show_alert_config.go | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index 65301cf76..a3ac7c728 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -15,6 +15,9 @@ func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts Confi raw, err := client.Put(client.ServiceURL("antiddos", floatingIpId), b, nil, &golangsdk.RequestOpts{ OkCodes: []int{200}, }) + if err != nil { + return nil, err + } var res TaskResponse err = extract.Into(raw.Body, &res) diff --git a/openstack/antiddos/v2/warnalert/show_alert_config.go b/openstack/antiddos/v2/warnalert/show_alert_config.go index 2359f264f..0aa4e0ca9 100644 --- a/openstack/antiddos/v2/warnalert/show_alert_config.go +++ b/openstack/antiddos/v2/warnalert/show_alert_config.go @@ -8,9 +8,12 @@ import ( func ShowAlertConfig(client *golangsdk.ServiceClient) (*ShowAlertConfigResponse, error) { // GET /v2/{project_id}/warnalert/alertconfig/query raw, err := client.Get(client.ServiceURL("warnalert", "alertconfig", "query"), nil, nil) + if err != nil { + return nil, err + } var res ShowAlertConfigResponse - err = extract.Into(raw, &res) + err = extract.Into(raw.Body, &res) if err != nil { return nil, err } @@ -20,9 +23,9 @@ func ShowAlertConfig(client *golangsdk.ServiceClient) (*ShowAlertConfigResponse, type ShowAlertConfigResponse struct { // ID of an alarm group - TopicUrn *string `json:"topic_urn"` + TopicUrn string `json:"topic_urn"` // Description of an alarm group - DisplayName *string `json:"display_name"` + DisplayName string `json:"display_name"` // Alarm configuration WarnConfig AlertConfigRespWarnConfig `json:"warn_config"` } From ad9b514aca719f828031218e57a8d235398a5156 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:37:07 +0200 Subject: [PATCH 18/26] remove , --- .../antiddos/v1/antiddos/list_daily_logs.go | 16 +++++----- .../antiddos/v1/antiddos/list_daily_report.go | 14 ++++----- .../antiddos/v1/antiddos/list_ddos_status.go | 12 ++++---- .../antiddos/v1/antiddos/list_new_configs.go | 22 +++++++------- .../v1/antiddos/list_weekly_reports.go | 30 +++++++++---------- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/list_daily_logs.go b/openstack/antiddos/v1/antiddos/list_daily_logs.go index 4c997d633..742f2befa 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_logs.go +++ b/openstack/antiddos/v1/antiddos/list_daily_logs.go @@ -42,24 +42,24 @@ func ListDailyLogs(client *golangsdk.ServiceClient, floatingIpId string, opts Li type ListDailyLogsResponse struct { // Total number of EIPs - Total int `json:"total,"` + Total int `json:"total"` // List of events - Logs []Logs `json:"logs,"` + Logs []Logs `json:"logs"` } type Logs struct { // Start time - StartTime int `json:"start_time,"` + StartTime int `json:"start_time"` // End time - EndTime int `json:"end_time,"` + EndTime int `json:"end_time"` // Defense status, the possible value of which is one of the following: // 1: indicates that traffic cleaning is underway. // 2: indicates that traffic is discarded. - Status int `json:"status,"` + Status int `json:"status"` // Traffic at the triggering point. - TriggerBps int `json:"trigger_bps,"` + TriggerBps int `json:"trigger_bps"` // Packet rate at the triggering point - TriggerPps int `json:"trigger_pps,"` + TriggerPps int `json:"trigger_pps"` // HTTP request rate at the triggering point - TriggerHttpPps int `json:"trigger_http_pps,"` + TriggerHttpPps int `json:"trigger_http_pps"` } diff --git a/openstack/antiddos/v1/antiddos/list_daily_report.go b/openstack/antiddos/v1/antiddos/list_daily_report.go index 3d428fb7d..f69edaa42 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_report.go +++ b/openstack/antiddos/v1/antiddos/list_daily_report.go @@ -23,17 +23,17 @@ func ListDailyReport(client *golangsdk.ServiceClient, floatingIpId string) ([]Da type Data struct { // Start time - PeriodStart int `json:"period_start,"` + PeriodStart int `json:"period_start"` // Inbound traffic (bit/s) - BpsIn int `json:"bps_in,"` + BpsIn int `json:"bps_in"` // Attack traffic (bit/s) - BpsAttack int `json:"bps_attack,"` + BpsAttack int `json:"bps_attack"` // Total traffic - TotalBps int `json:"total_bps,"` + TotalBps int `json:"total_bps"` // Inbound packet rate (number of packets per second) - PpsIn int `json:"pps_in,"` + PpsIn int `json:"pps_in"` // Attack packet rate (number of packets per second) - PpsAttack int `json:"pps_attack,"` + PpsAttack int `json:"pps_attack"` // Total packet rate - TotalPps int `json:"total_pps,"` + TotalPps int `json:"total_pps"` } diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index 6278ba4af..d0b126d73 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -25,13 +25,13 @@ type ListDDosStatusOpts struct { type DDosStatus struct { // Floating IP address - FloatingIpAddress string `json:"floating_ip_address,"` + FloatingIpAddress string `json:"floating_ip_address"` // ID of an EIP - FloatingIpId string `json:"floating_ip_id,"` + FloatingIpId string `json:"floating_ip_id"` // EIP type. - NetworkType string `json:"network_type,"` + NetworkType string `json:"network_type"` // Defense status - Status string `json:"status,"` + Status string `json:"status"` } func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([]DDosStatus, error) { @@ -57,9 +57,9 @@ func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([ type ListStatusResponse struct { // Total number of EIPs - Total int `json:"total,"` + Total int `json:"total"` // List of defense statuses - DDosStatus []DDosStatus `json:"ddosStatus,"` + DDosStatus []DDosStatus `json:"ddosStatus"` } func FilterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosStatus, error) { diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go index 7cce09947..dddb89d3f 100644 --- a/openstack/antiddos/v1/antiddos/list_new_configs.go +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -25,28 +25,28 @@ type ListConfigsResponse struct { // List of traffic limits TrafficLimitedList []struct { // Position ID of traffic - TrafficPosId int `json:"traffic_pos_id,"` + TrafficPosId int `json:"traffic_pos_id"` // Threshold of traffic per second (Mbit/s) - TrafficPerSecond int `json:"traffic_per_second,"` + TrafficPerSecond int `json:"traffic_per_second"` // Threshold of number of packets per second - PacketPerSecond int `json:"packet_per_second,"` - } `json:"traffic_limited_list,"` + PacketPerSecond int `json:"packet_per_second"` + } `json:"traffic_limited_list"` // List of HTTP limits HttpLimitedList []struct { // Position ID of number of HTTP requests - HttpRequestPosId int `json:"http_request_pos_id,"` + HttpRequestPosId int `json:"http_request_pos_id"` // Threshold of number of HTTP requests per second - HttpPacketPerSecond int `json:"http_packet_per_second,"` - } `json:"http_limited_list,"` + HttpPacketPerSecond int `json:"http_packet_per_second"` + } `json:"http_limited_list"` // List of limits of numbers of connections ConnectionLimitedList []struct { // Position ID of access limit during cleaning - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` + CleaningAccessPosId int `json:"cleaning_access_pos_id"` // Position ID of access limit during cleaning - NewConnectionLimited int `json:"new_connection_limited,"` + NewConnectionLimited int `json:"new_connection_limited"` // Position ID of access limit during cleaning - TotalConnectionLimited int `json:"total_connection_limited,"` - } `json:"connection_limited_list,"` + TotalConnectionLimited int `json:"total_connection_limited"` + } `json:"connection_limited_list"` } diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index f39171d71..9967bd363 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -29,29 +29,29 @@ func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Tim type ListWeeklyReportsResponse struct { // Number of DDoS attacks intercepted in a week - DDosInterceptTimes int `json:"ddos_intercept_times,"` + DDosInterceptTimes int `json:"ddos_intercept_times"` // Number of DDoS attacks intercepted in a week Weekdata []WeekData `json:"-"` // Top 10 attacked IP addresses Top10 []struct { // EIP - FloatingIpAddress string `json:"floating_ip_address,"` + FloatingIpAddress string `json:"floating_ip_address"` // Number of DDoS attacks intercepted, including cleaning operations and black-holes - Times int `json:"times,"` - } `json:"top10,"` + Times int `json:"times"` + } `json:"top10"` } type WeekData struct { // Number of DDoS attacks intercepted - DDosInterceptTimes int `json:"ddos_intercept_times,"` + DDosInterceptTimes int `json:"ddos_intercept_times"` // Number of DDoS blackholes - DDosBlackholeTimes int `json:"ddos_blackhole_times,"` + DDosBlackholeTimes int `json:"ddos_blackhole_times"` // Maximum attack traffic - MaxAttackBps int `json:"max_attack_bps,"` + MaxAttackBps int `json:"max_attack_bps"` // Maximum number of attack connections - MaxAttackConns int `json:"max_attack_conns,"` + MaxAttackConns int `json:"max_attack_conns"` // Start date - PeriodStartDate time.Time `json:"period_start_date,"` + PeriodStartDate time.Time `json:"period_start_date"` } func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { @@ -60,16 +60,16 @@ func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { tmp Weekdata []struct { // Number of DDoS attacks intercepted - DDosInterceptTimes int `json:"ddos_intercept_times,"` + DDosInterceptTimes int `json:"ddos_intercept_times"` // Number of DDoS blackholes - DDosBlackholeTimes int `json:"ddos_blackhole_times,"` + DDosBlackholeTimes int `json:"ddos_blackhole_times"` // Maximum attack traffic - MaxAttackBps int `json:"max_attack_bps,"` + MaxAttackBps int `json:"max_attack_bps"` // Maximum number of attack connections - MaxAttackConns int `json:"max_attack_conns,"` + MaxAttackConns int `json:"max_attack_conns"` // Start date - PeriodStartDate int64 `json:"period_start_date,"` - } `json:"weekdata,"` + PeriodStartDate int64 `json:"period_start_date"` + } `json:"weekdata"` } err := json.Unmarshal(b, &s) if err != nil { From 931ef753567599f962ddebdd0c2cca6c15e655c1 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 23 Aug 2022 11:41:29 +0200 Subject: [PATCH 19/26] remove , --- acceptance/openstack/antiddos/fixtures.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/acceptance/openstack/antiddos/fixtures.go b/acceptance/openstack/antiddos/fixtures.go index 1ec8d52a4..5e77c2356 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/acceptance/openstack/antiddos/fixtures.go @@ -173,9 +173,9 @@ func HandleListStatusSuccessfully(t *testing.T) { var ListConfigsResponse = antiddos.ListConfigsResponse{ TrafficLimitedList: []struct { - TrafficPosId int `json:"traffic_pos_id,"` - TrafficPerSecond int `json:"traffic_per_second,"` - PacketPerSecond int `json:"packet_per_second,"` + TrafficPosId int `json:"traffic_pos_id"` + TrafficPerSecond int `json:"traffic_per_second"` + PacketPerSecond int `json:"packet_per_second"` }{ { TrafficPosId: 1, @@ -224,8 +224,8 @@ var ListConfigsResponse = antiddos.ListConfigsResponse{ }, }, HttpLimitedList: []struct { - HttpRequestPosId int `json:"http_request_pos_id,"` - HttpPacketPerSecond int `json:"http_packet_per_second,"` + HttpRequestPosId int `json:"http_request_pos_id"` + HttpPacketPerSecond int `json:"http_packet_per_second"` }{ { HttpRequestPosId: 1, @@ -289,9 +289,9 @@ var ListConfigsResponse = antiddos.ListConfigsResponse{ }, }, ConnectionLimitedList: []struct { - CleaningAccessPosId int `json:"cleaning_access_pos_id,"` - NewConnectionLimited int `json:"new_connection_limited,"` - TotalConnectionLimited int `json:"total_connection_limited,"` + CleaningAccessPosId int `json:"cleaning_access_pos_id"` + NewConnectionLimited int `json:"new_connection_limited"` + TotalConnectionLimited int `json:"total_connection_limited"` }{ { CleaningAccessPosId: 1, @@ -587,8 +587,8 @@ var WeeklyReportResponse = antiddos.ListWeeklyReportsResponse{ }, }, Top10: []struct { - FloatingIpAddress string `json:"floating_ip_address,"` - Times int `json:"times,"` + FloatingIpAddress string `json:"floating_ip_address"` + Times int `json:"times"` }{}, } From 830794add6d7be48eb98a29bec1e5e014beb9262 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 23 Aug 2022 15:09:16 +0200 Subject: [PATCH 20/26] return err --- openstack/antiddos/v1/antiddos/create_default_config.go | 6 +----- openstack/antiddos/v1/antiddos/delete_default_config.go | 6 +----- openstack/antiddos/v1/antiddos/list_daily_logs.go | 6 +----- openstack/antiddos/v1/antiddos/list_daily_report.go | 6 +----- openstack/antiddos/v1/antiddos/list_new_configs.go | 6 +----- openstack/antiddos/v1/antiddos/list_weekly_reports.go | 6 +----- openstack/antiddos/v1/antiddos/show_ddos.go | 6 +----- openstack/antiddos/v1/antiddos/show_ddos_status.go | 6 +----- openstack/antiddos/v1/antiddos/show_default_config.go | 6 +----- openstack/antiddos/v1/antiddos/show_new_task_status.go | 6 +----- openstack/antiddos/v1/antiddos/update_ddos.go | 6 +----- openstack/antiddos/v2/warnalert/show_alert_config.go | 6 +----- 12 files changed, 12 insertions(+), 60 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 836179aee..be07d4dd7 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -34,11 +34,7 @@ func CreateDefaultConfig(client *golangsdk.ServiceClient, opts ConfigOpts) (*Tas var res TaskResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } type TaskResponse struct { diff --git a/openstack/antiddos/v1/antiddos/delete_default_config.go b/openstack/antiddos/v1/antiddos/delete_default_config.go index 8f2dcbc69..32aa55159 100644 --- a/openstack/antiddos/v1/antiddos/delete_default_config.go +++ b/openstack/antiddos/v1/antiddos/delete_default_config.go @@ -16,9 +16,5 @@ func DeleteDefaultConfig(client *golangsdk.ServiceClient) (*TaskResponse, error) var res TaskResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } diff --git a/openstack/antiddos/v1/antiddos/list_daily_logs.go b/openstack/antiddos/v1/antiddos/list_daily_logs.go index 742f2befa..35ca03c15 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_logs.go +++ b/openstack/antiddos/v1/antiddos/list_daily_logs.go @@ -33,11 +33,7 @@ func ListDailyLogs(client *golangsdk.ServiceClient, floatingIpId string, opts Li var res ListDailyLogsResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } type ListDailyLogsResponse struct { diff --git a/openstack/antiddos/v1/antiddos/list_daily_report.go b/openstack/antiddos/v1/antiddos/list_daily_report.go index f69edaa42..477b9ed60 100644 --- a/openstack/antiddos/v1/antiddos/list_daily_report.go +++ b/openstack/antiddos/v1/antiddos/list_daily_report.go @@ -14,11 +14,7 @@ func ListDailyReport(client *golangsdk.ServiceClient, floatingIpId string) ([]Da var res []Data err = extract.IntoSlicePtr(raw.Body, &res, "data") - if err != nil { - return nil, err - } - - return res, nil + return res, err } type Data struct { diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go index dddb89d3f..9f6779267 100644 --- a/openstack/antiddos/v1/antiddos/list_new_configs.go +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -14,11 +14,7 @@ func ListNewConfigs(client *golangsdk.ServiceClient) (*ListConfigsResponse, erro var response ListConfigsResponse err = extract.Into(raw.Body, &response) - if err != nil { - return nil, err - } - - return &response, nil + return &response, err } type ListConfigsResponse struct { diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index 9967bd363..de33ed9cf 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -20,11 +20,7 @@ func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Tim var res ListWeeklyReportsResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } type ListWeeklyReportsResponse struct { diff --git a/openstack/antiddos/v1/antiddos/show_ddos.go b/openstack/antiddos/v1/antiddos/show_ddos.go index df1ecca8b..da886dd9b 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos.go +++ b/openstack/antiddos/v1/antiddos/show_ddos.go @@ -14,9 +14,5 @@ func ShowDDos(client *golangsdk.ServiceClient, floatingIpId string) (*ConfigOpts var res ConfigOpts err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } diff --git a/openstack/antiddos/v1/antiddos/show_ddos_status.go b/openstack/antiddos/v1/antiddos/show_ddos_status.go index e7c971853..4c671f2c4 100644 --- a/openstack/antiddos/v1/antiddos/show_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/show_ddos_status.go @@ -16,9 +16,5 @@ func ShowDDosStatus(client *golangsdk.ServiceClient, floatingIpId string) (strin Status string `json:"status"` } err = extract.Into(raw.Body, &res) - if err != nil { - return "", err - } - - return res.Status, nil + return res.Status, err } diff --git a/openstack/antiddos/v1/antiddos/show_default_config.go b/openstack/antiddos/v1/antiddos/show_default_config.go index 89353c865..5fc22af86 100644 --- a/openstack/antiddos/v1/antiddos/show_default_config.go +++ b/openstack/antiddos/v1/antiddos/show_default_config.go @@ -14,9 +14,5 @@ func ShowDefaultConfig(client *golangsdk.ServiceClient) (*ConfigOpts, error) { var res ConfigOpts err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } diff --git a/openstack/antiddos/v1/antiddos/show_new_task_status.go b/openstack/antiddos/v1/antiddos/show_new_task_status.go index dca18ed12..d03c0dcdf 100644 --- a/openstack/antiddos/v1/antiddos/show_new_task_status.go +++ b/openstack/antiddos/v1/antiddos/show_new_task_status.go @@ -24,11 +24,7 @@ func ShowNewTaskStatus(client *golangsdk.ServiceClient, opts ShowNewTaskStatusOp var res ShowNewTaskStatusResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } type ShowNewTaskStatusResponse struct { diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index a3ac7c728..ff132c7cc 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -21,9 +21,5 @@ func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts Confi var res TaskResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } diff --git a/openstack/antiddos/v2/warnalert/show_alert_config.go b/openstack/antiddos/v2/warnalert/show_alert_config.go index 0aa4e0ca9..8f42e29dc 100644 --- a/openstack/antiddos/v2/warnalert/show_alert_config.go +++ b/openstack/antiddos/v2/warnalert/show_alert_config.go @@ -14,11 +14,7 @@ func ShowAlertConfig(client *golangsdk.ServiceClient) (*ShowAlertConfigResponse, var res ShowAlertConfigResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return &res, nil + return &res, err } type ShowAlertConfigResponse struct { From ed54f760e084797da6c9039a6ac3f35fb0b6ab24 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 24 Aug 2022 20:14:45 +0200 Subject: [PATCH 21/26] move back --- .../antiddos/v1/antiddos/list_ddos_status.go | 4 +- .../antiddos/v1/antiddos/list_new_configs.go | 52 ++++++++++--------- .../v1/antiddos/list_weekly_reports.go | 30 +++++------ .../antiddos/v1/antiddos/testing}/fixtures.go | 2 +- .../v1/antiddos/testing}/requests_test.go | 2 +- 5 files changed, 44 insertions(+), 46 deletions(-) rename {acceptance/openstack/antiddos => openstack/antiddos/v1/antiddos/testing}/fixtures.go (99%) rename {acceptance/openstack/antiddos => openstack/antiddos/v1/antiddos/testing}/requests_test.go (99%) diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index d0b126d73..f95f711e6 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -52,7 +52,7 @@ func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([ return nil, err } - return FilterDdosStatus(res.DDosStatus, opts) + return filterDdosStatus(res.DDosStatus, opts) } type ListStatusResponse struct { @@ -62,7 +62,7 @@ type ListStatusResponse struct { DDosStatus []DDosStatus `json:"ddosStatus"` } -func FilterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosStatus, error) { +func filterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosStatus, error) { var refinedDdosStatus []DDosStatus var matched bool m := map[string]interface{}{} diff --git a/openstack/antiddos/v1/antiddos/list_new_configs.go b/openstack/antiddos/v1/antiddos/list_new_configs.go index 9f6779267..67841b4bc 100644 --- a/openstack/antiddos/v1/antiddos/list_new_configs.go +++ b/openstack/antiddos/v1/antiddos/list_new_configs.go @@ -19,30 +19,34 @@ func ListNewConfigs(client *golangsdk.ServiceClient) (*ListConfigsResponse, erro type ListConfigsResponse struct { // List of traffic limits - TrafficLimitedList []struct { - // Position ID of traffic - TrafficPosId int `json:"traffic_pos_id"` - // Threshold of traffic per second (Mbit/s) - TrafficPerSecond int `json:"traffic_per_second"` - // Threshold of number of packets per second - PacketPerSecond int `json:"packet_per_second"` - } `json:"traffic_limited_list"` - + TrafficLimitedList []TrafficLimited `json:"traffic_limited_list"` // List of HTTP limits - HttpLimitedList []struct { - // Position ID of number of HTTP requests - HttpRequestPosId int `json:"http_request_pos_id"` - // Threshold of number of HTTP requests per second - HttpPacketPerSecond int `json:"http_packet_per_second"` - } `json:"http_limited_list"` - + HttpLimitedList []HttpLimited `json:"http_limited_list"` // List of limits of numbers of connections - ConnectionLimitedList []struct { - // Position ID of access limit during cleaning - CleaningAccessPosId int `json:"cleaning_access_pos_id"` - // Position ID of access limit during cleaning - NewConnectionLimited int `json:"new_connection_limited"` - // Position ID of access limit during cleaning - TotalConnectionLimited int `json:"total_connection_limited"` - } `json:"connection_limited_list"` + ConnectionLimitedList []ConnectionLimited `json:"connection_limited_list"` +} + +type TrafficLimited struct { + // Position ID of traffic + TrafficPosId int `json:"traffic_pos_id"` + // Threshold of traffic per second (Mbit/s) + TrafficPerSecond int `json:"traffic_per_second"` + // Threshold of number of packets per second + PacketPerSecond int `json:"packet_per_second"` +} + +type HttpLimited struct { + // Position ID of number of HTTP requests + HttpRequestPosId int `json:"http_request_pos_id"` + // Threshold of number of HTTP requests per second + HttpPacketPerSecond int `json:"http_packet_per_second"` +} + +type ConnectionLimited struct { + // Position ID of access limit during cleaning + CleaningAccessPosId int `json:"cleaning_access_pos_id"` + // Position ID of access limit during cleaning + NewConnectionLimited int `json:"new_connection_limited"` + // Position ID of access limit during cleaning + TotalConnectionLimited int `json:"total_connection_limited"` } diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index de33ed9cf..65cce1f5c 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -29,12 +29,14 @@ type ListWeeklyReportsResponse struct { // Number of DDoS attacks intercepted in a week Weekdata []WeekData `json:"-"` // Top 10 attacked IP addresses - Top10 []struct { - // EIP - FloatingIpAddress string `json:"floating_ip_address"` - // Number of DDoS attacks intercepted, including cleaning operations and black-holes - Times int `json:"times"` - } `json:"top10"` + Top10 []Top10 `json:"top10"` +} + +type Top10 struct { + // EIP + FloatingIpAddress string `json:"floating_ip_address"` + // Number of DDoS attacks intercepted, including cleaning operations and black-holes + Times int `json:"times"` } type WeekData struct { @@ -51,28 +53,20 @@ type WeekData struct { } func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { - type tmp ListWeeklyReportsResponse var s struct { - tmp + ListWeeklyReportsResponse Weekdata []struct { - // Number of DDoS attacks intercepted - DDosInterceptTimes int `json:"ddos_intercept_times"` - // Number of DDoS blackholes - DDosBlackholeTimes int `json:"ddos_blackhole_times"` - // Maximum attack traffic - MaxAttackBps int `json:"max_attack_bps"` - // Maximum number of attack connections - MaxAttackConns int `json:"max_attack_conns"` - // Start date + WeekData PeriodStartDate int64 `json:"period_start_date"` } `json:"weekdata"` } + err := json.Unmarshal(b, &s) if err != nil { return err } - *r = ListWeeklyReportsResponse(s.tmp) + *r = s.ListWeeklyReportsResponse r.Weekdata = make([]WeekData, len(s.Weekdata)) for idx, val := range s.Weekdata { diff --git a/acceptance/openstack/antiddos/fixtures.go b/openstack/antiddos/v1/antiddos/testing/fixtures.go similarity index 99% rename from acceptance/openstack/antiddos/fixtures.go rename to openstack/antiddos/v1/antiddos/testing/fixtures.go index 5e77c2356..5cb7c9431 100644 --- a/acceptance/openstack/antiddos/fixtures.go +++ b/openstack/antiddos/v1/antiddos/testing/fixtures.go @@ -1,4 +1,4 @@ -package antiddos +package testing import ( "fmt" diff --git a/acceptance/openstack/antiddos/requests_test.go b/openstack/antiddos/v1/antiddos/testing/requests_test.go similarity index 99% rename from acceptance/openstack/antiddos/requests_test.go rename to openstack/antiddos/v1/antiddos/testing/requests_test.go index 0a603f1f5..7b71abf98 100644 --- a/acceptance/openstack/antiddos/requests_test.go +++ b/openstack/antiddos/v1/antiddos/testing/requests_test.go @@ -1,4 +1,4 @@ -package antiddos +package testing import ( "testing" From a2e03775d913107ec39faaec9ef8752d3833fbae Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 24 Aug 2022 20:21:11 +0200 Subject: [PATCH 22/26] move back --- .../antiddos/v1/antiddos/testing/fixtures.go | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/testing/fixtures.go b/openstack/antiddos/v1/antiddos/testing/fixtures.go index 5cb7c9431..55943815d 100644 --- a/openstack/antiddos/v1/antiddos/testing/fixtures.go +++ b/openstack/antiddos/v1/antiddos/testing/fixtures.go @@ -172,11 +172,7 @@ func HandleListStatusSuccessfully(t *testing.T) { } var ListConfigsResponse = antiddos.ListConfigsResponse{ - TrafficLimitedList: []struct { - TrafficPosId int `json:"traffic_pos_id"` - TrafficPerSecond int `json:"traffic_per_second"` - PacketPerSecond int `json:"packet_per_second"` - }{ + TrafficLimitedList: []antiddos.TrafficLimited{ { TrafficPosId: 1, TrafficPerSecond: 10, @@ -223,10 +219,7 @@ var ListConfigsResponse = antiddos.ListConfigsResponse{ PacketPerSecond: 70000, }, }, - HttpLimitedList: []struct { - HttpRequestPosId int `json:"http_request_pos_id"` - HttpPacketPerSecond int `json:"http_packet_per_second"` - }{ + HttpLimitedList: []antiddos.HttpLimited{ { HttpRequestPosId: 1, HttpPacketPerSecond: 100, @@ -288,11 +281,7 @@ var ListConfigsResponse = antiddos.ListConfigsResponse{ HttpPacketPerSecond: 20000, }, }, - ConnectionLimitedList: []struct { - CleaningAccessPosId int `json:"cleaning_access_pos_id"` - NewConnectionLimited int `json:"new_connection_limited"` - TotalConnectionLimited int `json:"total_connection_limited"` - }{ + ConnectionLimitedList: []antiddos.ConnectionLimited{ { CleaningAccessPosId: 1, NewConnectionLimited: 10, @@ -586,10 +575,7 @@ var WeeklyReportResponse = antiddos.ListWeeklyReportsResponse{ PeriodStartDate: responsePeriodTime, }, }, - Top10: []struct { - FloatingIpAddress string `json:"floating_ip_address"` - Times int `json:"times"` - }{}, + Top10: []antiddos.Top10{}, } func HandleWeeklyReportSuccessfully(t *testing.T) { From 755efeec2ada8d4aa940b473da1a08fe0fb0aa0a Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 29 Aug 2022 19:11:05 +0200 Subject: [PATCH 23/26] TaskResponse --- .../v1/antiddos/create_default_config.go | 2 +- .../antiddos/v1/antiddos/testing/fixtures.go | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index be07d4dd7..15c2c96ca 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -41,7 +41,7 @@ type TaskResponse struct { // Internal error code ErrorCode string `json:"error_code"` // Internal error description - ErrorDescription string `json:"error_description"` + ErrorMessage string `json:"error_msg"` // ID of a task. This ID can be used to query the status of the task. // This field is reserved for use in task auditing later. It is temporarily unused. TaskId string `json:"task_id"` diff --git a/openstack/antiddos/v1/antiddos/testing/fixtures.go b/openstack/antiddos/v1/antiddos/testing/fixtures.go index 55943815d..ea8b8fb95 100644 --- a/openstack/antiddos/v1/antiddos/testing/fixtures.go +++ b/openstack/antiddos/v1/antiddos/testing/fixtures.go @@ -14,8 +14,8 @@ import ( const CreateOutput string = ` { "error_code": "10000000", - "error_description": "The task has been received and is being handled", - "task_id": "82463800-70fe-4cba-9a96-06175e246ab3" + "error_msg": "Ok", + "task_id": "" } ` @@ -30,13 +30,13 @@ const CreateRequest string = ` ` var CreateResponse = antiddos.TaskResponse{ - ErrorCode: "10000000", - ErrorDescription: "The task has been received and is being handled", - TaskId: "82463800-70fe-4cba-9a96-06175e246ab3", + ErrorCode: "10000000", + ErrorMessage: "Ok", + TaskId: "", } func HandleCreateSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/antiddos/82abaa86-8518-47db-8d63-ddf152824635", func(w http.ResponseWriter, r *http.Request) { + th.Mux.HandleFunc("/antiddos/default-config", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "POST") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) th.TestJSONRequest(t, r, CreateRequest) @@ -47,21 +47,21 @@ func HandleCreateSuccessfully(t *testing.T) { } var DeleteResponse = antiddos.TaskResponse{ - ErrorCode: "10000000", - ErrorDescription: "The task has been received and is being handled", - TaskId: "f732e7f1-26b2-40f1-85e9-a8a4d3a43038", + ErrorCode: "10000000", + ErrorMessage: "Ok", + TaskId: "", } const DeleteOutput string = ` { "error_code": "10000000", - "error_description": "The task has been received and is being handled", - "task_id": "f732e7f1-26b2-40f1-85e9-a8a4d3a43038" + "error_msg": "Ok", + "task_id": "" } ` func HandleDeleteSuccessfully(t *testing.T) { - th.Mux.HandleFunc("/antiddos/82abaa86-8518-47db-8d63-ddf152824635", func(w http.ResponseWriter, r *http.Request) { + th.Mux.HandleFunc("/antiddos/default-config", func(w http.ResponseWriter, r *http.Request) { th.TestMethod(t, r, "DELETE") th.TestHeader(t, r, "X-Auth-Token", client.TokenID) @@ -101,8 +101,8 @@ func HandleGetSuccessfully(t *testing.T) { const UpdateOutput string = ` { "error_code": "10000000", - "error_description": "The task has been received and is being handled", - "task_id": "82463800-70fe-4cba-9a96-06175e246ab3" + "error_msg": "Ok", + "task_id": "" } ` @@ -117,9 +117,9 @@ const UpdateRequest string = ` ` var UpdateResponse = antiddos.TaskResponse{ - ErrorCode: "10000000", - ErrorDescription: "The task has been received and is being handled", - TaskId: "82463800-70fe-4cba-9a96-06175e246ab3", + ErrorCode: "10000000", + ErrorMessage: "Ok", + TaskId: "", } func HandleUpdateSuccessfully(t *testing.T) { From 192882873e179eefcaf75a8f8d833b4985008aaa Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Mon, 29 Aug 2022 19:34:40 +0200 Subject: [PATCH 24/26] WeekData --- .../v1/antiddos/list_weekly_reports.go | 40 ++----------------- .../antiddos/v1/antiddos/testing/fixtures.go | 2 +- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index 65cce1f5c..a6bb924a2 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -1,18 +1,16 @@ package antiddos import ( - "encoding/json" "strconv" - "time" "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) -func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate time.Time) (*ListWeeklyReportsResponse, error) { +func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate int64) (*ListWeeklyReportsResponse, error) { // GET /v1/{project_id}/antiddos/weekly raw, err := client.Get( - client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate.Unix()*1000, 10), + client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate, 10), nil, nil) if err != nil { return nil, err @@ -27,7 +25,7 @@ type ListWeeklyReportsResponse struct { // Number of DDoS attacks intercepted in a week DDosInterceptTimes int `json:"ddos_intercept_times"` // Number of DDoS attacks intercepted in a week - Weekdata []WeekData `json:"-"` + Weekdata []WeekData `json:"weekdata"` // Top 10 attacked IP addresses Top10 []Top10 `json:"top10"` } @@ -49,35 +47,5 @@ type WeekData struct { // Maximum number of attack connections MaxAttackConns int `json:"max_attack_conns"` // Start date - PeriodStartDate time.Time `json:"period_start_date"` -} - -func (r *ListWeeklyReportsResponse) UnmarshalJSON(b []byte) error { - var s struct { - ListWeeklyReportsResponse - Weekdata []struct { - WeekData - PeriodStartDate int64 `json:"period_start_date"` - } `json:"weekdata"` - } - - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - *r = s.ListWeeklyReportsResponse - r.Weekdata = make([]WeekData, len(s.Weekdata)) - - for idx, val := range s.Weekdata { - r.Weekdata[idx] = WeekData{ - DDosInterceptTimes: val.DDosBlackholeTimes, - DDosBlackholeTimes: val.DDosBlackholeTimes, - MaxAttackBps: val.MaxAttackBps, - MaxAttackConns: val.MaxAttackConns, - PeriodStartDate: time.Unix(val.PeriodStartDate/1000, 0).UTC(), - } - } - - return nil + PeriodStartDate int64 `json:"period_start_date"` } diff --git a/openstack/antiddos/v1/antiddos/testing/fixtures.go b/openstack/antiddos/v1/antiddos/testing/fixtures.go index ea8b8fb95..e72837958 100644 --- a/openstack/antiddos/v1/antiddos/testing/fixtures.go +++ b/openstack/antiddos/v1/antiddos/testing/fixtures.go @@ -520,7 +520,7 @@ var WeeklyReportOutput = ` ` // init the loc -var responsePeriodTime = time.Date(2018, 3, 1, 0, 0, 0, 0, time.UTC) +var responsePeriodTime = time.Date(2018, 3, 1, 0, 0, 0, 0, time.UTC).UnixMilli() var WeeklyReportResponse = antiddos.ListWeeklyReportsResponse{ DDosInterceptTimes: 0, From 11823083f284c5079da870ec510b3dc7b8b318cc Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:59:38 +0200 Subject: [PATCH 25/26] fix --- .../v1/antiddos/create_default_config.go | 3 +- .../antiddos/v1/antiddos/list_ddos_status.go | 46 +------------------ .../v1/antiddos/list_weekly_reports.go | 5 +- openstack/antiddos/v1/antiddos/update_ddos.go | 3 +- 4 files changed, 8 insertions(+), 49 deletions(-) diff --git a/openstack/antiddos/v1/antiddos/create_default_config.go b/openstack/antiddos/v1/antiddos/create_default_config.go index 15c2c96ca..133d588be 100644 --- a/openstack/antiddos/v1/antiddos/create_default_config.go +++ b/openstack/antiddos/v1/antiddos/create_default_config.go @@ -2,6 +2,7 @@ package antiddos import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) @@ -19,7 +20,7 @@ type ConfigOpts struct { } func CreateDefaultConfig(client *golangsdk.ServiceClient, opts ConfigOpts) (*TaskResponse, error) { - b, err := golangsdk.BuildRequestBody(opts, "") + b, err := build.RequestBody(opts, "") if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/list_ddos_status.go b/openstack/antiddos/v1/antiddos/list_ddos_status.go index f95f711e6..74efe0fea 100644 --- a/openstack/antiddos/v1/antiddos/list_ddos_status.go +++ b/openstack/antiddos/v1/antiddos/list_ddos_status.go @@ -1,8 +1,6 @@ package antiddos import ( - "reflect" - "github.com/opentelekomcloud/gophertelekomcloud" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) @@ -34,7 +32,7 @@ type DDosStatus struct { Status string `json:"status"` } -func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([]DDosStatus, error) { +func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) (*ListStatusResponse, error) { q, err := golangsdk.BuildQueryString(&opts) if err != nil { return nil, err @@ -48,11 +46,7 @@ func ListDDosStatus(client *golangsdk.ServiceClient, opts ListDDosStatusOpts) ([ var res ListStatusResponse err = extract.Into(raw.Body, &res) - if err != nil { - return nil, err - } - - return filterDdosStatus(res.DDosStatus, opts) + return &res, err } type ListStatusResponse struct { @@ -61,39 +55,3 @@ type ListStatusResponse struct { // List of defense statuses DDosStatus []DDosStatus `json:"ddosStatus"` } - -func filterDdosStatus(ddosStatus []DDosStatus, opts ListDDosStatusOpts) ([]DDosStatus, error) { - var refinedDdosStatus []DDosStatus - var matched bool - m := map[string]interface{}{} - - if opts.FloatingIpId != "" { - m["FloatingIpId"] = opts.FloatingIpId - } - - if len(m) > 0 && len(ddosStatus) > 0 { - for _, ddosStatus := range ddosStatus { - matched = true - - for key, value := range m { - if sVal := getStructField(&ddosStatus, key); !(sVal == value) { - matched = false - } - } - - if matched { - refinedDdosStatus = append(refinedDdosStatus, ddosStatus) - } - } - } else { - refinedDdosStatus = ddosStatus - } - - return refinedDdosStatus, nil -} - -func getStructField(v *DDosStatus, field string) string { - r := reflect.ValueOf(v) - f := reflect.Indirect(r).FieldByName(field) - return f.String() -} diff --git a/openstack/antiddos/v1/antiddos/list_weekly_reports.go b/openstack/antiddos/v1/antiddos/list_weekly_reports.go index a6bb924a2..af401e330 100644 --- a/openstack/antiddos/v1/antiddos/list_weekly_reports.go +++ b/openstack/antiddos/v1/antiddos/list_weekly_reports.go @@ -9,9 +9,8 @@ import ( func ListWeeklyReports(client *golangsdk.ServiceClient, periodStartDate int64) (*ListWeeklyReportsResponse, error) { // GET /v1/{project_id}/antiddos/weekly - raw, err := client.Get( - client.ServiceURL("antiddos", "weekly")+"?period_start_date="+strconv.FormatInt(periodStartDate, 10), - nil, nil) + url := client.ServiceURL("antiddos", "weekly") + "?period_start_date=" + strconv.FormatInt(periodStartDate, 10) + raw, err := client.Get(url, nil, nil) if err != nil { return nil, err } diff --git a/openstack/antiddos/v1/antiddos/update_ddos.go b/openstack/antiddos/v1/antiddos/update_ddos.go index ff132c7cc..8087c3d4a 100644 --- a/openstack/antiddos/v1/antiddos/update_ddos.go +++ b/openstack/antiddos/v1/antiddos/update_ddos.go @@ -2,11 +2,12 @@ package antiddos import ( "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" ) func UpdateDDos(client *golangsdk.ServiceClient, floatingIpId string, opts ConfigOpts) (*TaskResponse, error) { - b, err := golangsdk.BuildRequestBody(opts, "") + b, err := build.RequestBody(opts, "") if err != nil { return nil, err } From 88e3d1041ec0ae61390d27211bdccaf0dea00900 Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Tue, 25 Oct 2022 13:50:43 +0200 Subject: [PATCH 26/26] fix --- openstack/antiddos/v1/antiddos/testing/requests_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openstack/antiddos/v1/antiddos/testing/requests_test.go b/openstack/antiddos/v1/antiddos/testing/requests_test.go index 7b71abf98..b9f770bc2 100644 --- a/openstack/antiddos/v1/antiddos/testing/requests_test.go +++ b/openstack/antiddos/v1/antiddos/testing/requests_test.go @@ -80,7 +80,7 @@ func TestListStatus(t *testing.T) { actual, err := antiddos.ListDDosStatus(client.ServiceClient(), listOpt) th.AssertNoErr(t, err) - th.CheckDeepEquals(t, ListStatusResponse, actual) + th.CheckDeepEquals(t, ListStatusResponse, actual.DDosStatus) } func TestListConfigs(t *testing.T) {