-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch(feat): octo-aws-cdk | simple-aws-subnet with ability to associa…
…te with siblings.
- Loading branch information
1 parent
04a3cbe
commit 75698a9
Showing
5 changed files
with
241 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../subnet/simple-aws-subnet/models/subnet/actions/update-subnet-association.model.action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { | ||
Action, | ||
type ActionOutputs, | ||
type Diff, | ||
DiffAction, | ||
type EnhancedModuleSchema, | ||
Factory, | ||
type IModelAction, | ||
} from '@quadnix/octo'; | ||
import { NetworkAcl, type NetworkAclSchema } from '../../../../../../resources/network-acl/index.js'; | ||
import type { AwsSubnetModule } from '../../../aws-subnet.module.js'; | ||
import { AwsSubnet } from '../aws.subnet.model.js'; | ||
|
||
@Action(AwsSubnet) | ||
export class UpdateSubnetAssociationModelAction implements IModelAction<AwsSubnetModule> { | ||
filter(diff: Diff): boolean { | ||
return ( | ||
diff.action === DiffAction.ADD && | ||
diff.node instanceof AwsSubnet && | ||
(diff.node.constructor as typeof AwsSubnet).NODE_NAME === 'subnet' && | ||
diff.field === 'sibling' | ||
); | ||
} | ||
|
||
async handle( | ||
diff: Diff, | ||
actionInputs: EnhancedModuleSchema<AwsSubnetModule>, | ||
actionOutputs: ActionOutputs, | ||
): Promise<ActionOutputs> { | ||
const subnet = diff.node as AwsSubnet; | ||
const siblingSubnet = diff.value as AwsSubnet; | ||
|
||
const siblingSubnetInputs = actionInputs.inputs.subnetSiblings || []; | ||
const siblingSubnetInput = siblingSubnetInputs.find((s) => s.subnetName === siblingSubnet.subnetName)!; | ||
const subnetNAcl = actionInputs.resources[`nacl-${subnet.subnetId}`] as NetworkAcl; | ||
|
||
const subnetNAclLastEntryRuleNumber = Math.max(...subnetNAcl.properties.entries.map((e) => e.RuleNumber), 0); | ||
|
||
// Create Network ACL entries. | ||
const subnetNAclEntries: NetworkAclSchema['properties']['entries'] = []; | ||
subnetNAclEntries.push({ | ||
CidrBlock: siblingSubnetInput?.subnetCidrBlock, | ||
Egress: false, | ||
PortRange: { From: -1, To: -1 }, | ||
Protocol: '-1', // All. | ||
RuleAction: 'allow', | ||
RuleNumber: Math.ceil(subnetNAclLastEntryRuleNumber / 10) * 10 + 1, | ||
}); | ||
subnetNAclEntries.push({ | ||
CidrBlock: siblingSubnetInput?.subnetCidrBlock, | ||
Egress: true, | ||
PortRange: { From: -1, To: -1 }, | ||
Protocol: '-1', // All. | ||
RuleAction: 'allow', | ||
RuleNumber: Math.ceil(subnetNAclLastEntryRuleNumber / 10) * 10 + 1, | ||
}); | ||
subnetNAcl.properties.entries.push(...subnetNAclEntries); | ||
|
||
actionOutputs[subnetNAcl.resourceId] = subnetNAcl; | ||
return actionOutputs; | ||
} | ||
} | ||
|
||
@Factory<UpdateSubnetAssociationModelAction>(UpdateSubnetAssociationModelAction) | ||
export class UpdateSubnetAssociationModelActionFactory { | ||
private static instance: UpdateSubnetAssociationModelAction; | ||
|
||
static async create(): Promise<UpdateSubnetAssociationModelAction> { | ||
if (!this.instance) { | ||
this.instance = new UpdateSubnetAssociationModelAction(); | ||
} | ||
return this.instance; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/octo-aws-cdk/src/modules/subnet/simple-aws-subnet/models/subnet/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import './actions/add-subnet.model.action.js'; | ||
import './actions/update-subnet-association.model.action.js'; | ||
|
||
export { AwsSubnet } from './aws.subnet.model.js'; | ||
export { AwsSubnetSchema } from './aws.subnet.schema.js'; |