Skip to content

Commit 3631824

Browse files
authored
Merge pull request #10 from teitei-tk/aws_package
append AWS package
2 parents dce14c0 + ea9e460 commit 3631824

File tree

15 files changed

+1774
-52
lines changed

15 files changed

+1774
-52
lines changed

.envrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export TOPDIR=$PWD
2+
export CERTS_DIR=${TOPDIR}/certs
3+
export CERT_KEY_PATH=${CERTS_DIR}/cert.pem
4+
export PRIVATE_KEY_PATH=${CERTS_DIR}/private-key.pem
5+
export PUBLIC_KEY_PATH=${CERTS_DIR}/public-key.pem
6+
export ROOT_KEY_PATH=${CERTS_DIR}/root-CA.pem

boilerplate/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@
33
"version": "1.0.0",
44
"main": "lib/index.ts",
55
"license": "MIT",
6+
"scripts": {
7+
"test": "jest"
8+
},
69
"devDependencies": {
10+
"@types/jest": "^23.3.1",
711
"@types/node": "^10.5.7",
12+
"jest": "^23.5.0",
13+
"ts-jest": "^23.1.3",
814
"typescript": "^3.0.1"
15+
},
16+
"jest": {
17+
"moduleFileExtensions": [ "js", "ts", "tsx" ],
18+
"transform": {
19+
"^.+\\.(ts|tsx)$": "ts-jest"
20+
},
21+
"testMatch": [
22+
"**/__tests__/*.+(ts|tsx|js)"
23+
]
924
}
1025
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"author": "teitei-tk <teitei.tk@gmail.com>",
77
"license": "Apache-2.0",
88
"scripts": {
9-
"bootstrap": "lerna bootstrap"
9+
"bootstrap": "lerna bootstrap",
10+
"test:packages": "lerna run test"
1011
},
1112
"devDependencies": {
1213
"@monorepo-utils/publish": "^1.3.2",

packages/aws/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# AWS
2+
AWS components
3+
4+
## Usage
5+
```js
6+
import { CeritifcateClient } from "@teitei-tk/bravia-aws-package"
7+
8+
const client = new CeritifcateClient();
9+
client.certKeyPath(); // Project/certs/cert.pem
10+
```
11+
12+
## development
13+
```bash
14+
$ yarn install
15+
```
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import * as fs from "fs";
2+
import * as assert from "assert";
3+
4+
import { CertificateClient } from "../lib";
5+
import { CertificateInterface } from "../lib/certificate";
6+
7+
class TestCertificateClient implements CertificateInterface {
8+
certsDirPath(): string {
9+
return "./tmp";
10+
}
11+
12+
certKeyPath(): string {
13+
return `${this.certsDirPath()}/cert.txt`;
14+
}
15+
16+
privateKeyPath(): string {
17+
return `${this.certsDirPath()}/private.txt`;
18+
}
19+
20+
publicKeyPath(): string {
21+
return `${this.certsDirPath()}/public.txt`;
22+
}
23+
24+
rootKeyPath(): string {
25+
return `${this.certsDirPath()}/root.txt`;
26+
}
27+
}
28+
29+
describe("@teitei-tk/bravia-aws-package", () => {
30+
describe("CertificateClient", () => {
31+
let client: CertificateClient;
32+
beforeAll(() => {
33+
client = new CertificateClient(new TestCertificateClient());
34+
35+
// mkdir
36+
const mkdirReuslt = fs.mkdirSync(client.certsDirPath());
37+
assert.equal(mkdirReuslt, undefined);
38+
39+
const certKeyResult = fs.writeFileSync(client.certKeyPath(), "");
40+
assert.equal(certKeyResult, undefined);
41+
42+
const privateKeyResult = fs.writeFileSync(client.privateKeyPath(), "");
43+
assert.equal(privateKeyResult, undefined);
44+
45+
const publicKeyResult = fs.writeFileSync(client.publicKeyPath(), "");
46+
assert.equal(publicKeyResult, undefined);
47+
48+
const rootKeyResult = fs.writeFileSync(client.rootKeyPath(), "");
49+
assert.equal(rootKeyResult, undefined);
50+
});
51+
52+
afterAll(() => {
53+
const certKeyResult = fs.unlinkSync(client.certKeyPath());
54+
assert.equal(certKeyResult, undefined);
55+
56+
const privateKeyResult = fs.unlinkSync(client.privateKeyPath());
57+
assert.equal(privateKeyResult, undefined);
58+
59+
const publicKeyResult = fs.unlinkSync(client.publicKeyPath());
60+
assert.equal(publicKeyResult, undefined);
61+
62+
const rootKeyResult = fs.unlinkSync(client.rootKeyPath());
63+
assert.equal(rootKeyResult, undefined);
64+
65+
// rmdir
66+
const result = fs.rmdirSync(client.certsDirPath());
67+
assert.equal(result, undefined);
68+
});
69+
70+
it("certs dir exists?", () => {
71+
const result = fs.existsSync(client.certsDirPath());
72+
expect(result).toBeTruthy();
73+
});
74+
75+
it("certs key exists?", () => {
76+
const result = fs.existsSync(client.certKeyPath());
77+
expect(result).toBeTruthy();
78+
});
79+
80+
it("private key exists?", () => {
81+
const result = fs.existsSync(client.privateKeyPath());
82+
expect(result).toBeTruthy();
83+
});
84+
85+
it("public key exists?", () => {
86+
const result = fs.existsSync(client.publicKeyPath());
87+
expect(result).toBeTruthy();
88+
});
89+
90+
it("root key exists?", () => {
91+
const result = fs.existsSync(client.rootKeyPath());
92+
expect(result).toBeTruthy();
93+
});
94+
});
95+
});

packages/aws/lib/certificate.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
export interface CertificateInterface {
2+
certsDirPath(): string;
3+
certKeyPath(): string;
4+
privateKeyPath(): string;
5+
publicKeyPath(): string;
6+
rootKeyPath(): string;
7+
}
8+
9+
export class EnvironmentCertificate implements CertificateInterface {
10+
certsDirPath(): string {
11+
return process.env["CERTS_DIR"];
12+
}
13+
14+
certKeyPath(): string {
15+
return process.env["CERT_KEY_PATH"];
16+
}
17+
18+
privateKeyPath(): string {
19+
return process.env["PRIVATE_KEY_PATH"];
20+
}
21+
22+
publicKeyPath(): string {
23+
return process.env["PUBLIC_KEY_PATH"];
24+
}
25+
26+
rootKeyPath(): string {
27+
return process.env["ROOT_KEY_PATH"];
28+
}
29+
}
30+
31+
export class CertificateClient {
32+
certificate: CertificateInterface;
33+
34+
constructor(certificate?: CertificateInterface | null) {
35+
if (certificate == null) {
36+
certificate = new EnvironmentCertificate();
37+
}
38+
39+
this.certificate = certificate;
40+
}
41+
42+
certsDirPath(): string {
43+
return this.certificate.certsDirPath();
44+
}
45+
46+
certKeyPath(): string {
47+
return this.certificate.certKeyPath();
48+
}
49+
50+
privateKeyPath(): string {
51+
return this.certificate.privateKeyPath();
52+
}
53+
54+
publicKeyPath(): string {
55+
return this.certificate.publicKeyPath();
56+
}
57+
58+
rootKeyPath(): string {
59+
return this.certificate.rootKeyPath();
60+
}
61+
}

packages/aws/lib/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { CertificateClient } from "./certificate";
2+
3+
export { CertificateClient };

packages/aws/package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "@teitei-tk/bravia-aws-package",
3+
"version": "1.0.0",
4+
"main": "lib/index.ts",
5+
"license": "Apache-2.0",
6+
"scripts": {
7+
"build": "tsc",
8+
"test": "jest"
9+
},
10+
"files": [
11+
"build/"
12+
],
13+
"devDependencies": {
14+
"@types/jest": "^23.3.1",
15+
"@types/node": "^10.5.7",
16+
"jest": "^23.5.0",
17+
"ts-jest": "^23.1.3",
18+
"typescript": "^3.0.1"
19+
},
20+
"jest": {
21+
"moduleFileExtensions": [ "js", "ts", "tsx" ],
22+
"transform": {
23+
"^.+\\.(ts|tsx)$": "ts-jest"
24+
},
25+
"testMatch": [
26+
"**/__tests__/*.+(ts|tsx|js)"
27+
]
28+
}
29+
}

packages/aws/tsconfig.build.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": "./lib",
5+
"outDir": "./build"
6+
}

packages/aws/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./build"
5+
},
6+
"include": [
7+
"./lib/**/*.ts"
8+
],
9+
"exclude": [
10+
"node_modules/",
11+
]
12+
}

0 commit comments

Comments
 (0)