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

Header generation refactoring #2436

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

Header generation refactoring #2436

wants to merge 26 commits into from

Conversation

ATorrise
Copy link
Contributor

@ATorrise ATorrise commented Feb 14, 2025

This refactoring effort centralizes and standardizes header generation across the SDK and CLI.

responseTimeout (and other headers) are now consistently applied in all REST calls and to simplify maintenance and future extensibility.

  • All header logic is now consolidated in a single utility class in ZosFilesHeaders. This replaces duplicate header creation logic across multiple SDK methods and separate header generation functions across the different methods.

  • Header Generation now:

    • depends on:
      • the request options
    • optionally takes:
      • dataLength
      • enum called context where:
        • STREAM and BUFFER: representing any upload/download operation
        • USS
        • ZFS
        • Undefined / Default: when no context is provided, the default is to treat the operation as a Dataset creation.
    (method) ZosFilesHeaders.generateHeaders<T>({ options, context, dataLength, }: {
        options: T;
        context?: ZosFilesContext;
        dataLength?: number | string;
    }): IHeaderContent[]
    Generates an array of headers based on provided options and context.
    
    @param options  The request options.
    
    @param context  The operation context from enum (optional) ie STREAM or ZFS.
    
    @param dataLength  The content length (optional).
    
    @returns  An array of generated headers.

Because of this centralization, any future header changes or additions require modifications in only one location. And creating headers can now be done with a one line function call, without much thought required in future development of the files SDK.

        const reqHeaders = ZosFilesHeaders.generateHeaders({options, dataLength: jsonContent.length});

@ATorrise ATorrise requested review from zFernand0, jace-roell and awharn and removed request for zFernand0 and jace-roell February 14, 2025 21:58
Copy link

github-actions bot commented Feb 14, 2025

📅 Suggested merge-by date: 3/5/2025

Signed-off-by: Amber <[email protected]>
Signed-off-by: Amber <[email protected]>
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.45%. Comparing base (e80dcd2) to head (c62d3f7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2436      +/-   ##
==========================================
- Coverage   91.49%   91.45%   -0.05%     
==========================================
  Files         641      642       +1     
  Lines       18358    18341      -17     
  Branches     3978     3955      -23     
==========================================
- Hits        16796    16773      -23     
- Misses       1560     1566       +6     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Amber Torrise <[email protected]>
@ATorrise ATorrise marked this pull request as draft February 18, 2025 15:40
Copy link
Contributor

@anaxceron anaxceron left a comment

Choose a reason for hiding this comment

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

Left some comments re: changelogs

@ATorrise ATorrise marked this pull request as ready for review February 19, 2025 16:15
Copy link
Member

@awharn awharn left a comment

Choose a reason for hiding this comment

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

I attempted to run a zowe files list ds command on this branch, but it fails with the following error:

Response From Service
TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "undefined"

@@ -84,7 +84,7 @@ describe("Copy", () => {
expect(copyExpectStringSpy).toHaveBeenLastCalledWith(
dummySession,
expectedEndpoint,
expectedHeaders,
expect.arrayContaining(expectedHeaders),
Copy link
Member

Choose a reason for hiding this comment

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

We want to make sure that no extra headers are being defined, so I don't think we should use expect.arrayContaining for headers in our unit tests.

If we need a way to ignore the order of the headers, we could create a Jest helper function that expects the exact same set of items but allows any order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review/QA
Development

Successfully merging this pull request may close these issues.

5 participants