Skip to content

[TT-11991]: added request_headers_rewrite#6257

Merged
kofoworola merged 3 commits into
masterfrom
feat/requestrewriteapidef
May 6, 2024
Merged

[TT-11991]: added request_headers_rewrite#6257
kofoworola merged 3 commits into
masterfrom
feat/requestrewriteapidef

Conversation

@kofoworola

@kofoworola kofoworola commented May 2, 2024

Copy link
Copy Markdown
Contributor

User description

Description

TT-11991

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • 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

  • 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

Type

enhancement


Description

  • Introduced new configuration options for rewriting request headers in the GraphQL proxy settings.
  • Added RequestHeadersRewrite field to GraphQLProxyConfig with a corresponding RequestHeadersRewriteConfig struct.
  • Updated the JSON schema to support the new request_headers_rewrite configuration, including necessary validations.

Changes walkthrough

Relevant files
Enhancement
api_definitions.go
Add Request Headers Rewrite Configuration to GraphQL Proxy

apidef/api_definitions.go

  • Added a new field RequestHeadersRewrite in GraphQLProxyConfig struct.
  • Introduced RequestHeadersRewriteConfig struct with fields Value and
    Remove.
  • +10/-4   
    schema.go
    Update Schema for Request Headers Rewrite                               

    apidef/schema.go

  • Updated JSON schema to include request_headers_rewrite with properties
    value and remove.
  • Added validation requirements for the new properties in the schema.
  • +16/-1   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions

    github-actions Bot commented May 2, 2024

    Copy link
    Copy Markdown
    Contributor

    API Changes

    --- prev.txt	2024-05-06 09:43:23.580620002 +0000
    +++ current.txt	2024-05-06 09:43:20.752612305 +0000
    @@ -735,7 +735,22 @@
                         "properties": {
                             "auth_headers": {
                                 "type": ["object", "null"]
    -                        }
    +                        },
    +						"request_headers_rewrite": {
    +        					"type": ["object", "null"],
    +        					"additionalProperties": {
    +          						"type": "object",
    +          						"properties": {
    +            						"value": {
    +										"type": "string"
    +            						},
    +            						"remove": {
    +              							"type": "boolean"
    +            						}
    +          						},
    +          						"required": ["value", "remove"]
    +        					}
    +      					}
                         }
                     },
                     "subgraph": {
    @@ -1336,10 +1351,11 @@
         which will be hosted alongside the api.
     
     type GraphQLProxyConfig struct {
    -	AuthHeaders           map[string]string         `bson:"auth_headers" json:"auth_headers"`
    -	SubscriptionType      SubscriptionType          `bson:"subscription_type" json:"subscription_type,omitempty"`
    -	RequestHeaders        map[string]string         `bson:"request_headers" json:"request_headers"`
    -	UseResponseExtensions GraphQLResponseExtensions `bson:"use_response_extensions" json:"use_response_extensions"`
    +	AuthHeaders           map[string]string                      `bson:"auth_headers" json:"auth_headers"`
    +	SubscriptionType      SubscriptionType                       `bson:"subscription_type" json:"subscription_type,omitempty"`
    +	RequestHeaders        map[string]string                      `bson:"request_headers" json:"request_headers"`
    +	UseResponseExtensions GraphQLResponseExtensions              `bson:"use_response_extensions" json:"use_response_extensions"`
    +	RequestHeadersRewrite map[string]RequestHeadersRewriteConfig `json:"request_headers_rewrite" bson:"request_headers_rewrite"`
     }
     
     type GraphQLResponseExtensions struct {
    @@ -1629,6 +1645,11 @@
     	Value string `bson:"value" json:"value"`
     }
     
    +type RequestHeadersRewriteConfig struct {
    +	Value  string `json:"value" bson:"value"`
    +	Remove bool   `json:"remove" bson:"remove"`
    +}
    +
     type RequestInputType string
     
     type RequestSigningMeta struct {

    @github-actions

    github-actions Bot commented May 2, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Description updated to latest commit (5e08d0c)

    @github-actions

    github-actions Bot commented May 2, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are localized to specific structures and schema definitions, which are straightforward to review. The modifications are clear and pertain to adding a new feature for request header rewriting.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: The RequestHeadersRewrite map in GraphQLProxyConfig does not specify what happens if both value and remove are provided. This could lead to ambiguous behavior where it's unclear whether the header should be rewritten or removed.

    🔒 Security concerns

    No

    Code feedback:
    relevant fileapidef/api_definitions.go
    suggestion      

    Consider adding validation logic to handle cases where both value and remove are provided in RequestHeadersRewriteConfig. This will prevent ambiguous behavior and ensure clear functionality. [important]

    relevant lineRequestHeadersRewrite map[string]RequestHeadersRewriteConfig `json:"request_headers_rewrite" bson:"request_headers_rewrite"`

    relevant fileapidef/schema.go
    suggestion      

    Ensure that the JSON schema validation for request_headers_rewrite correctly enforces the presence of both value and remove properties to prevent runtime errors due to missing required fields. [important]

    relevant line"required": ["value", "remove"]


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    @github-actions

    github-actions Bot commented May 2, 2024

    Copy link
    Copy Markdown
    Contributor

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Best practice
    Initialize maps in the struct to prevent nil map runtime errors.

    Consider initializing maps in the GraphQLProxyConfig struct to avoid nil map runtime
    errors when trying to insert data. This can be done using the make function.

    apidef/api_definitions.go [845-849]

    -AuthHeaders           map[string]string                      `bson:"auth_headers" json:"auth_headers"`
    -SubscriptionType      SubscriptionType                       `bson:"subscription_type" json:"subscription_type,omitempty"`
    -RequestHeaders        map[string]string                      `bson:"request_headers" json:"request_headers"`
    -UseResponseExtensions GraphQLResponseExtensions              `bson:"use_response_extensions" json:"use_response_extensions"`
    -RequestHeadersRewrite map[string]RequestHeadersRewriteConfig `json:"request_headers_rewrite" bson:"request_headers_rewrite"`
    +AuthHeaders:           make(map[string]string),
    +SubscriptionType:      SubscriptionType,
    +RequestHeaders:        make(map[string]string),
    +UseResponseExtensions: GraphQLResponseExtensions,
    +RequestHeadersRewrite: make(map[string]RequestHeadersRewriteConfig),
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @github-actions

    github-actions Bot commented May 2, 2024

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @kofoworola
    kofoworola enabled auto-merge (squash) May 6, 2024 08:37
    @github-actions

    github-actions Bot commented May 6, 2024

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @kofoworola
    kofoworola force-pushed the feat/requestrewriteapidef branch from 329a343 to be1a82d Compare May 6, 2024 09:00
    @github-actions

    github-actions Bot commented May 6, 2024

    Copy link
    Copy Markdown
    Contributor

    💥 CI tests failed 🙈

    git-state

    all ok

    Please look at the run or in the Checks tab.

    @sonarqubecloud

    sonarqubecloud Bot commented May 6, 2024

    Copy link
    Copy Markdown

    Quality Gate Failed Quality Gate failed

    Failed conditions
    C Reliability Rating on New Code (required ≥ A)

    See analysis details on SonarCloud

    Catch issues before they fail your Quality Gate with our IDE extension SonarLint

    @kofoworola
    kofoworola merged commit 0ec4364 into master May 6, 2024
    @kofoworola
    kofoworola deleted the feat/requestrewriteapidef branch May 6, 2024 10:05
    titpetric pushed a commit that referenced this pull request May 8, 2024
    ## **User description**
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    [TT-11991](https://tyktech.atlassian.net/browse/TT-11991)
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    ## 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
    
    
    [TT-11991]:
    https://tyktech.atlassian.net/browse/TT-11991?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
    
    
    ___
    
    ## **Type**
    enhancement
    
    
    ___
    
    ## **Description**
    - Introduced new configuration options for rewriting request headers in
    the GraphQL proxy settings.
    - Added `RequestHeadersRewrite` field to `GraphQLProxyConfig` with a
    corresponding `RequestHeadersRewriteConfig` struct.
    - Updated the JSON schema to support the new `request_headers_rewrite`
    configuration, including necessary validations.
    
    
    ___
    
    
    
    ## **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_definitions.go</strong><dd><code>Add Request
    Headers Rewrite Configuration to GraphQL Proxy</code></dd></summary>
    <hr>
    
    apidef/api_definitions.go
    <li>Added a new field <code>RequestHeadersRewrite</code> in
    <code>GraphQLProxyConfig</code> struct.<br> <li> Introduced
    <code>RequestHeadersRewriteConfig</code> struct with fields
    <code>Value</code> and <br><code>Remove</code>.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6257/files#diff-9961ccc89a48d32db5b47ba3006315ef52f6e5007fb4b09f8c5d6d299c669d67">+10/-4</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>schema.go</strong><dd><code>Update Schema for Request
    Headers Rewrite</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    apidef/schema.go
    <li>Updated JSON schema to include <code>request_headers_rewrite</code>
    with properties <br><code>value</code> and <code>remove</code>.<br> <li>
    Added validation requirements for the new properties in the schema.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6257/files#diff-f8a37bb370eb6fe20063786a5e6ea3d85a5c91d8e289f0b3e045830c4d322095">+16/-1</a>&nbsp;
    &nbsp; </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
    nerdydread pushed a commit that referenced this pull request Sep 6, 2024
    ## **User description**
    <!-- Provide a general summary of your changes in the Title above -->
    
    ## Description
    [TT-11991](https://tyktech.atlassian.net/browse/TT-11991)
    <!-- Describe your changes in detail -->
    
    ## Related Issue
    
    <!-- This project only accepts pull requests related to open issues. -->
    <!-- If suggesting a new feature or change, please discuss it in an
    issue first. -->
    <!-- If fixing a bug, there should be an issue describing it with steps
    to reproduce. -->
    <!-- OSS: Please link to the issue here. Tyk: please create/link the
    JIRA ticket. -->
    
    ## 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
    
    
    [TT-11991]:
    https://tyktech.atlassian.net/browse/TT-11991?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
    
    
    ___
    
    ## **Type**
    enhancement
    
    
    ___
    
    ## **Description**
    - Introduced new configuration options for rewriting request headers in
    the GraphQL proxy settings.
    - Added `RequestHeadersRewrite` field to `GraphQLProxyConfig` with a
    corresponding `RequestHeadersRewriteConfig` struct.
    - Updated the JSON schema to support the new `request_headers_rewrite`
    configuration, including necessary validations.
    
    
    ___
    
    
    
    ## **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_definitions.go</strong><dd><code>Add Request
    Headers Rewrite Configuration to GraphQL Proxy</code></dd></summary>
    <hr>
    
    apidef/api_definitions.go
    <li>Added a new field <code>RequestHeadersRewrite</code> in
    <code>GraphQLProxyConfig</code> struct.<br> <li> Introduced
    <code>RequestHeadersRewriteConfig</code> struct with fields
    <code>Value</code> and <br><code>Remove</code>.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6257/files#diff-9961ccc89a48d32db5b47ba3006315ef52f6e5007fb4b09f8c5d6d299c669d67">+10/-4</a>&nbsp;
    &nbsp; </td>
    </tr>                    
    
    <tr>
      <td>
        <details>
    <summary><strong>schema.go</strong><dd><code>Update Schema for Request
    Headers Rewrite</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    </dd></summary>
    <hr>
    
    apidef/schema.go
    <li>Updated JSON schema to include <code>request_headers_rewrite</code>
    with properties <br><code>value</code> and <code>remove</code>.<br> <li>
    Added validation requirements for the new properties in the schema.<br>
    
    
    </details>
        
    
      </td>
    <td><a
    href="https://github.com/TykTechnologies/tyk/pull/6257/files#diff-f8a37bb370eb6fe20063786a5e6ea3d85a5c91d8e289f0b3e045830c4d322095">+16/-1</a>&nbsp;
    &nbsp; </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
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants