fanqiang 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +202 -0
- package/README.md +78 -0
- package/bin/fanqiang.d.ts +3 -0
- package/bin/fanqiang.d.ts.map +1 -0
- package/bin/fanqiang.js +31 -0
- package/bin/fanqiang.js.map +1 -0
- package/bin/fanqiang.ts +35 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/index.ts +3 -0
- package/lib/core/AwsS3CloudStorage.d.ts +6 -0
- package/lib/core/AwsS3CloudStorage.d.ts.map +1 -0
- package/lib/core/AwsS3CloudStorage.js +70 -0
- package/lib/core/AwsS3CloudStorage.js.map +1 -0
- package/lib/core/AwsS3CloudStorage.ts +90 -0
- package/lib/core/Configuration.d.ts +15 -0
- package/lib/core/Configuration.d.ts.map +1 -0
- package/lib/core/Configuration.js +24 -0
- package/lib/core/Configuration.js.map +1 -0
- package/lib/core/Configuration.ts +33 -0
- package/lib/core/StoredOptions.d.ts +18 -0
- package/lib/core/StoredOptions.d.ts.map +1 -0
- package/lib/core/StoredOptions.js +30 -0
- package/lib/core/StoredOptions.js.map +1 -0
- package/lib/core/StoredOptions.ts +37 -0
- package/lib/core/TerraformTunnelProxyOperations.d.ts +9 -0
- package/lib/core/TerraformTunnelProxyOperations.d.ts.map +1 -0
- package/lib/core/TerraformTunnelProxyOperations.js +38 -0
- package/lib/core/TerraformTunnelProxyOperations.js.map +1 -0
- package/lib/core/TerraformTunnelProxyOperations.ts +43 -0
- package/lib/core/aliyunCredentials.d.ts +7 -0
- package/lib/core/aliyunCredentials.d.ts.map +1 -0
- package/lib/core/aliyunCredentials.js +29 -0
- package/lib/core/aliyunCredentials.js.map +1 -0
- package/lib/core/aliyunCredentials.ts +30 -0
- package/lib/core/langUtils.d.ts +11 -0
- package/lib/core/langUtils.d.ts.map +1 -0
- package/lib/core/langUtils.js +69 -0
- package/lib/core/langUtils.js.map +1 -0
- package/lib/core/langUtils.ts +71 -0
- package/lib/core/terraform.d.ts +5 -0
- package/lib/core/terraform.d.ts.map +1 -0
- package/lib/core/terraform.js +90 -0
- package/lib/core/terraform.js.map +1 -0
- package/lib/core/terraform.ts +99 -0
- package/lib/domain/Clash.d.ts +6 -0
- package/lib/domain/Clash.d.ts.map +1 -0
- package/lib/domain/Clash.js +24 -0
- package/lib/domain/Clash.js.map +1 -0
- package/lib/domain/Clash.ts +24 -0
- package/lib/domain/CloudStorage.d.ts +9 -0
- package/lib/domain/CloudStorage.d.ts.map +1 -0
- package/lib/domain/CloudStorage.js +3 -0
- package/lib/domain/CloudStorage.js.map +1 -0
- package/lib/domain/CloudStorage.ts +11 -0
- package/lib/domain/TunnelProxyOperations.d.ts +19 -0
- package/lib/domain/TunnelProxyOperations.d.ts.map +1 -0
- package/lib/domain/TunnelProxyOperations.js +3 -0
- package/lib/domain/TunnelProxyOperations.js.map +1 -0
- package/lib/domain/TunnelProxyOperations.ts +19 -0
- package/lib/handlers.d.ts +3 -0
- package/lib/handlers.d.ts.map +1 -0
- package/lib/handlers.js +27 -0
- package/lib/handlers.js.map +1 -0
- package/lib/handlers.ts +28 -0
- package/package.json +81 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"AwsS3CloudStorage.js","sourceRoot":"","sources":["AwsS3CloudStorage.ts"],"names":[],"mappings":"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"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import {
|
2
|
+
CreateBucketCommand,
|
3
|
+
DeleteBucketCommand,
|
4
|
+
DeleteObjectsCommand,
|
5
|
+
GetBucketLocationCommand,
|
6
|
+
ListObjectsV2Command,
|
7
|
+
ListObjectsV2CommandInput,
|
8
|
+
ListObjectsV2CommandOutput,
|
9
|
+
PutObjectCommand,
|
10
|
+
S3Client,
|
11
|
+
} from "@aws-sdk/client-s3";
|
12
|
+
import { invokeIgnoreError, nonNullArray, Strict } from "./langUtils";
|
13
|
+
import { Bucket, CloudStorage } from "../domain/CloudStorage";
|
14
|
+
|
15
|
+
export class AwsS3CloudStorage implements CloudStorage {
|
16
|
+
async getBucket(region: string): Promise<Bucket> {
|
17
|
+
const bucket = `fanqiang${Date.now()}`;
|
18
|
+
await runWithClient(region, async (client) => {
|
19
|
+
try {
|
20
|
+
await client.send(new GetBucketLocationCommand({ Bucket: bucket }));
|
21
|
+
} catch (e) {
|
22
|
+
if (e.name !== "NoSuchBucket") {
|
23
|
+
throw e;
|
24
|
+
}
|
25
|
+
await client.send(new CreateBucketCommand({ Bucket: bucket, ACL: "public-read" }));
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
29
|
+
return {
|
30
|
+
name: bucket,
|
31
|
+
save: async (objectKey: string, content: string) => {
|
32
|
+
await runWithClient(region, (client) =>
|
33
|
+
client.send(
|
34
|
+
new PutObjectCommand({
|
35
|
+
Bucket: bucket,
|
36
|
+
Key: objectKey,
|
37
|
+
Body: content,
|
38
|
+
ACL: "public-read",
|
39
|
+
})
|
40
|
+
)
|
41
|
+
);
|
42
|
+
return `http://${bucket}.s3.amazonaws.com/${objectKey}`;
|
43
|
+
},
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
async destroy(region: string, bucket: string): Promise<void> {
|
48
|
+
await runWithClient(region, (client) =>
|
49
|
+
invokeIgnoreError(
|
50
|
+
async () => {
|
51
|
+
const keys = await listObjectKeys(bucket, client);
|
52
|
+
if (keys.length) {
|
53
|
+
await client.send(
|
54
|
+
new DeleteObjectsCommand({
|
55
|
+
Bucket: bucket,
|
56
|
+
Delete: { Objects: keys.map((k) => ({ Key: k })) },
|
57
|
+
})
|
58
|
+
);
|
59
|
+
}
|
60
|
+
await client.send(new DeleteBucketCommand({ Bucket: bucket }));
|
61
|
+
},
|
62
|
+
"NoSuchBucket",
|
63
|
+
"Bucket does not exists: " + bucket
|
64
|
+
)
|
65
|
+
);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
async function runWithClient<R>(region: string, executeFunc: (client: S3Client) => Promise<R>) {
|
70
|
+
const client = new S3Client({ region });
|
71
|
+
try {
|
72
|
+
return await executeFunc(client);
|
73
|
+
} finally {
|
74
|
+
client.destroy();
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
async function listObjectKeys(Bucket: string, client: S3Client): Promise<string[]> {
|
79
|
+
let response: ListObjectsV2CommandOutput;
|
80
|
+
const params: Strict<ListObjectsV2CommandInput> = { Bucket };
|
81
|
+
const objectKeys: string[] = [];
|
82
|
+
do {
|
83
|
+
response = await client.send(new ListObjectsV2Command(params));
|
84
|
+
if (response.KeyCount) {
|
85
|
+
objectKeys.push(...nonNullArray(response.Contents?.map((c) => <string>c.Key)));
|
86
|
+
}
|
87
|
+
params.ContinuationToken = response.NextContinuationToken;
|
88
|
+
} while (response.IsTruncated);
|
89
|
+
return objectKeys;
|
90
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { AliyunCredentials } from "./aliyunCredentials";
|
2
|
+
import { CloudStorage } from "../domain/CloudStorage";
|
3
|
+
import { StoredOptionsRepository } from "./StoredOptions";
|
4
|
+
import { TunnelProxyOperations } from "../domain/TunnelProxyOperations";
|
5
|
+
export declare const APP_NAME = "fanqiang";
|
6
|
+
export interface Configuration {
|
7
|
+
aliyun: {
|
8
|
+
credentials: AliyunCredentials;
|
9
|
+
};
|
10
|
+
cloudStorage: CloudStorage;
|
11
|
+
storedOptionsRepository: StoredOptionsRepository;
|
12
|
+
tunnelProxyOperations?: TunnelProxyOperations;
|
13
|
+
}
|
14
|
+
export declare function loadConfiguration(): Promise<Configuration>;
|
15
|
+
//# sourceMappingURL=Configuration.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Configuration.d.ts","sourceRoot":"","sources":["Configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAGzE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAoC,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,eAAO,MAAM,QAAQ,aAAa,CAAC;AAEnC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE;QACN,WAAW,EAAE,iBAAiB,CAAC;KAChC,CAAC;IACF,YAAY,EAAE,YAAY,CAAC;IAC3B,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;CAC/C;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC,CAYhE"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.loadConfiguration = exports.APP_NAME = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const aliyunCredentials_1 = require("./aliyunCredentials");
|
6
|
+
const path = tslib_1.__importStar(require("path"));
|
7
|
+
const os_1 = require("os");
|
8
|
+
const AwsS3CloudStorage_1 = require("./AwsS3CloudStorage");
|
9
|
+
const StoredOptions_1 = require("./StoredOptions");
|
10
|
+
const TerraformTunnelProxyOperations_1 = require("./TerraformTunnelProxyOperations");
|
11
|
+
exports.APP_NAME = "fanqiang";
|
12
|
+
async function loadConfiguration() {
|
13
|
+
const configuration = {
|
14
|
+
aliyun: {
|
15
|
+
credentials: await aliyunCredentials_1.loadCredentials(),
|
16
|
+
},
|
17
|
+
cloudStorage: new AwsS3CloudStorage_1.AwsS3CloudStorage(),
|
18
|
+
storedOptionsRepository: new StoredOptions_1.LocalFileStoredOptionsRepository(path.join(os_1.homedir(), ".config", exports.APP_NAME, "options.json")),
|
19
|
+
};
|
20
|
+
configuration.tunnelProxyOperations = new TerraformTunnelProxyOperations_1.TerraformTunnelProxyOperations(configuration);
|
21
|
+
return configuration;
|
22
|
+
}
|
23
|
+
exports.loadConfiguration = loadConfiguration;
|
24
|
+
//# sourceMappingURL=Configuration.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Configuration.js","sourceRoot":"","sources":["Configuration.ts"],"names":[],"mappings":";;;;AAAA,2DAAyE;AACzE,mDAA6B;AAC7B,2BAA6B;AAE7B,2DAAwD;AACxD,mDAA4F;AAE5F,qFAAkF;AAErE,QAAA,QAAQ,GAAG,UAAU,CAAC;AAW5B,KAAK,UAAU,iBAAiB;IACrC,MAAM,aAAa,GAAkB;QACnC,MAAM,EAAE;YACN,WAAW,EAAE,MAAM,mCAAe,EAAE;SACrC;QACD,YAAY,EAAE,IAAI,qCAAiB,EAAE;QACrC,uBAAuB,EAAE,IAAI,gDAAgC,CAC3D,IAAI,CAAC,IAAI,CAAC,YAAO,EAAE,EAAE,SAAS,EAAE,gBAAQ,EAAE,cAAc,CAAC,CAC1D;KACF,CAAC;IACF,aAAa,CAAC,qBAAqB,GAAG,IAAI,+DAA8B,CAAC,aAAa,CAAC,CAAC;IACxF,OAAO,aAAa,CAAC;AACvB,CAAC;AAZD,8CAYC"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { AliyunCredentials, loadCredentials } from "./aliyunCredentials";
|
2
|
+
import * as path from "path";
|
3
|
+
import { homedir } from "os";
|
4
|
+
import { CloudStorage } from "../domain/CloudStorage";
|
5
|
+
import { AwsS3CloudStorage } from "./AwsS3CloudStorage";
|
6
|
+
import { LocalFileStoredOptionsRepository, StoredOptionsRepository } from "./StoredOptions";
|
7
|
+
import { TunnelProxyOperations } from "../domain/TunnelProxyOperations";
|
8
|
+
import { TerraformTunnelProxyOperations } from "./TerraformTunnelProxyOperations";
|
9
|
+
|
10
|
+
export const APP_NAME = "fanqiang";
|
11
|
+
|
12
|
+
export interface Configuration {
|
13
|
+
aliyun: {
|
14
|
+
credentials: AliyunCredentials;
|
15
|
+
};
|
16
|
+
cloudStorage: CloudStorage;
|
17
|
+
storedOptionsRepository: StoredOptionsRepository;
|
18
|
+
tunnelProxyOperations?: TunnelProxyOperations;
|
19
|
+
}
|
20
|
+
|
21
|
+
export async function loadConfiguration(): Promise<Configuration> {
|
22
|
+
const configuration: Configuration = {
|
23
|
+
aliyun: {
|
24
|
+
credentials: await loadCredentials(),
|
25
|
+
},
|
26
|
+
cloudStorage: new AwsS3CloudStorage(),
|
27
|
+
storedOptionsRepository: new LocalFileStoredOptionsRepository(
|
28
|
+
path.join(homedir(), ".config", APP_NAME, "options.json")
|
29
|
+
),
|
30
|
+
};
|
31
|
+
configuration.tunnelProxyOperations = new TerraformTunnelProxyOperations(configuration);
|
32
|
+
return configuration;
|
33
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { TunnelProxyCreatingRequest } from "../domain/TunnelProxyOperations";
|
2
|
+
export interface StoredOptions {
|
3
|
+
bucket: string;
|
4
|
+
request: TunnelProxyCreatingRequest;
|
5
|
+
}
|
6
|
+
export interface StoredOptionsRepository {
|
7
|
+
save(storedOptions: StoredOptions): Promise<void>;
|
8
|
+
load(): Promise<StoredOptions | undefined>;
|
9
|
+
delete(): Promise<void>;
|
10
|
+
}
|
11
|
+
export declare class LocalFileStoredOptionsRepository implements StoredOptionsRepository {
|
12
|
+
private readonly filePath;
|
13
|
+
constructor(filePath: string);
|
14
|
+
delete(): Promise<void>;
|
15
|
+
load(): Promise<StoredOptions | undefined>;
|
16
|
+
save(storedOptions: StoredOptions): Promise<void>;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=StoredOptions.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"StoredOptions.d.ts","sourceRoot":"","sources":["StoredOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAG7E,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,0BAA0B,CAAC;CACrC;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAC3C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,qBAAa,gCAAiC,YAAW,uBAAuB;IAClE,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAEvC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAQvB,IAAI,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAO1C,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAIxD"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LocalFileStoredOptionsRepository = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const fs = tslib_1.__importStar(require("fs-extra"));
|
6
|
+
class LocalFileStoredOptionsRepository {
|
7
|
+
constructor(filePath) {
|
8
|
+
this.filePath = filePath;
|
9
|
+
}
|
10
|
+
async delete() {
|
11
|
+
try {
|
12
|
+
await fs.rm(this.filePath, { force: true });
|
13
|
+
}
|
14
|
+
catch (e) {
|
15
|
+
console.log(e.message);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
async load() {
|
19
|
+
if (!(await fs.pathExists(this.filePath))) {
|
20
|
+
return undefined;
|
21
|
+
}
|
22
|
+
return await fs.readJSON(this.filePath);
|
23
|
+
}
|
24
|
+
async save(storedOptions) {
|
25
|
+
await fs.ensureFile(this.filePath);
|
26
|
+
await fs.writeJson(this.filePath, storedOptions);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.LocalFileStoredOptionsRepository = LocalFileStoredOptionsRepository;
|
30
|
+
//# sourceMappingURL=StoredOptions.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"StoredOptions.js","sourceRoot":"","sources":["StoredOptions.ts"],"names":[],"mappings":";;;;AACA,qDAA+B;AAa/B,MAAa,gCAAgC;IAC3C,YAA6B,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IAAG,CAAC;IAEjD,KAAK,CAAC,MAAM;QACV,IAAI;YACF,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;SAC7C;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACxB;IACH,CAAC;IAED,KAAK,CAAC,IAAI;QACR,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE;YACzC,OAAO,SAAS,CAAC;SAClB;QACD,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,aAA4B;QACrC,MAAM,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACnD,CAAC;CACF;AAtBD,4EAsBC"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { TunnelProxyCreatingRequest } from "../domain/TunnelProxyOperations";
|
2
|
+
import * as fs from "fs-extra";
|
3
|
+
|
4
|
+
export interface StoredOptions {
|
5
|
+
bucket: string;
|
6
|
+
request: TunnelProxyCreatingRequest;
|
7
|
+
}
|
8
|
+
|
9
|
+
export interface StoredOptionsRepository {
|
10
|
+
save(storedOptions: StoredOptions): Promise<void>;
|
11
|
+
load(): Promise<StoredOptions | undefined>;
|
12
|
+
delete(): Promise<void>;
|
13
|
+
}
|
14
|
+
|
15
|
+
export class LocalFileStoredOptionsRepository implements StoredOptionsRepository {
|
16
|
+
constructor(private readonly filePath: string) {}
|
17
|
+
|
18
|
+
async delete(): Promise<void> {
|
19
|
+
try {
|
20
|
+
await fs.rm(this.filePath, { force: true });
|
21
|
+
} catch (e) {
|
22
|
+
console.log(e.message);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
async load(): Promise<StoredOptions | undefined> {
|
27
|
+
if (!(await fs.pathExists(this.filePath))) {
|
28
|
+
return undefined;
|
29
|
+
}
|
30
|
+
return await fs.readJSON(this.filePath);
|
31
|
+
}
|
32
|
+
|
33
|
+
async save(storedOptions: StoredOptions): Promise<void> {
|
34
|
+
await fs.ensureFile(this.filePath);
|
35
|
+
await fs.writeJson(this.filePath, storedOptions);
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { TunnelProxyCreatingRequest, TunnelProxyCreatingResult, TunnelProxyOperations } from "../domain/TunnelProxyOperations";
|
2
|
+
import { Configuration } from "./Configuration";
|
3
|
+
export declare class TerraformTunnelProxyOperations implements TunnelProxyOperations {
|
4
|
+
private readonly configuration;
|
5
|
+
constructor(configuration: Configuration);
|
6
|
+
create(request: TunnelProxyCreatingRequest): Promise<TunnelProxyCreatingResult>;
|
7
|
+
destroy(): Promise<void>;
|
8
|
+
}
|
9
|
+
//# sourceMappingURL=TerraformTunnelProxyOperations.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TerraformTunnelProxyOperations.d.ts","sourceRoot":"","sources":["TerraformTunnelProxyOperations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,8BAA+B,YAAW,qBAAqB;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa;gBAAb,aAAa,EAAE,aAAa;IAEnD,MAAM,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAsB/E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAS/B"}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TerraformTunnelProxyOperations = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const terraform = tslib_1.__importStar(require("./terraform"));
|
6
|
+
class TerraformTunnelProxyOperations {
|
7
|
+
constructor(configuration) {
|
8
|
+
this.configuration = configuration;
|
9
|
+
}
|
10
|
+
async create(request) {
|
11
|
+
let storedOptions = await this.configuration.storedOptionsRepository.load();
|
12
|
+
if (storedOptions) {
|
13
|
+
throw new Error("Tunnel proxy already exists!");
|
14
|
+
}
|
15
|
+
const bucket = await this.configuration.cloudStorage.getBucket(request.proxyRegion);
|
16
|
+
storedOptions = {
|
17
|
+
request,
|
18
|
+
bucket: bucket.name,
|
19
|
+
};
|
20
|
+
const endpointAddress = await terraform.apply(storedOptions.request, storedOptions.bucket, this.configuration.aliyun.credentials);
|
21
|
+
await this.configuration.storedOptionsRepository.save(storedOptions);
|
22
|
+
return {
|
23
|
+
address: endpointAddress,
|
24
|
+
bucket,
|
25
|
+
};
|
26
|
+
}
|
27
|
+
async destroy() {
|
28
|
+
const storedOptions = await this.configuration.storedOptionsRepository.load();
|
29
|
+
if (!storedOptions) {
|
30
|
+
throw new Error("Tunnel proxy does not exists!");
|
31
|
+
}
|
32
|
+
await terraform.destroy(storedOptions.request, storedOptions.bucket, this.configuration.aliyun.credentials);
|
33
|
+
await this.configuration.cloudStorage.destroy(storedOptions.request.proxyRegion, storedOptions.bucket);
|
34
|
+
await this.configuration.storedOptionsRepository.delete();
|
35
|
+
}
|
36
|
+
}
|
37
|
+
exports.TerraformTunnelProxyOperations = TerraformTunnelProxyOperations;
|
38
|
+
//# sourceMappingURL=TerraformTunnelProxyOperations.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TerraformTunnelProxyOperations.js","sourceRoot":"","sources":["TerraformTunnelProxyOperations.ts"],"names":[],"mappings":";;;;AAKA,+DAAyC;AAGzC,MAAa,8BAA8B;IACzC,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,OAAmC;QAC9C,IAAI,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC;QAC5E,IAAI,aAAa,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpF,aAAa,GAAG;YACd,OAAO;YACP,MAAM,EAAE,MAAM,CAAC,IAAI;SACpB,CAAC;QACF,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,KAAK,CAC3C,aAAa,CAAC,OAAO,EACrB,aAAa,CAAC,MAAM,EACpB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CACtC,CAAC;QACF,MAAM,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACrE,OAAO;YACL,OAAO,EAAE,eAAe;YACxB,MAAM;SACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC;QAC9E,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QACD,MAAM,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC5G,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QACvG,MAAM,IAAI,CAAC,aAAa,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC;IAC5D,CAAC;CACF;AAlCD,wEAkCC"}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import {
|
2
|
+
TunnelProxyCreatingRequest,
|
3
|
+
TunnelProxyCreatingResult,
|
4
|
+
TunnelProxyOperations,
|
5
|
+
} from "../domain/TunnelProxyOperations";
|
6
|
+
import * as terraform from "./terraform";
|
7
|
+
import { Configuration } from "./Configuration";
|
8
|
+
|
9
|
+
export class TerraformTunnelProxyOperations implements TunnelProxyOperations {
|
10
|
+
constructor(private readonly configuration: Configuration) {}
|
11
|
+
|
12
|
+
async create(request: TunnelProxyCreatingRequest): Promise<TunnelProxyCreatingResult> {
|
13
|
+
let storedOptions = await this.configuration.storedOptionsRepository.load();
|
14
|
+
if (storedOptions) {
|
15
|
+
throw new Error("Tunnel proxy already exists!");
|
16
|
+
}
|
17
|
+
const bucket = await this.configuration.cloudStorage.getBucket(request.proxyRegion);
|
18
|
+
storedOptions = {
|
19
|
+
request,
|
20
|
+
bucket: bucket.name,
|
21
|
+
};
|
22
|
+
const endpointAddress = await terraform.apply(
|
23
|
+
storedOptions.request,
|
24
|
+
storedOptions.bucket,
|
25
|
+
this.configuration.aliyun.credentials
|
26
|
+
);
|
27
|
+
await this.configuration.storedOptionsRepository.save(storedOptions);
|
28
|
+
return {
|
29
|
+
address: endpointAddress,
|
30
|
+
bucket,
|
31
|
+
};
|
32
|
+
}
|
33
|
+
|
34
|
+
async destroy(): Promise<void> {
|
35
|
+
const storedOptions = await this.configuration.storedOptionsRepository.load();
|
36
|
+
if (!storedOptions) {
|
37
|
+
throw new Error("Tunnel proxy does not exists!");
|
38
|
+
}
|
39
|
+
await terraform.destroy(storedOptions.request, storedOptions.bucket, this.configuration.aliyun.credentials);
|
40
|
+
await this.configuration.cloudStorage.destroy(storedOptions.request.proxyRegion, storedOptions.bucket);
|
41
|
+
await this.configuration.storedOptionsRepository.delete();
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export declare type AliyunCredentials = {
|
2
|
+
accessKeyId: string;
|
3
|
+
accessKeySecret: string;
|
4
|
+
};
|
5
|
+
export declare function loadCredentials(): Promise<AliyunCredentials>;
|
6
|
+
export declare function asEnvironmentVariables(credentials: AliyunCredentials): Record<string, string>;
|
7
|
+
//# sourceMappingURL=aliyunCredentials.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"aliyunCredentials.d.ts","sourceRoot":"","sources":["aliyunCredentials.ts"],"names":[],"mappings":"AAKA,oBAAY,iBAAiB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,wBAAgB,eAAe,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAe5D;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK7F"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.asEnvironmentVariables = exports.loadCredentials = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const credentials_1 = tslib_1.__importDefault(require("@alicloud/credentials"));
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
7
|
+
const os = tslib_1.__importStar(require("os"));
|
8
|
+
const langUtils_1 = require("./langUtils");
|
9
|
+
function loadCredentials() {
|
10
|
+
return langUtils_1.executeWithEnvironment(async () => {
|
11
|
+
const credential = new credentials_1.default();
|
12
|
+
if (!credential.credential) {
|
13
|
+
throw new Error("Failed to load aliyun credentials!");
|
14
|
+
}
|
15
|
+
return {
|
16
|
+
accessKeyId: await credential.getAccessKeyId(),
|
17
|
+
accessKeySecret: await credential.getAccessKeySecret(),
|
18
|
+
};
|
19
|
+
}, "ALIBABA_CLOUD_CREDENTIALS_FILE", path_1.default.join(os.homedir(), ".alibabacloud", "credentials"));
|
20
|
+
}
|
21
|
+
exports.loadCredentials = loadCredentials;
|
22
|
+
function asEnvironmentVariables(credentials) {
|
23
|
+
return {
|
24
|
+
ALICLOUD_ACCESS_KEY: credentials.accessKeyId,
|
25
|
+
ALICLOUD_SECRET_KEY: credentials.accessKeySecret,
|
26
|
+
};
|
27
|
+
}
|
28
|
+
exports.asEnvironmentVariables = asEnvironmentVariables;
|
29
|
+
//# sourceMappingURL=aliyunCredentials.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"aliyunCredentials.js","sourceRoot":"","sources":["aliyunCredentials.ts"],"names":[],"mappings":";;;;AAAA,gFAA+C;AAC/C,wDAAwB;AACxB,+CAAyB;AACzB,2CAAqD;AAIrD,SAAgB,eAAe;IAC7B,OAAO,kCAAsB,CAC3B,KAAK,IAAI,EAAE;QACT,MAAM,UAAU,GAAG,IAAI,qBAAU,EAAE,CAAC;QACpC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QACD,OAAO;YACL,WAAW,EAAE,MAAM,UAAU,CAAC,cAAc,EAAE;YAC9C,eAAe,EAAE,MAAM,UAAU,CAAC,kBAAkB,EAAE;SACvD,CAAC;IACJ,CAAC,EACD,gCAAgC,EAChC,cAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,aAAa,CAAC,CACxD,CAAC;AACJ,CAAC;AAfD,0CAeC;AAED,SAAgB,sBAAsB,CAAC,WAA8B;IACnE,OAAO;QACL,mBAAmB,EAAE,WAAW,CAAC,WAAW;QAC5C,mBAAmB,EAAE,WAAW,CAAC,eAAe;KACjD,CAAC;AACJ,CAAC;AALD,wDAKC"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import Credential from "@alicloud/credentials";
|
2
|
+
import path from "path";
|
3
|
+
import * as os from "os";
|
4
|
+
import { executeWithEnvironment } from "./langUtils";
|
5
|
+
|
6
|
+
export type AliyunCredentials = { accessKeyId: string; accessKeySecret: string };
|
7
|
+
|
8
|
+
export function loadCredentials(): Promise<AliyunCredentials> {
|
9
|
+
return executeWithEnvironment(
|
10
|
+
async () => {
|
11
|
+
const credential = new Credential();
|
12
|
+
if (!credential.credential) {
|
13
|
+
throw new Error("Failed to load aliyun credentials!");
|
14
|
+
}
|
15
|
+
return {
|
16
|
+
accessKeyId: await credential.getAccessKeyId(),
|
17
|
+
accessKeySecret: await credential.getAccessKeySecret(),
|
18
|
+
};
|
19
|
+
},
|
20
|
+
"ALIBABA_CLOUD_CREDENTIALS_FILE",
|
21
|
+
path.join(os.homedir(), ".alibabacloud", "credentials")
|
22
|
+
);
|
23
|
+
}
|
24
|
+
|
25
|
+
export function asEnvironmentVariables(credentials: AliyunCredentials): Record<string, string> {
|
26
|
+
return {
|
27
|
+
ALICLOUD_ACCESS_KEY: credentials.accessKeyId,
|
28
|
+
ALICLOUD_SECRET_KEY: credentials.accessKeySecret,
|
29
|
+
};
|
30
|
+
}
|