Skip to content

Commit

Permalink
chore: fix credentials loading from ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
OlafConijn committed Jun 3, 2024
1 parent 42b7339 commit f395f33
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-organization-formation",
"version": "1.0.14",
"version": "1.0.15-beta.1",
"description": "Infrastructure as code solution for AWS Organizations",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 6 additions & 2 deletions src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync, readFileSync } from 'fs';
import { Command } from 'commander';
import minimatch from 'minimatch';
import RC from 'rc';
import { fromIni } from '@aws-sdk/credential-provider-ini';
import { AwsUtil } from '../util/aws-util';
import { ConsoleUtil } from '../util/console-util';
import { OrgFormationError } from '../org-formation-error';
Expand Down Expand Up @@ -345,8 +346,11 @@ export abstract class BaseCliCommand<T extends ICommandArgs> {
if (command.debugTemplating) {
NunjucksDebugSettings.debug = true;
}

await AwsUtil.Initialize();
if (command.profile !== undefined) {
await AwsUtil.Initialize(fromIni({ profile: command.profile }));
} else {
await AwsUtil.Initialize();
}
await Promise.all([AwsUtil.GetPartitionFromCurrentSession(), AwsUtil.SetEnabledRegions()]);

command.initialized = true;
Expand Down
50 changes: 28 additions & 22 deletions src/plugin/impl/rp-build-task-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IBuildTaskPluginCommandArgs, IBuildTaskPlugin, CommonTaskAttributeNames
import { IPluginTask, IPluginBinding } from '~plugin/plugin-binder';
import { IPerformTasksCommandArgs } from '~commands/index';
import { Validator } from '~parser/validator';
import { OrgFormationError } from '~org-formation-error';
import { ErrorCode, OrgFormationError } from '~org-formation-error';
import { AwsUtil, BoundCloudFormationClient, CfnUtil } from '~util/aws-util';
import { ConsoleUtil } from '~util/console-util';

Expand Down Expand Up @@ -80,28 +80,34 @@ export class RpBuildTaskPlugin implements IBuildTaskPlugin<IRpBuildTaskConfig, I
}

async performRemove(binding: IPluginBinding<IRpTask> /* , resolver: CfnExpressionResolver*/): Promise<void> {
const cfn = AwsUtil.GetCloudFormationService(binding.target.accountId, binding.target.region, binding.task.taskRoleName, undefined, AwsUtil.GetIsPartition());
let listVersionsResponse: CFN.ListTypeVersionsCommandOutput;
do {
listVersionsResponse = await cfn.send(
new CFN.ListTypeVersionsCommand({
Type: 'RESOURCE',
TypeName: binding.task.resourceType,
NextToken: listVersionsResponse?.NextToken,
}));
for (const version of listVersionsResponse.TypeVersionSummaries) {
if (!version.IsDefaultVersion) {
await cfn.send(
new CFN.DeregisterTypeCommand({
Type: 'RESOURCE',
TypeName: binding.task.resourceType,
VersionId: version.VersionId,
}),
);
try{
const cfn = AwsUtil.GetCloudFormationService(binding.target.accountId, binding.target.region, binding.task.taskRoleName, undefined, AwsUtil.GetIsPartition());
let listVersionsResponse: CFN.ListTypeVersionsCommandOutput;
do {
listVersionsResponse = await cfn.send(
new CFN.ListTypeVersionsCommand({
Type: 'RESOURCE',
TypeName: binding.task.resourceType,
NextToken: listVersionsResponse?.NextToken,
}));
for (const version of listVersionsResponse.TypeVersionSummaries) {
if (!version.IsDefaultVersion) {
await cfn.send(
new CFN.DeregisterTypeCommand({
Type: 'RESOURCE',
TypeName: binding.task.resourceType,
VersionId: version.VersionId,
}),
);
}
}
}
} while (listVersionsResponse.NextToken);
await cfn.send(new CFN.DeregisterTypeCommand({ Type: 'RESOURCE', TypeName: binding.task.resourceType }));
} while (listVersionsResponse.NextToken);
await cfn.send(new CFN.DeregisterTypeCommand({ Type: 'RESOURCE', TypeName: binding.task.resourceType }));


} catch(err) {
throw new OrgFormationError(`error removing resource provider ${binding.target.accountId}/${binding.target.region} ${binding.task.resourceType}.\n error: ${err}`, ErrorCode.FailureToRemove);
}
}

async performCreateOrUpdate(binding: IPluginBinding<IRpTask> /* , resolver: CfnExpressionResolver */): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/util/aws-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ export class CfnUtil {
throw new OrgFormationError(`Stack ${updateStackInput.StackName} seems stuck in UPDATE_IN_PROGRESS (or similar) state.`);
}

ConsoleUtil.LogInfo(`Stack ${updateStackInput.StackName} is already being updated. waiting.... `);
ConsoleUtil.LogInfo(`Stack ${updateStackInput.StackName} in ${cfn.binding.accountId}/${cfn.binding.region} is already being updated. waiting.... `);
retryStackIsBeingUpdatedCount += 1;
await sleep(26 + (4 * Math.random()));
retryStackIsBeingUpdated = true;
Expand Down

0 comments on commit f395f33

Please sign in to comment.