Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jun 24, 2022
1 parent 0985816 commit 06d1075
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 35 deletions.
28 changes: 14 additions & 14 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -3969,7 +3969,7 @@ const communicationProps: CommunicationProps = { ... }
| <code><a href="#cdktg.CommunicationProps.property.readonly">readonly</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.CommunicationProps.property.usage">usage</a></code> | <code><a href="#cdktg.Usage">Usage</a></code> | *No description.* |
| <code><a href="#cdktg.CommunicationProps.property.vpn">vpn</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.CommunicationProps.property.caller">caller</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |
| <code><a href="#cdktg.CommunicationProps.property.source">source</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |
| <code><a href="#cdktg.CommunicationProps.property.target">target</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |

---
Expand Down Expand Up @@ -4054,10 +4054,10 @@ public readonly vpn: boolean;

---

##### `caller`<sup>Required</sup> <a name="caller" id="cdktg.CommunicationProps.property.caller"></a>
##### `source`<sup>Required</sup> <a name="source" id="cdktg.CommunicationProps.property.source"></a>

```typescript
public readonly caller: TechnicalAsset;
public readonly source: TechnicalAsset;
```

- *Type:* <a href="#cdktg.TechnicalAsset">TechnicalAsset</a>
Expand Down Expand Up @@ -6072,12 +6072,12 @@ public sends(assets: DataAsset): void
| --- | --- | --- |
| <code><a href="#cdktg.Communication.property.authentication">authentication</a></code> | <code><a href="#cdktg.Authentication">Authentication</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.authorization">authorization</a></code> | <code><a href="#cdktg.Authorization">Authorization</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.caller">caller</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.description">description</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cdktg.Communication.property.id">id</a></code> | <code>string</code> | *No description.* |
| <code><a href="#cdktg.Communication.property.ipFiltered">ipFiltered</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.Communication.property.protocol">protocol</a></code> | <code><a href="#cdktg.Protocol">Protocol</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.readonly">readonly</a></code> | <code>boolean</code> | *No description.* |
| <code><a href="#cdktg.Communication.property.source">source</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.target">target</a></code> | <code><a href="#cdktg.TechnicalAsset">TechnicalAsset</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.usage">usage</a></code> | <code><a href="#cdktg.Usage">Usage</a></code> | *No description.* |
| <code><a href="#cdktg.Communication.property.vpn">vpn</a></code> | <code>boolean</code> | *No description.* |
Expand All @@ -6104,16 +6104,6 @@ public readonly authorization: Authorization;

---

##### `caller`<sup>Required</sup> <a name="caller" id="cdktg.Communication.property.caller"></a>

```typescript
public readonly caller: TechnicalAsset;
```

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

---

##### `description`<sup>Required</sup> <a name="description" id="cdktg.Communication.property.description"></a>

```typescript
Expand Down Expand Up @@ -6164,6 +6154,16 @@ public readonly readonly: boolean;

---

##### `source`<sup>Required</sup> <a name="source" id="cdktg.Communication.property.source"></a>

```typescript
public readonly source: TechnicalAsset;
```

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

---

##### `target`<sup>Required</sup> <a name="target" id="cdktg.Communication.property.target"></a>

```typescript
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ project.synth();

