Skip to content

Commit

Permalink
Add highest availability
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jun 28, 2022
1 parent 378d485 commit cd1961b
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 9 deletions.
86 changes: 86 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ Any object.
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.ciaTriad">ciaTriad</a></code> | <code><a href="#cdktg.CIATriad">CIATriad</a></code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.customDevelopedParts">customDevelopedParts</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.encryption">encryption</a></code> | <code><a href="#cdktg.Encryption">Encryption</a></code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.highestAvailability">highestAvailability</a></code> | <code><a href="#cdktg.Availability">Availability</a></code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.humanUse">humanUse</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.internet">internet</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus_aws.ApplicationLoadBalancer.property.machine">machine</a></code> | <code><a href="#cdktg.Machine">Machine</a></code> | *No description.* |
Expand Down Expand Up @@ -255,6 +256,16 @@ public readonly encryption: Encryption;

---

##### `highestAvailability`<sup>Required</sup> <a name="highestAvailability" id="cdktg.plus_aws.ApplicationLoadBalancer.property.highestAvailability"></a>

```typescript
public readonly highestAvailability: Availability;
```

- *Type:* <a href="#cdktg.Availability">Availability</a>

---

##### `humanUse`<sup>Required</sup> <a name="humanUse" id="cdktg.plus_aws.ApplicationLoadBalancer.property.humanUse"></a>

```typescript
Expand Down Expand Up @@ -570,6 +581,7 @@ Any object.
| <code><a href="#cdktg.plus.Browser.property.ciaTriad">ciaTriad</a></code> | <code><a href="#cdktg.CIATriad">CIATriad</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.customDevelopedParts">customDevelopedParts</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.encryption">encryption</a></code> | <code><a href="#cdktg.Encryption">Encryption</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.highestAvailability">highestAvailability</a></code> | <code><a href="#cdktg.Availability">Availability</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.humanUse">humanUse</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.internet">internet</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Browser.property.machine">machine</a></code> | <code><a href="#cdktg.Machine">Machine</a></code> | *No description.* |
Expand Down Expand Up @@ -648,6 +660,16 @@ public readonly encryption: Encryption;

---

##### `highestAvailability`<sup>Required</sup> <a name="highestAvailability" id="cdktg.plus.Browser.property.highestAvailability"></a>

```typescript
public readonly highestAvailability: Availability;
```

- *Type:* <a href="#cdktg.Availability">Availability</a>

---

##### `humanUse`<sup>Required</sup> <a name="humanUse" id="cdktg.plus.Browser.property.humanUse"></a>

```typescript
Expand Down Expand Up @@ -2705,6 +2727,7 @@ Any object.
| <code><a href="#cdktg.TechnicalAsset.property.ciaTriad">ciaTriad</a></code> | <code><a href="#cdktg.CIATriad">CIATriad</a></code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.customDevelopedParts">customDevelopedParts</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.encryption">encryption</a></code> | <code><a href="#cdktg.Encryption">Encryption</a></code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.highestAvailability">highestAvailability</a></code> | <code><a href="#cdktg.Availability">Availability</a></code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.humanUse">humanUse</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.internet">internet</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.TechnicalAsset.property.machine">machine</a></code> | <code><a href="#cdktg.Machine">Machine</a></code> | *No description.* |
Expand Down Expand Up @@ -2783,6 +2806,16 @@ public readonly encryption: Encryption;

---

##### `highestAvailability`<sup>Required</sup> <a name="highestAvailability" id="cdktg.TechnicalAsset.property.highestAvailability"></a>

```typescript
public readonly highestAvailability: Availability;
```

- *Type:* <a href="#cdktg.Availability">Availability</a>

---

##### `humanUse`<sup>Required</sup> <a name="humanUse" id="cdktg.TechnicalAsset.property.humanUse"></a>

```typescript
Expand Down Expand Up @@ -3298,6 +3331,7 @@ Any object.
| <code><a href="#cdktg.plus.Vault.property.ciaTriad">ciaTriad</a></code> | <code><a href="#cdktg.CIATriad">CIATriad</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.customDevelopedParts">customDevelopedParts</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.encryption">encryption</a></code> | <code><a href="#cdktg.Encryption">Encryption</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.highestAvailability">highestAvailability</a></code> | <code><a href="#cdktg.Availability">Availability</a></code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.humanUse">humanUse</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.internet">internet</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.plus.Vault.property.machine">machine</a></code> | <code><a href="#cdktg.Machine">Machine</a></code> | *No description.* |
Expand Down Expand Up @@ -3378,6 +3412,16 @@ public readonly encryption: Encryption;

---

##### `highestAvailability`<sup>Required</sup> <a name="highestAvailability" id="cdktg.plus.Vault.property.highestAvailability"></a>

```typescript
public readonly highestAvailability: Availability;
```

- *Type:* <a href="#cdktg.Availability">Availability</a>

---

##### `humanUse`<sup>Required</sup> <a name="humanUse" id="cdktg.plus.Vault.property.humanUse"></a>

```typescript
Expand Down Expand Up @@ -5935,6 +5979,25 @@ new CIATriad(props: CIATriadProps)

---

#### Methods <a name="Methods" id="Methods"></a>

| **Name** | **Description** |
| --- | --- |
| <code><a href="#cdktg.CIATriad.hasHigherAvailabilty">hasHigherAvailabilty</a></code> | *No description.* |

---

##### `hasHigherAvailabilty` <a name="hasHigherAvailabilty" id="cdktg.CIATriad.hasHigherAvailabilty"></a>

```typescript
public hasHigherAvailabilty(availability: Availability): boolean
```

###### `availability`<sup>Required</sup> <a name="availability" id="cdktg.CIATriad.hasHigherAvailabilty.parameter.availability"></a>

- *Type:* <a href="#cdktg.Availability">Availability</a>

---


#### Properties <a name="Properties" id="Properties"></a>
Expand Down Expand Up @@ -6979,6 +7042,29 @@ public readonly SECURING_ADMINISTRATIVE_ACCESS: SecurityRequirement;

---

### Testing <a name="Testing" id="cdktg.Testing"></a>

Testing utilities for cdktg models.


#### Static Functions <a name="Static Functions" id="Static Functions"></a>

| **Name** | **Description** |
| --- | --- |
| <code><a href="#cdktg.Testing.model">model</a></code> | *No description.* |

---

##### `model` <a name="model" id="cdktg.Testing.model"></a>

```typescript
import { Testing } from 'cdktg'

Testing.model()
```



## Protocols <a name="Protocols" id="Protocols"></a>

### IAspect <a name="IAspect" id="cdktg.IAspect"></a>
Expand Down
15 changes: 15 additions & 0 deletions src/cia-triad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export class CIATriad {
this.justification = props.justification;
}

public hasHigherAvailabilty(availability: Availability): boolean {
const availabilityRank: Record<Availability, number> = {
[Availability.ARCHIVE]: 0,
[Availability.OPERATIONAL]: 1,
[Availability.IMPORTANT]: 2,
[Availability.CRITICAL]: 3,
[Availability.MISSION_CRITICAL]: 4,
};

const thisRank = availabilityRank[this.availability];
const thatRank = availabilityRank[availability];

return thisRank > thatRank;
}

/**
* @internal
*/
Expand Down
40 changes: 31 additions & 9 deletions src/technical-asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct } from "constructs";

import { CIATriad } from "./cia-triad";
import { Availability, CIATriad } from "./cia-triad";
import { Communication, CommunicationOptions } from "./communication";
import { DataAsset } from "./data-asset";
import { Model } from "./model";
Expand Down Expand Up @@ -50,8 +50,8 @@ export class TechnicalAsset extends Resource {

protected trustBoundary?: TrustBoundary;

private dataAssetsProcessed: Set<string>;
private dataAssetsStored: Set<string>;
private dataAssetsProcessed: Set<DataAsset>;
private dataAssetsStored: Set<DataAsset>;
private communications: Communication[];

constructor(scope: Construct, id: string, props: TechnicalAssetProps) {
Expand All @@ -74,8 +74,8 @@ export class TechnicalAsset extends Resource {
this.customDevelopedParts = props.customDevelopedParts ?? false;
this.dataFormatsAccepted = props.dataFormatsAccepted;

this.dataAssetsProcessed = new Set<string>();
this.dataAssetsStored = new Set<string>();
this.dataAssetsProcessed = new Set<DataAsset>();
this.dataAssetsStored = new Set<DataAsset>();

this.communications = new Array<Communication>();

Expand All @@ -91,13 +91,13 @@ export class TechnicalAsset extends Resource {

public processes(...assets: DataAsset[]) {
assets.forEach((a) => {
this.dataAssetsProcessed.add(a.uuid);
this.dataAssetsProcessed.add(a);
});
}

public stores(...assets: DataAsset[]) {
assets.forEach((a) => {
this.dataAssetsStored.add(a.uuid);
this.dataAssetsStored.add(a);
});
}

Expand Down Expand Up @@ -127,6 +127,24 @@ export class TechnicalAsset extends Resource {
].includes(this.technology);
}

public get highestAvailability(): Availability {
let { availability: highest } = this.ciaTriad;

this.dataAssetsProcessed.forEach((a) => {
if (a.ciaTriad.hasHigherAvailabilty(highest)) {
highest = a.ciaTriad.availability;
}
});

this.dataAssetsStored.forEach((a) => {
if (a.ciaTriad.hasHigherAvailabilty(highest)) {
highest = a.ciaTriad.availability;
}
});

return highest;
}

public communicatesWith(
id: string,
target: TechnicalAsset,
Expand Down Expand Up @@ -173,8 +191,12 @@ export class TechnicalAsset extends Resource {
multitenant: this.multiTenant,
redundant: this.redundant,
custom_developed_parts: this.customDevelopedParts,
data_assets_processed: Array.from(this.dataAssetsProcessed),
data_assets_stored: Array.from(this.dataAssetsStored),
data_assets_processed: Array.from(this.dataAssetsProcessed).map(
(a) => a.uuid
),
data_assets_stored: Array.from(this.dataAssetsStored).map(
(a) => a.uuid
),
data_formats_accepted: this.dataFormatsAccepted,
},
};
Expand Down
101 changes: 101 additions & 0 deletions test/technical-asset.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {
TechnicalAsset,
Testing,
CIATriad,
TechnicalAssetType,
Usage,
Size,
Model,
Technology,
Machine,
Encryption,
Confidentiality,
Availability,
Integrity,
DataAsset,
Quantity,
} from "../src";

describe("highest availability", () => {
let model: Model;
let technicalAsset: TechnicalAsset;

beforeEach(() => {
model = Testing.model();

technicalAsset = new TechnicalAsset(model, "Some Technical Asset", {
description: "Some Description",
type: TechnicalAssetType.PROCESS,
usage: Usage.BUSINESS,
humanUse: false,
size: Size.COMPONENT,
technology: Technology.WEB_SERVICE_REST,
tags: ["some-tag", "some-other-tag"],
internet: false,
machine: Machine.VIRTUAL,
encryption: Encryption.NONE,
owner: "Some Owner",
ciaTriad: new CIATriad({
confidentiality: Confidentiality.CONFIDENTIAL,
integrity: Integrity.CRITICAL,
availability: Availability.IMPORTANT,
}),
multiTenant: false,
redundant: true,
});
});

test("without data asset", () => {
expect(technicalAsset.highestAvailability).toBe(
technicalAsset.ciaTriad.availability
);
});

test("with critical data asset processed", () => {
const expected = Availability.CRITICAL;

technicalAsset.processes(
new DataAsset(model, "Data Asset Processed", {
usage: Usage.BUSINESS,
quantity: Quantity.MANY,
ciaTriad: new CIATriad({
availability: expected,
integrity: Integrity.IMPORTANT,
confidentiality: Confidentiality.RESTRICTED,
}),
})
);

expect(technicalAsset.highestAvailability).toBe(expected);
});

test("with mission critical data asset stored", () => {
const expected = Availability.MISSION_CRITICAL;

technicalAsset.processes(
new DataAsset(model, "Data Asset Processed", {
usage: Usage.BUSINESS,
quantity: Quantity.MANY,
ciaTriad: new CIATriad({
availability: Availability.CRITICAL,
integrity: Integrity.IMPORTANT,
confidentiality: Confidentiality.RESTRICTED,
}),
})
);

technicalAsset.stores(
new DataAsset(model, "Data Asset Stored", {
usage: Usage.BUSINESS,
quantity: Quantity.MANY,
ciaTriad: new CIATriad({
availability: expected,
integrity: Integrity.IMPORTANT,
confidentiality: Confidentiality.RESTRICTED,
}),
})
);

expect(technicalAsset.highestAvailability).toBe(expected);
});
});

0 comments on commit cd1961b

Please sign in to comment.