Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
chore: eslint all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Chazal committed Jan 13, 2023
1 parent 1f3c4f5 commit 8f26cee
Show file tree
Hide file tree
Showing 26 changed files with 7,300 additions and 7,149 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ you end up with a tgz package into dist folder importable into your cdk app with
```
"dependencies": {
...
"aws-bootstrap-kit": "file:../../source/aws-bootstrap-kit/dist/js/aws-bootstrap-kit@0.2.4.jsii.tgz",
"aws-bootstrap-kit": "file:../../dist/js/aws-bootstrap-kit@0.2.4.jsii.tgz",
...
}
```
Expand Down
34 changes: 17 additions & 17 deletions src/account-handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import type {
IsCompleteRequest,
IsCompleteResponse,
OnEventResponse,
} from "aws-cdk-lib/custom-resources/lib/provider-framework/types";
} from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';

// eslint-disable-line import/no-extraneous-dependencies
import { Organizations } from "aws-sdk";
import { Organizations } from 'aws-sdk';

/**
* A function capable of creating an account into an AWS Organisation
Expand All @@ -31,24 +31,24 @@ import { Organizations } from "aws-sdk";
*/

export async function onEventHandler(event: any): Promise<OnEventResponse> {
console.log("Event: %j", event);
console.log('Event: %j', event);

switch (event.RequestType) {
case "Create":
const awsOrganizationsClient = new Organizations({ region: "us-east-1" });
case 'Create':
const awsOrganizationsClient = new Organizations({ region: 'us-east-1' });
try {
const data = await awsOrganizationsClient
.createAccount({
Email: event.ResourceProperties.Email,
AccountName: event.ResourceProperties.AccountName,
})
.promise();
console.log("create account: %j", data);
console.log('create account: %j', data);
return { PhysicalResourceId: data.CreateAccountStatus?.Id };
} catch (error) {
throw new Error(`Failed to create account: ${error}`);
}
case "Delete": // only called if the removalPolicy is DESTROY
case 'Delete': // only called if the removalPolicy is DESTROY
throw new Error(`Cannot delete account '${event.PhysicalResourceId}'. See https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_remove.html`);
default:
// just return the resource (we cannot update or delete an account)
Expand All @@ -65,15 +65,15 @@ export async function onEventHandler(event: any): Promise<OnEventResponse> {
* @returns A payload containing the IsComplete Flag requested by cdk Custom Resource fwk to figure out if the resource has been created or failed to be or if it needs to retry
*/
export async function isCompleteHandler(
event: IsCompleteRequest
event: IsCompleteRequest,
): Promise<IsCompleteResponse> {
console.log("Event: %j", event);
console.log('Event: %j', event);

if (!event.PhysicalResourceId) {
throw new Error("Missing PhysicalResourceId parameter.");
throw new Error('Missing PhysicalResourceId parameter.');
}

const awsOrganizationsClient = new Organizations({ region: "us-east-1" });
const awsOrganizationsClient = new Organizations({ region: 'us-east-1' });

const describeCreateAccountStatusParams: Organizations.DescribeCreateAccountStatusRequest =
{ CreateAccountRequestId: event.PhysicalResourceId };
Expand All @@ -82,25 +82,25 @@ export async function isCompleteHandler(
.describeCreateAccountStatus(describeCreateAccountStatusParams)
.promise();

console.log("Describe account: %j", data);
console.log('Describe account: %j', data);

const CreateAccountStatus = data.CreateAccountStatus?.State;
const AccountId = data.CreateAccountStatus?.AccountId;

switch (event.RequestType) {
case "Create":
if (CreateAccountStatus === "FAILED") {
case 'Create':
if (CreateAccountStatus === 'FAILED') {
throw new Error(
`Error creating the account ${data.CreateAccountStatus?.AccountName}, cause: ${data.CreateAccountStatus?.FailureReason}`
`Error creating the account ${data.CreateAccountStatus?.AccountName}, cause: ${data.CreateAccountStatus?.FailureReason}`,
);
}
return {
IsComplete: CreateAccountStatus === "SUCCEEDED",
IsComplete: CreateAccountStatus === 'SUCCEEDED',
Data: { AccountId: AccountId },
};
default:
return {
IsComplete: CreateAccountStatus === "SUCCEEDED",
IsComplete: CreateAccountStatus === 'SUCCEEDED',
Data: { AccountId: AccountId },
};
}
Expand Down
38 changes: 19 additions & 19 deletions src/account-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import {Construct} from 'constructs';
import * as path from 'path';
import { Duration, NestedStack, Stack } from 'aws-cdk-lib';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Duration, NestedStack, Stack } from 'aws-cdk-lib';
import * as cr from 'aws-cdk-lib/custom-resources';
import { Construct } from 'constructs';


/**
Expand Down Expand Up @@ -64,14 +64,14 @@ export class AccountProvider extends NestedStack {
});

this.onEventHandler.addToRolePolicy(
new iam.PolicyStatement({
actions: [
'organizations:CreateAccount',
'organizations:TagResource'
],
resources: ['*'],
}),
);
new iam.PolicyStatement({
actions: [
'organizations:CreateAccount',
'organizations:TagResource',
],
resources: ['*'],
}),
);

// Checks if account is ready
this.isCompleteHandler = new lambda.Function(this, 'IsCompleteHandler', {
Expand All @@ -82,15 +82,15 @@ export class AccountProvider extends NestedStack {
});

this.isCompleteHandler.addToRolePolicy(
new iam.PolicyStatement({
actions: [
'organizations:CreateAccount',
'organizations:DescribeCreateAccountStatus',
'organizations:TagResource'
],
resources: ['*'],
}),
);
new iam.PolicyStatement({
actions: [
'organizations:CreateAccount',
'organizations:DescribeCreateAccountStatus',
'organizations:TagResource',
],
resources: ['*'],
}),
);

this.provider = new cr.Provider(this, 'AccountProvider', {
onEventHandler: this.onEventHandler,
Expand Down
Loading

0 comments on commit 8f26cee

Please sign in to comment.