### High level constructs (cdktg/plus*)
```typescript
import { ApplicationLoadBalancer, Cloud } from "cdktg/plus_aws";
import { ApplicationLoadBalancer, Cloud } from "cdktg/plus-aws";

// ...

Expand Down
5 changes: 3 additions & 2 deletions src/cli/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from "fs-extra";
import { CommandModule, Arguments, Argv, Options } from "yargs";

import { Threagile } from "../api/threagile";
import { CDKTG_OUT_DIR } from "../common";
import { Manifest } from "../manifest";

interface AnalyzeOptions extends Options {
Expand Down Expand Up @@ -40,14 +41,14 @@ export class AnalyzeCommand<U extends AnalyzeOptions>

const api = new Threagile(url);

const manifest = Manifest.fromPath(".cdktg.out");
const manifest = Manifest.fromPath(CDKTG_OUT_DIR);

for (const k in manifest.models) {
try {
const modelManifest = manifest.models[k];

const resp = await api.analyze(
path.join(".cdktg.out", modelManifest.synthesizedModelPath)
path.join(CDKTG_OUT_DIR, modelManifest.synthesizedModelPath)
);

if (resp.status === 400) {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as path from "path";
import { CommandModule, Arguments, Argv, Options } from "yargs";

import { Threagile } from "../api/threagile";
import { CDKTG_OUT_DIR } from "../common";
import { Manifest } from "../manifest";

interface CheckOptions extends Options {
Expand All @@ -25,7 +26,7 @@ export class CheckCommand<U extends CheckOptions>

const api = new Threagile(url);

const manifest = Manifest.fromPath(".cdktg.out");
const manifest = Manifest.fromPath(CDKTG_OUT_DIR);

for (const k in manifest.models) {
try {
Expand Down
9 changes: 4 additions & 5 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as path from "path";
import * as fs from "fs-extra";
import { CommandModule, Arguments, Argv, Options } from "yargs";

import { CDKTG_VERSION } from "../common";

interface InitOptions extends Options {
language: string;
}
Expand Down Expand Up @@ -79,10 +81,7 @@ project.synth();
}

interface CdktgPackageJson {
version: string;
scripts: Record<string, string>;
peerDependencies: Record<string, string>;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
}

Expand All @@ -103,15 +102,15 @@ function createPackageJson(language: string) {
return {
scripts,
devDependencies: {
cdktg: `^${cdktgJson.version}`,
cdktg: `^${CDKTG_VERSION}`,
},
};
}

return {
scripts,
dependencies: {
cdktg: `^${cdktgJson.version}`,
cdktg: `^${CDKTG_VERSION}`,
constructs: cdktgJson.peerDependencies.constructs,
},
devDependencies: {
Expand Down
8 changes: 8 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const CDKTG_OUT_DIR = ".cdktg.out";

export const IS_TEST_RUN = process.env.NODE_ENV === "test";

// eslint-disable-next-line @typescript-eslint/no-require-imports
const packageVersion = require("../package.json").version;

export const CDKTG_VERSION = packageVersion;
6 changes: 3 additions & 3 deletions src/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export interface CommunicationOptions {
}

export interface CommunicationProps extends CommunicationOptions {
readonly caller: TechnicalAsset;
readonly source: TechnicalAsset;
readonly target: TechnicalAsset;
}

export class Communication {
public readonly id: string;
public readonly caller: TechnicalAsset;
public readonly source: TechnicalAsset;
public readonly target: TechnicalAsset;
public readonly description: string;
public readonly protocol: Protocol;
Expand All @@ -36,7 +36,7 @@ export class Communication {

constructor(id: string, props: CommunicationProps) {
this.id = id;
this.caller = props.caller;
this.source = props.source;
this.target = props.target;
this.description = props.description;
this.protocol = props.protocol;
Expand Down
10 changes: 3 additions & 7 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "path";
import { Construct } from "constructs";
import * as fs from "fs-extra";

import { CDKTG_OUT_DIR, CDKTG_VERSION } from "./common";
import { Manifest } from "./manifest";
import { Model } from "./model";
import { ISynthesisSession } from "./synthesizer";
Expand Down Expand Up @@ -38,18 +38,14 @@ export class Project extends Construct {
constructor(props: ProjectProps = {}) {
super(undefined as any, "");

this.outdir = props.outdir ?? ".cdktg.out";
this.outdir = props.outdir ?? CDKTG_OUT_DIR;
this.skipValidation = props.skipValidation;

const { version } = fs.readJSONSync(
path.join(__dirname, "..", "package.json")
);

if (!fs.existsSync(this.outdir)) {
fs.mkdirSync(this.outdir, { recursive: true });
}

this.manifest = new Manifest(version, this.outdir);
this.manifest = new Manifest(CDKTG_VERSION, this.outdir);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/technical-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class TechnicalAsset extends Resource {
options: CommunicationOptions
): Communication {
const communication = new Communication(id, {
caller: this,
source: this,
target: target,
...options,
});
Expand Down
2 changes: 1 addition & 1 deletion src/trust-boundary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class TrustBoundary extends Resource {

public addTechnicalAssets(...assets: TechnicalAsset[]) {
assets.forEach((a) => {
if (a._trustBoundary) {
if (a._trustBoundary && this !== a._trustBoundary) {
return this.addTrustBoundary(a._trustBoundary);
}

Expand Down

0 comments on commit 06d1075

Please sign in to comment.