Tags: sshyran/tyk
Tags
Refactor streaming functionality to become a standard middleware
Merging to release-5.4.0: [TT-12454] Extract ApplyPolicies into inter… …nal/policy scope (TykTechnologies#6367) [TT-12454] Extract ApplyPolicies into internal/policy scope (TykTechnologies#6367) ### **User description** This extracts a large problematic `ApplyPolicies` function into it's own package scope. It does this by: - defining an interface for policy access and deleting inline mutex use - updated *Gateway to implement storage interface - implement storage interface in policy.Store as well (used inline) On top of that: - Fixes a bug in the Duration/Less() functions on user.APILimit, fixes tests - Adds a test particular to ApplyRateLimits (decrease coginitive complexity) The duration was calculated as rate/per, however, the correct way was per/rate; This fixes it so duration is calculated correctly, fixing the Less function comparison. ___ ### **PR Type** Enhancement, Bug fix ___ ### **Description** - Refactored `handleGetPolicy` to use the new `PolicyByID` method. - Introduced a `Repository` interface and added methods `PolicyIDs`, `PolicyByID`, and `PolicyCount` to the `Gateway` struct. - Refactored `ApplyPolicies` in `BaseMiddleware` to use the new `policy` package. - Updated `buildNodeInfo` to use `PolicyCount` instead of `policiesByIDLen`. - Removed redundant methods `getPolicy` and `policiesByIDLen` from `Gateway`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Refactor policy retrieval in `handleGetPolicy`.</code> </dd></summary> <hr> gateway/api.go - Replaced `getPolicy` with `PolicyByID` in `handleGetPolicy`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>gateway.go</strong><dd><code>Add policy-related methods and interface to Gateway.</code> </dd></summary> <hr> gateway/gateway.go <li>Introduced <code>Repository</code> interface.<br> <li> Added methods <code>PolicyIDs</code>, <code>PolicyByID</code>, and <code>PolicyCount</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-17cb8b37eda9018fe1c6cdb5f96b3fc948fc8ba49bc516987b8269576db9fcd4">+38/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Refactor ApplyPolicies to use new policy store.</code> </dd></summary> <hr> gateway/middleware.go <li>Removed <code>clearSession</code> method.<br> <li> Refactored <code>ApplyPolicies</code> to use <code>policy.New</code> and <code>store.Apply</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+3/-411</a> </td> </tr> <tr> <td> <details> <summary><strong>rpc_storage_handler.go</strong><dd><code>Update policy count retrieval in buildNodeInfo.</code> </dd></summary> <hr> gateway/rpc_storage_handler.go - Replaced `policiesByIDLen` with `PolicyCount` in `buildNodeInfo`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-8875f75b602664c44b62b67a4da41d748124ad270573a44db4ec977ee5d68021">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>server.go</strong><dd><code>Remove redundant policy methods from Gateway.</code> </dd></summary> <hr> gateway/server.go - Removed `getPolicy` and `policiesByIDLen` methods. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+0/-13</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <[email protected]>
Merging to release-5.4.0: [TT-12454] Extract ApplyPolicies into inter… …nal/policy scope (TykTechnologies#6367) [TT-12454] Extract ApplyPolicies into internal/policy scope (TykTechnologies#6367) ### **User description** This extracts a large problematic `ApplyPolicies` function into it's own package scope. It does this by: - defining an interface for policy access and deleting inline mutex use - updated *Gateway to implement storage interface - implement storage interface in policy.Store as well (used inline) On top of that: - Fixes a bug in the Duration/Less() functions on user.APILimit, fixes tests - Adds a test particular to ApplyRateLimits (decrease coginitive complexity) The duration was calculated as rate/per, however, the correct way was per/rate; This fixes it so duration is calculated correctly, fixing the Less function comparison. ___ ### **PR Type** Enhancement, Bug fix ___ ### **Description** - Refactored `handleGetPolicy` to use the new `PolicyByID` method. - Introduced a `Repository` interface and added methods `PolicyIDs`, `PolicyByID`, and `PolicyCount` to the `Gateway` struct. - Refactored `ApplyPolicies` in `BaseMiddleware` to use the new `policy` package. - Updated `buildNodeInfo` to use `PolicyCount` instead of `policiesByIDLen`. - Removed redundant methods `getPolicy` and `policiesByIDLen` from `Gateway`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Refactor policy retrieval in `handleGetPolicy`.</code> </dd></summary> <hr> gateway/api.go - Replaced `getPolicy` with `PolicyByID` in `handleGetPolicy`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>gateway.go</strong><dd><code>Add policy-related methods and interface to Gateway.</code> </dd></summary> <hr> gateway/gateway.go <li>Introduced <code>Repository</code> interface.<br> <li> Added methods <code>PolicyIDs</code>, <code>PolicyByID</code>, and <code>PolicyCount</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-17cb8b37eda9018fe1c6cdb5f96b3fc948fc8ba49bc516987b8269576db9fcd4">+38/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Refactor ApplyPolicies to use new policy store.</code> </dd></summary> <hr> gateway/middleware.go <li>Removed <code>clearSession</code> method.<br> <li> Refactored <code>ApplyPolicies</code> to use <code>policy.New</code> and <code>store.Apply</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+3/-411</a> </td> </tr> <tr> <td> <details> <summary><strong>rpc_storage_handler.go</strong><dd><code>Update policy count retrieval in buildNodeInfo.</code> </dd></summary> <hr> gateway/rpc_storage_handler.go - Replaced `policiesByIDLen` with `PolicyCount` in `buildNodeInfo`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-8875f75b602664c44b62b67a4da41d748124ad270573a44db4ec977ee5d68021">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>server.go</strong><dd><code>Remove redundant policy methods from Gateway.</code> </dd></summary> <hr> gateway/server.go - Removed `getPolicy` and `policiesByIDLen` methods. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+0/-13</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <[email protected]>
Merging to release-5.4.0: [TT-12454] Extract ApplyPolicies into inter… …nal/policy scope (TykTechnologies#6367) [TT-12454] Extract ApplyPolicies into internal/policy scope (TykTechnologies#6367) ### **User description** This extracts a large problematic `ApplyPolicies` function into it's own package scope. It does this by: - defining an interface for policy access and deleting inline mutex use - updated *Gateway to implement storage interface - implement storage interface in policy.Store as well (used inline) On top of that: - Fixes a bug in the Duration/Less() functions on user.APILimit, fixes tests - Adds a test particular to ApplyRateLimits (decrease coginitive complexity) The duration was calculated as rate/per, however, the correct way was per/rate; This fixes it so duration is calculated correctly, fixing the Less function comparison. ___ ### **PR Type** Enhancement, Bug fix ___ ### **Description** - Refactored `handleGetPolicy` to use the new `PolicyByID` method. - Introduced a `Repository` interface and added methods `PolicyIDs`, `PolicyByID`, and `PolicyCount` to the `Gateway` struct. - Refactored `ApplyPolicies` in `BaseMiddleware` to use the new `policy` package. - Updated `buildNodeInfo` to use `PolicyCount` instead of `policiesByIDLen`. - Removed redundant methods `getPolicy` and `policiesByIDLen` from `Gateway`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Refactor policy retrieval in `handleGetPolicy`.</code> </dd></summary> <hr> gateway/api.go - Replaced `getPolicy` with `PolicyByID` in `handleGetPolicy`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>gateway.go</strong><dd><code>Add policy-related methods and interface to Gateway.</code> </dd></summary> <hr> gateway/gateway.go <li>Introduced <code>Repository</code> interface.<br> <li> Added methods <code>PolicyIDs</code>, <code>PolicyByID</code>, and <code>PolicyCount</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-17cb8b37eda9018fe1c6cdb5f96b3fc948fc8ba49bc516987b8269576db9fcd4">+38/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Refactor ApplyPolicies to use new policy store.</code> </dd></summary> <hr> gateway/middleware.go <li>Removed <code>clearSession</code> method.<br> <li> Refactored <code>ApplyPolicies</code> to use <code>policy.New</code> and <code>store.Apply</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+3/-411</a> </td> </tr> <tr> <td> <details> <summary><strong>rpc_storage_handler.go</strong><dd><code>Update policy count retrieval in buildNodeInfo.</code> </dd></summary> <hr> gateway/rpc_storage_handler.go - Replaced `policiesByIDLen` with `PolicyCount` in `buildNodeInfo`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-8875f75b602664c44b62b67a4da41d748124ad270573a44db4ec977ee5d68021">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>server.go</strong><dd><code>Remove redundant policy methods from Gateway.</code> </dd></summary> <hr> gateway/server.go - Removed `getPolicy` and `policiesByIDLen` methods. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6367/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+0/-13</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <[email protected]>
Merging to release-5.4.0: TT-12347 fix management of custom keys in m… …dcb installations (TykTechnologies#6353) TT-12347 fix management of custom keys in mdcb installations (TykTechnologies#6353) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> ## Related Issue https://tyktech.atlassian.net/browse/TT-12347 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ### **PR Type** Enhancement ___ ### **Description** - Changed the order of key search logic in the `SessionDetail` method of `DefaultSessionManager`. - Moved `keyName` to be appended after generating token with `orgID`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>auth_manager.go</strong><dd><code>Modify key search order in `SessionDetail` method</code> </dd></summary> <hr> gateway/auth_manager.go <li>Changed the order of key search logic in <code>SessionDetail</code> method.<br> <li> Moved <code>keyName</code> to be appended after generating token with <code>orgID</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6353/files#diff-311e18b071d244ed1615c0019215b633278679df373288b3451bcc5cf7c52c4e">+3/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions
Merging to release-5.4.0: [TT-12285] Add smoothing, fix duplicate x-g… …o-name (TykTechnologies#6346) [TT-12285] Add smoothing, fix duplicate x-go-name (TykTechnologies#6346) ### **User description** Document Smoothing in Policy and SessionState definitions. Fix Policy ID duplicate x-go-name. ___ ### **PR Type** enhancement, documentation ___ ### **Description** - Added a new `RateLimitSmoothing` schema to define rate limit smoothing settings, including properties like `delay`, `enabled`, `step`, `threshold`, and `trigger`. - Updated the `Policy` and `SessionState` definitions to include the `smoothing` property referencing the new `RateLimitSmoothing` schema. - Changed the `x-go-name` for the `_id` property in the `Policy` definition from `ID` to `MID` to fix a duplicate name issue. - Provided detailed descriptions and titles for the new `RateLimitSmoothing` schema and its properties. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement </strong></td><td><table> <tr> <td> <details> <summary><strong>swagger.yml</strong><dd><code>Add rate limit smoothing and update Policy schema</code> </dd></summary> <hr> swagger.yml <li>Added <code>smoothing</code> property to <code>Policy</code> and <code>SessionState</code> definitions.<br> <li> Introduced <code>RateLimitSmoothing</code> schema with detailed description and <br>properties.<br> <li> Changed <code>x-go-name</code> for <code>_id</code> property in <code>Policy</code> definition to <code>MID</code>.<br> <li> Added titles and descriptions for new and existing components.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6346/files#diff-8f3c4cb253eee09ae2401daa7279a8bbfbfd4168bb579c3ac0ee5c672d63bb2c">+89/-1</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Tit Petric <[email protected]> Co-authored-by: andyo-tyk <[email protected]>
Merging to release-5.4.0: [TT-12313, TT-12222] Update graphql-go-tools ( TykTechnologies#6326) [TT-12313, TT-12222] Update graphql-go-tools (TykTechnologies#6326)
[TT-12186] Fixes TestOAS_ExtractTo_ResetAPIDefinition with a valid ev… …ent config (TykTechnologies#6321) ### **User description** The migration wasn't handled correctly in test, test only change ___ ### **PR Type** Bug fix, Tests ___ ### **Description** - Added a valid event handler configuration to the `TestOAS_ExtractTo_ResetAPIDefinition` test to ensure proper migration handling. - Removed an incorrect assertion related to event handlers in the test. - Updated import statements for better organization and readability. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Tests </strong></td><td><table> <tr> <td> <details> <summary><strong>oas_test.go</strong><dd><code>Fix and enhance `TestOAS_ExtractTo_ResetAPIDefinition` test.</code></dd></summary> <hr> apidef/oas/oas_test.go <li>Added valid event handler configuration to <br><code>TestOAS_ExtractTo_ResetAPIDefinition</code>.<br> <li> Removed an incorrect assertion in the test.<br> <li> Updated import statements for better organization.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6321/files#diff-74029ee88132d30d6478c96a35f8bb2200e0c8e6f42f2c9b147dc6bb7ce74644">+14/-4</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions Co-authored-by: Tit Petric <[email protected]>
PreviousNext