Skip to content

Commit

Permalink
fix: PolicyStore field should be mandatory inside PolicyTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
reste85 committed Feb 15, 2024
1 parent 51b1ce3 commit bbcf6de
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 77 deletions.
60 changes: 30 additions & 30 deletions API.md

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ permit (
);`;
const template = new PolicyTemplate(scope, 'PolicyTemplate', {
statement: policyTemplateStatement,
policyStore: policyStore,
});

const policy = new Policy(scope, 'MyTestPolicy', {
Expand Down
2 changes: 1 addition & 1 deletion package.json

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

12 changes: 6 additions & 6 deletions src/policy-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export interface PolicyTemplateProps {
/**
* The policy store that contains the template.
*
* @default - No policy store.
* @default - The policy store to attach the new or updated policy template.
*/
readonly policyStore?: IPolicyStore;
readonly policyStore: IPolicyStore;
}

export interface PolicyTemplateAttributes {
Expand Down Expand Up @@ -65,11 +65,11 @@ export class PolicyTemplate extends PolicyTemplateBase {
}

/**
* Creates a PolicyStore construct that represents an external Policy Store.
* Creates a PolicyTemplate construct that represents an external Policy Template.
*
* @param scope The parent creating construct (usually `this`).
* @param id The construct's name.
* @param attrs A `PolicyStoreAttributes` object.
* @param attrs A `PolicyTemplateAttributes` object.
*/
public static fromPolicyTemplateAttributes(
scope: Construct,
Expand Down Expand Up @@ -113,15 +113,15 @@ export class PolicyTemplate extends PolicyTemplateBase {
/**
* The Policy store that contains the template.
*/
readonly policyStore?: IPolicyStore;
readonly policyStore: IPolicyStore;

constructor(scope: Construct, id: string, props: PolicyTemplateProps) {
super(scope, id);

this.policyTemplate = new CfnPolicyTemplate(this, id, {
statement: props.statement,
description: props.description,
policyStoreId: props.policyStore?.policyStoreId,
policyStoreId: props.policyStore.policyStoreId,
});
this.policyTemplateId = this.policyTemplate.attrPolicyTemplateId;
this.statement = this.policyTemplate.statement;
Expand Down
28 changes: 7 additions & 21 deletions test/policy-template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,31 @@ permit (
);`;

describe('Policy Template creation', () => {
test('Policy Template creation only with Statement', () => {
test('Policy Template creation with Statement and PolicyStore', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack');

// WHEN
new PolicyTemplate(stack, 'PolicyTemplate', {
statement: Statement.fromInline(policyTemplateStatement),
});

// THEN
Template.fromStack(stack).hasResourceProperties(
'AWS::VerifiedPermissions::PolicyTemplate',
{
Statement: policyTemplateStatement,
const policyStore = new PolicyStore(stack, 'PolicyStore', {
validationSettings: {
mode: ValidationSettingsMode.OFF,
},
);
});

test('Policy Template creation with Statement and Description', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack');
});

// WHEN
new PolicyTemplate(stack, 'PolicyTemplate', {
statement: Statement.fromInline(policyTemplateStatement),
description: 'Test Description for Policy Template',
policyStore: policyStore,
});

// THEN
Template.fromStack(stack).hasResourceProperties(
'AWS::VerifiedPermissions::PolicyTemplate',
{
Statement: policyTemplateStatement,
Description: 'Test Description for Policy Template',
},
);
});

test('Policy Template creation with Statement and Description and PolicyStoreId', () => {
test('Policy Template creation with Statement and Description and PolicyStore', () => {
// GIVEN
const stack = new Stack(undefined, 'Stack');
const policyStore = new PolicyStore(stack, 'PolicyStore', {
Expand Down
2 changes: 2 additions & 0 deletions test/policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ when { true };`;
});
const template = new PolicyTemplate(stack, 'PolicyTemplate', {
statement: Statement.fromInline(policyTemplateStatement),
policyStore: policyStore,
});

// Create a policy and add it to the policy store
Expand Down Expand Up @@ -268,6 +269,7 @@ when { true };`;
});
const template = new PolicyTemplate(stack, 'PolicyTemplate', {
statement: Statement.fromInline(policyTemplateStatement),
policyStore: policyStore,
});

// THEN
Expand Down
38 changes: 19 additions & 19 deletions yarn.lock

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

0 comments on commit bbcf6de

Please sign in to comment.