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

[shared-ini-file-loader] loadSharedConfigFiles is broken on empty value - regression since v2.0.13 #1015

Closed
xfournet opened this issue Oct 9, 2023 · 2 comments · Fixed by #1029
Labels
workaround-available This issue has a work around available.

Comments

@xfournet
Copy link

xfournet commented Oct 9, 2023

Describe the bug

The utility loadSharedConfigFiles incorrecly prefix keys when previous key has an empty value.
In the example below, in latest version, the region key is incorrectly prefixed with cli_pager.

Steps to reproduce

// test.mjs
import { tmpdir } from "os";
import { mkdtemp, rm, writeFile } from "fs/promises";
import { loadSharedConfigFiles } from "@smithy/shared-ini-file-loader";

const tempDir = await mkdtemp(tmpdir());

const filepath = `${tempDir}/credentials`;
await writeFile(filepath, ``);

const configFilepath = `${tempDir}/config`;
await writeFile(
  configFilepath,
  `[profile dev]
cli_pager=  
region = us-east-2`
);

const sharedConfigFiles = await loadSharedConfigFiles({
  filepath,
  configFilepath,
});

console.log(JSON.stringify(sharedConfigFiles, null, 2));

await rm(tempDir, { recursive: true });

Observed behavior

v2.0.12 ✅ correct behavior

{
  "configFile": {
    "dev": {
      "region": "us-east-2"
    }
  },
  "credentialsFile": {}
}

v2.0.13 ❌ incorrect behavior

{
  "configFile": {},
  "credentialsFile": {}
}

v2.1.0 and v2.2.0 ❌ incorrect behavior

{
  "configFile": {
    "dev": {
      "cli_pager.region": "us-east-2"
    }
  },
  "credentialsFile": {}
}

Additional context

The regression comes from 60e88af (#986) and then from aa86b3f (#989)

@trivikr
Copy link
Contributor

trivikr commented Oct 12, 2023

As per the SDK reference for file-format, the subsections appears after the main section. And that's how the JS SDK v3 currently reads the configuration.

A workaround will be to move region above subsection as follows:

[profile dev]
region = us-east-2
cli_pager=  

In the meantime, I'll investigate if we can read values after subsections.

@xfournet
Copy link
Author

@trivikr yes the documentation specify that subsettings should have one or many spaces before. That is workly perfectly with AWS CLI and JS SDK until v2.0.12

I'm rather waiting for a new release instead of using the workaround : it may be costly to identify all the files to be updated, and in some situation I may not have the required permission to update them promptly.

hpmellema pushed a commit to hpmellema/smithy-typescript that referenced this issue Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workaround-available This issue has a work around available.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants