Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New APIG throttling policy resource supported #1296

Merged
merged 3 commits into from
Jul 31, 2021
Merged

New APIG throttling policy resource supported #1296

merged 3 commits into from
Jul 31, 2021

Conversation

Lance52259
Copy link
Collaborator

@Lance52259 Lance52259 commented Jul 19, 2021

What this PR does / why we need it:
The throttling policy controls the number of times APIs can be called by a user, an app, or an IP address during a specific period to protect backend services.

  • For different services and users, custom can control the request frequency at which an API can be called by a user, an app, and an IP address. This ensures that backend services can run stably.
  • The throttling can be accurate to the second, minute, hour, or day.
  • Excluded apps and tenants can be configured to limit the number of API calls from specific apps and tenants, respectively.

Which issue this PR fixes:
(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged)
reference: #1249

Special notes for your reviewer:

Release note:

1. New throttling policy resource support:
  a. support base type and share type
  b. support four kinds of call limit
2. Related acc unit test for each parameters.
3. Related document support.

PR Checklist

  • Tests added/passed.
  • Documentation updated.
  • Schema updated.

Acceptance Steps Performed

make testacc TEST='./huaweicloud/services/acceptance/apig' TESTARGS='-run=TestAccApigThrottlingPolicyV2_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./huaweicloud/services/acceptance/apig -v -run=TestAccApigThrottlingPolicyV2_basic -timeout 360m -parallel 4
=== RUN   TestAccApigThrottlingPolicyV2_basic
=== PAUSE TestAccApigThrottlingPolicyV2_basic
=== CONT  TestAccApigThrottlingPolicyV2_basic
--- PASS: TestAccApigThrottlingPolicyV2_basic (466.09s)
PASS
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/apig  466.161s
make testacc TEST='./huaweicloud/services/acceptance/apig' TESTARGS='-run=TestAccApigThrottlingPolicyV2_spec'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./huaweicloud/services/acceptance/apig -v -run=TestAccApigThrottlingPolicyV2_spec -timeout 360m -parallel 4
=== RUN   TestAccApigThrottlingPolicyV2_spec
=== PAUSE TestAccApigThrottlingPolicyV2_spec
=== CONT  TestAccApigThrottlingPolicyV2_spec
--- PASS: TestAccApigThrottlingPolicyV2_spec (485.65s)
PASS
ok      github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/apig      485.731s

@Lance52259
Copy link
Collaborator Author

Pending sdk supports throttling policy.

return fmtp.Errorf("Error saving special user throttles to state: %s", err)
}
apps := make([]map[string]interface{}, len(specThrottles))
for i, throttle := range specThrottles {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to construct users and apps in one loop.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, that's easy to understand.

- support base type and share type
- support four kinds of call limit
- support special throttling policies management
- use more readable code
- refactor the policies structure of attribute parameters
This parameter applies with each of the API call limits: `max_api_requests`, `max_app_requests`, `max_ip_requests`
and `max_user_requests`.

* `max_api_requests` - (Required, Int) Specifies the maximum number of times an API can be accessed within a specified
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put max_api_requests, max_app_requests, max_ip_requests and max_user_requests together.

return nil
}

func resourceApigThrottlingPolicyV2Create(d *schema.ResourceData, meta interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some blank lines to make it easier to read.

- adjust the locations of all api limit call in document
- add some blank lines and annotations
@ShiChangkuo ShiChangkuo merged commit a91bdb1 into huaweicloud:master Jul 31, 2021
@Lance52259 Lance52259 deleted the br_apig_throttles_active branch August 31, 2021 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants