Skip to content

Commit a46df83

Browse files
committed
undo the changes in clients/
1 parent d9f2f84 commit a46df83

File tree

7 files changed

+462
-18
lines changed

7 files changed

+462
-18
lines changed

clients/client-accessanalyzer/package.json

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
"description": "AWS SDK for JavaScript Accessanalyzer Client for Node.js, Browser and React Native",
44
"version": "3.758.0",
55
"scripts": {
6-
"build": "concurrently 'yarn generate:version' 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types' ",
7-
"build:webpack": "webpack",
6+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
87
"build:cjs": "node ../../scripts/compilation/inline client-accessanalyzer",
98
"build:es": "tsc -p tsconfig.es.json",
109
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
1110
"build:types": "tsc -p tsconfig.types.json",
1211
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1312
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1413
"extract:docs": "api-extractor run --local",
15-
"generate:client": "node ../../scripts/generate-clients/single-service --solo accessanalyzer",
16-
"generate:version": "node src/scripts/generate-version.js"
14+
"generate:client": "node ../../scripts/generate-clients/single-service --solo accessanalyzer"
1715
},
1816
"main": "./dist-cjs/index.js",
1917
"types": "./dist-types/index.d.ts",
@@ -65,23 +63,10 @@
6563
"devDependencies": {
6664
"@tsconfig/node18": "18.2.4",
6765
"@types/node": "^18.19.69",
68-
"@types/path-browserify": "^1",
69-
"@types/webpack-bundle-analyzer": "^4",
70-
"assert": "^2.1.0",
71-
"browserify-zlib": "^0.2.0",
7266
"concurrently": "7.0.0",
7367
"downlevel-dts": "0.10.1",
74-
"http2-wrapper": "^2.2.1",
75-
"https-browserify": "^1.0.0",
76-
"os-browserify": "^0.3.0",
77-
"path-browserify": "^1.0.1",
7868
"rimraf": "3.0.2",
79-
"stream-http": "^3.2.0",
80-
"typescript": "~5.2.2",
81-
"url": "^0.11.4",
82-
"webpack": "^5.97.1",
83-
"webpack-bundle-analyzer": "^4.10.2",
84-
"webpack-cli": "^6.0.1"
69+
"typescript": "~5.2.2"
8570
},
8671
"engines": {
8772
"node": ">=18.0.0"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// smithy-typescript generated code
2+
/* eslint-disable */
3+
/**
4+
* <p>Identity and Access Management Access Analyzer helps you to set, verify, and refine your IAM policies by providing
5+
* a suite of capabilities. Its features include findings for external and unused access,
6+
* basic and custom policy checks for validating policies, and policy generation to generate
7+
* fine-grained policies. To start using IAM Access Analyzer to identify external or unused access,
8+
* you first need to create an analyzer.</p>
9+
* <p>
10+
* <b>External access analyzers</b> help identify potential risks
11+
* of accessing resources by enabling you to identify any resource policies that grant access
12+
* to an external principal. It does this by using logic-based reasoning to analyze
13+
* resource-based policies in your Amazon Web Services environment. An external principal can be another
14+
* Amazon Web Services account, a root user, an IAM user or role, a federated user, an Amazon Web Services service, or an
15+
* anonymous user. You can also use IAM Access Analyzer to preview public and cross-account access
16+
* to your resources before deploying permissions changes.</p>
17+
* <p>
18+
* <b>Unused access analyzers</b> help identify potential
19+
* identity access risks by enabling you to identify unused IAM roles, unused access keys,
20+
* unused console passwords, and IAM principals with unused service and action-level
21+
* permissions.</p>
22+
* <p>Beyond findings, IAM Access Analyzer provides basic and custom policy checks to validate IAM
23+
* policies before deploying permissions changes. You can use policy generation to refine
24+
* permissions by attaching a policy generated using access activity logged in CloudTrail logs. </p>
25+
* <p>This guide describes the IAM Access Analyzer operations that you can call programmatically.
26+
* For general information about IAM Access Analyzer, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/what-is-access-analyzer.html">Identity and Access Management Access Analyzer</a> in the
27+
* <b>IAM User Guide</b>.</p>
28+
*
29+
* @packageDocumentation
30+
*/
31+
export * from "./AccessAnalyzerClient";
32+
export * from "./AccessAnalyzer";
33+
export { ClientInputEndpointParameters } from "./endpoint/EndpointParameters";
34+
export type { RuntimeExtension } from "./runtimeExtensions";
35+
export type { AccessAnalyzerExtensionConfiguration } from "./extensionConfiguration";
36+
export * from "./commands";
37+
export * from "./pagination";
38+
export * from "./models";
39+
40+
export { AccessAnalyzerServiceException } from "./models/AccessAnalyzerServiceException";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// smithy-typescript generated code
2+
// @ts-ignore: package.json will be imported from dist folders
3+
import packageInfo from "../package.json"; // eslint-disable-line
4+
5+
import { Sha256 } from "@aws-crypto/sha256-browser";
6+
import { createDefaultUserAgentProvider } from "@aws-sdk/util-user-agent-browser";
7+
import { DEFAULT_USE_DUALSTACK_ENDPOINT, DEFAULT_USE_FIPS_ENDPOINT } from "@smithy/config-resolver";
8+
import { FetchHttpHandler as RequestHandler, streamCollector } from "@smithy/fetch-http-handler";
9+
import { invalidProvider } from "@smithy/invalid-dependency";
10+
import { calculateBodyLength } from "@smithy/util-body-length-browser";
11+
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@smithy/util-retry";
12+
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
13+
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";
14+
import { loadConfigsForDefaultMode } from "@smithy/smithy-client";
15+
import { resolveDefaultsModeConfig } from "@smithy/util-defaults-mode-browser";
16+
17+
/**
18+
* @internal
19+
*/
20+
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
21+
const defaultsMode = resolveDefaultsModeConfig(config);
22+
const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
23+
const clientSharedValues = getSharedRuntimeConfig(config);
24+
return {
25+
...clientSharedValues,
26+
...config,
27+
runtime: "browser",
28+
defaultsMode,
29+
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
30+
credentialDefaultProvider:
31+
config?.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
32+
defaultUserAgentProvider:
33+
config?.defaultUserAgentProvider ??
34+
createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
35+
maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
36+
region: config?.region ?? invalidProvider("Region is missing"),
37+
requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider),
38+
retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE),
39+
sha256: config?.sha256 ?? Sha256,
40+
streamCollector: config?.streamCollector ?? streamCollector,
41+
useDualstackEndpoint: config?.useDualstackEndpoint ?? (() => Promise.resolve(DEFAULT_USE_DUALSTACK_ENDPOINT)),
42+
useFipsEndpoint: config?.useFipsEndpoint ?? (() => Promise.resolve(DEFAULT_USE_FIPS_ENDPOINT)),
43+
};
44+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// smithy-typescript generated code
2+
// @ts-ignore: package.json will be imported from dist folders
3+
import packageInfo from "../package.json"; // eslint-disable-line
4+
5+
import { emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
6+
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
7+
import { NODE_APP_ID_CONFIG_OPTIONS, createDefaultUserAgentProvider } from "@aws-sdk/util-user-agent-node";
8+
import {
9+
NODE_REGION_CONFIG_FILE_OPTIONS,
10+
NODE_REGION_CONFIG_OPTIONS,
11+
NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS,
12+
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
13+
} from "@smithy/config-resolver";
14+
import { Hash } from "@smithy/hash-node";
15+
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@smithy/middleware-retry";
16+
import { loadConfig as loadNodeConfig } from "@smithy/node-config-provider";
17+
import { NodeHttpHandler as RequestHandler, streamCollector } from "@smithy/node-http-handler";
18+
import { calculateBodyLength } from "@smithy/util-body-length-node";
19+
import { DEFAULT_RETRY_MODE } from "@smithy/util-retry";
20+
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
21+
import { getRuntimeConfig as getSharedRuntimeConfig } from "./runtimeConfig.shared";
22+
import { loadConfigsForDefaultMode } from "@smithy/smithy-client";
23+
import { resolveDefaultsModeConfig } from "@smithy/util-defaults-mode-node";
24+
import { emitWarningIfUnsupportedVersion } from "@smithy/smithy-client";
25+
26+
/**
27+
* @internal
28+
*/
29+
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
30+
emitWarningIfUnsupportedVersion(process.version);
31+
const defaultsMode = resolveDefaultsModeConfig(config);
32+
const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
33+
const clientSharedValues = getSharedRuntimeConfig(config);
34+
awsCheckVersion(process.version);
35+
const profileConfig = { profile: config?.profile };
36+
return {
37+
...clientSharedValues,
38+
...config,
39+
runtime: "node",
40+
defaultsMode,
41+
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
42+
credentialDefaultProvider: config?.credentialDefaultProvider ?? credentialDefaultProvider,
43+
defaultUserAgentProvider:
44+
config?.defaultUserAgentProvider ??
45+
createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
46+
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config),
47+
region:
48+
config?.region ??
49+
loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, { ...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig }),
50+
requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider),
51+
retryMode:
52+
config?.retryMode ??
53+
loadNodeConfig(
54+
{
55+
...NODE_RETRY_MODE_CONFIG_OPTIONS,
56+
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
57+
},
58+
config
59+
),
60+
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
61+
streamCollector: config?.streamCollector ?? streamCollector,
62+
useDualstackEndpoint:
63+
config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig),
64+
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig),
65+
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig),
66+
};
67+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
// Read the package.json file
5+
const packageJson = require("../../package.json");
6+
7+
// Create the version file content
8+
const versionFileContent = `{ "version":"${packageJson.version}" }`;
9+
10+
// Write to a new file
11+
const outputPath = path.join(__dirname, "../../version.json");
12+
fs.writeFileSync(outputPath, versionFileContent);
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { fromEnv } from "@aws-sdk/credential-provider-env";
2+
import { fromIni } from "@aws-sdk/credential-provider-ini";
3+
import { remoteProvider } from "@aws-sdk/credential-provider-node/src/remoteProvider";
4+
import { fromProcess } from "@aws-sdk/credential-provider-process";
5+
import { fromSSO } from "@aws-sdk/credential-provider-sso";
6+
import { fromTokenFile } from "@aws-sdk/credential-provider-web-identity";
7+
import { CredentialsProviderError } from "@smithy/property-provider";
8+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
9+
10+
import { fromAwsCliV2CompatibleProviderChain } from "./fromAwsCliV2CompatibleProviderChain";
11+
12+
vi.mock("@aws-sdk/credential-provider-env");
13+
vi.mock("@aws-sdk/credential-provider-ini");
14+
vi.mock("@aws-sdk/credential-provider-process");
15+
vi.mock("@aws-sdk/credential-provider-sso");
16+
vi.mock("@aws-sdk/credential-provider-web-identity");
17+
vi.mock("@aws-sdk/credential-provider-node/src/remoteProvider");
18+
19+
describe("fromAwsCliV2CompatibleProviderChain", () => {
20+
const mockCreds = {
21+
accessKeyId: "mockAccessKeyId",
22+
secretAccessKey: "mockSecretAccessKey",
23+
};
24+
25+
const mockInit = {
26+
profile: "mockProfile",
27+
logger: {
28+
debug: vi.fn(),
29+
info: vi.fn(),
30+
warn: vi.fn(),
31+
error: vi.fn(),
32+
},
33+
};
34+
35+
const credentials = () => {
36+
throw new CredentialsProviderError("test", true);
37+
};
38+
39+
const finalCredentials = () => {
40+
return mockCreds;
41+
};
42+
43+
const mockEnvFn = vi.fn().mockImplementation(() => credentials());
44+
const mockSsoFn = vi.fn().mockImplementation(() => credentials());
45+
const mockIniFn = vi.fn().mockImplementation(() => credentials());
46+
const mockProcessFn = vi.fn().mockImplementation(() => credentials());
47+
const mockTokenFileFn = vi.fn().mockImplementation(() => credentials());
48+
const mockRemoteProviderFn = vi.fn().mockImplementation(() => finalCredentials());
49+
50+
const ORIGINAL_ENV = { ...process.env };
51+
52+
beforeEach(() => {
53+
process.env = { ...ORIGINAL_ENV };
54+
delete process.env.AWS_PROFILE;
55+
delete process.env.AWS_ACCESS_KEY_ID;
56+
delete process.env.AWS_SECRET_ACCESS_KEY;
57+
58+
vi.mocked(fromEnv).mockReturnValue(mockEnvFn);
59+
vi.mocked(fromSSO).mockReturnValue(mockSsoFn);
60+
vi.mocked(fromIni).mockReturnValue(mockIniFn);
61+
vi.mocked(fromProcess).mockReturnValue(mockProcessFn);
62+
vi.mocked(fromTokenFile).mockReturnValue(mockTokenFileFn);
63+
vi.mocked(remoteProvider).mockReturnValue(mockRemoteProviderFn);
64+
});
65+
66+
afterEach(() => {
67+
vi.clearAllMocks();
68+
process.env = ORIGINAL_ENV;
69+
});
70+
71+
describe("when explicit credentials are provided", () => {
72+
it("should return the provided credentials", async () => {
73+
const credentials = await fromAwsCliV2CompatibleProviderChain({
74+
accessKeyId: "explicitAccessKey",
75+
secretAccessKey: "explicitSecretKey",
76+
})();
77+
78+
expect(credentials).toEqual({
79+
accessKeyId: "explicitAccessKey",
80+
secretAccessKey: "explicitSecretKey",
81+
});
82+
});
83+
});
84+
85+
describe("when profile is provided", () => {
86+
it("should use fromIni to resolve credentials", async () => {
87+
await fromAwsCliV2CompatibleProviderChain({ profile: "mockProfile" })();
88+
expect(fromIni).toHaveBeenCalledWith({ profile: "mockProfile" });
89+
});
90+
});
91+
92+
describe("credential provider chain resolution", () => {
93+
it("should call providers in correct order and return valid credentials", async () => {
94+
const provider = fromAwsCliV2CompatibleProviderChain(mockInit);
95+
96+
const receivedCreds = await provider();
97+
expect(receivedCreds).toEqual(mockCreds);
98+
99+
expect(fromEnv).toHaveBeenCalled();
100+
expect(fromSSO).toHaveBeenCalled();
101+
expect(fromIni).toHaveBeenCalledWith(mockInit);
102+
expect(fromProcess).toHaveBeenCalledWith(mockInit);
103+
expect(fromTokenFile).toHaveBeenCalledWith(mockInit);
104+
expect(remoteProvider).toHaveBeenCalledWith(mockInit);
105+
});
106+
107+
it("should skip fromEnv when profile is explicitly provided", async () => {
108+
await fromAwsCliV2CompatibleProviderChain({ profile: "mockProfile" })();
109+
expect(fromEnv).not.toHaveBeenCalled();
110+
});
111+
112+
it("should throw an error if no credentials are found", async () => {
113+
vi.mocked(fromEnv).mockImplementation(() => credentials());
114+
vi.mocked(fromSSO).mockImplementation(() => credentials());
115+
vi.mocked(fromIni).mockImplementation(() => credentials());
116+
vi.mocked(fromProcess).mockImplementation(() => credentials());
117+
vi.mocked(fromTokenFile).mockImplementation(() => credentials());
118+
vi.mocked(remoteProvider).mockImplementation(() => credentials());
119+
120+
const provider = fromAwsCliV2CompatibleProviderChain(mockInit);
121+
await expect(provider()).rejects.toThrow("Could not load credentials from any providers");
122+
});
123+
});
124+
125+
describe("when AWS_PROFILE is set in the environment", () => {
126+
it("should use fromIni with the environment profile", async () => {
127+
process.env.AWS_PROFILE = "envProfile";
128+
129+
await fromAwsCliV2CompatibleProviderChain({})();
130+
131+
expect(fromIni).toHaveBeenCalledWith({ profile: "envProfile" });
132+
});
133+
});
134+
135+
describe("when credentials are expired or near expiration", () => {
136+
it("should detect expired credentials", () => {
137+
const expiration = new Date(Date.now() - 24 * 60 * 60 * 1000); // Expired
138+
expect(credentialsTreatedAsExpired({ ...mockCreds, expiration })).toBe(true);
139+
});
140+
141+
it("should detect credentials that expire in less than 5 minutes", () => {
142+
const expiration = new Date(Date.now() + 299 * 1000);
143+
expect(credentialsTreatedAsExpired({ ...mockCreds, expiration })).toBe(true);
144+
});
145+
146+
it("should not mark credentials as expired if expiration is more than 5 minutes away", () => {
147+
const expiration = new Date(Date.now() + 301 * 1000);
148+
expect(credentialsTreatedAsExpired({ ...mockCreds, expiration })).toBe(false);
149+
});
150+
151+
it("should assume credentials need refresh if expiration is not set", () => {
152+
expect(credentialsWillNeedRefresh({ ...mockCreds })).toBe(true);
153+
});
154+
});
155+
});

0 commit comments

Comments
 (0)