@awsless/awsless 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.cjs +200 -157
- package/dist/bin.js +200 -157
- package/dist/index.d.ts +179 -0
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -63,15 +63,15 @@ var flushDebug = () => {
|
|
|
63
63
|
|
|
64
64
|
// src/util/param.ts
|
|
65
65
|
import { DeleteParameterCommand, GetParameterCommand, GetParametersByPathCommand, ParameterType, PutParameterCommand, SSMClient } from "@aws-sdk/client-ssm";
|
|
66
|
-
var configParameterPrefix = (
|
|
67
|
-
return `/${
|
|
66
|
+
var configParameterPrefix = (config) => {
|
|
67
|
+
return `/${config.stage}/awsless/${config.name}`;
|
|
68
68
|
};
|
|
69
69
|
var Params = class {
|
|
70
|
-
constructor(
|
|
71
|
-
this.config =
|
|
70
|
+
constructor(config) {
|
|
71
|
+
this.config = config;
|
|
72
72
|
this.client = new SSMClient({
|
|
73
|
-
credentials:
|
|
74
|
-
region:
|
|
73
|
+
credentials: config.credentials,
|
|
74
|
+
region: config.region
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
client;
|
|
@@ -146,13 +146,13 @@ var Params = class {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
// src/stack.ts
|
|
149
|
-
var toStack = ({ config
|
|
150
|
-
const stackName = `${
|
|
149
|
+
var toStack = ({ config, assets, app, stackConfig, plugins }) => {
|
|
150
|
+
const stackName = `${config.name}-${stackConfig.name}`;
|
|
151
151
|
const stack = new Stack(app, stackConfig.name, {
|
|
152
152
|
stackName,
|
|
153
153
|
tags: {
|
|
154
|
-
APP:
|
|
155
|
-
STAGE:
|
|
154
|
+
APP: config.name,
|
|
155
|
+
STAGE: config.stage,
|
|
156
156
|
STACK: stackConfig.name
|
|
157
157
|
}
|
|
158
158
|
});
|
|
@@ -163,7 +163,7 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
163
163
|
};
|
|
164
164
|
debug("Run plugin onStack listeners");
|
|
165
165
|
const functions = plugins.map((plugin) => plugin.onStack?.({
|
|
166
|
-
config
|
|
166
|
+
config,
|
|
167
167
|
assets,
|
|
168
168
|
app,
|
|
169
169
|
stack,
|
|
@@ -182,12 +182,12 @@ var toStack = ({ config: config2, assets, app, stackConfig, plugins }) => {
|
|
|
182
182
|
],
|
|
183
183
|
resources: [
|
|
184
184
|
Arn.format({
|
|
185
|
-
region:
|
|
186
|
-
account:
|
|
185
|
+
region: config.region,
|
|
186
|
+
account: config.account,
|
|
187
187
|
partition: "aws",
|
|
188
188
|
service: "ssm",
|
|
189
189
|
resource: "parameter",
|
|
190
|
-
resourceName: configParameterPrefix(
|
|
190
|
+
resourceName: configParameterPrefix(config)
|
|
191
191
|
})
|
|
192
192
|
// Fn.sub('arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter' + configParameterPrefix(config)),
|
|
193
193
|
]
|
|
@@ -377,17 +377,17 @@ var zipFiles = (files) => {
|
|
|
377
377
|
}
|
|
378
378
|
});
|
|
379
379
|
};
|
|
380
|
-
var writeBuildHash = async (
|
|
381
|
-
const funcPath = join2(assetDir, "function",
|
|
380
|
+
var writeBuildHash = async (config, stack, id, hash) => {
|
|
381
|
+
const funcPath = join2(assetDir, "function", config.name, stack.artifactId, id);
|
|
382
382
|
const versionFile = join2(funcPath, "HASH");
|
|
383
383
|
await writeFile(versionFile, hash);
|
|
384
384
|
};
|
|
385
|
-
var writeBuildFiles = async (
|
|
385
|
+
var writeBuildFiles = async (config, stack, id, files) => {
|
|
386
386
|
const bundle = await zipFiles(files);
|
|
387
|
-
const funcPath = join2(assetDir, "function",
|
|
387
|
+
const funcPath = join2(assetDir, "function", config.name, stack.artifactId, id);
|
|
388
388
|
const filesPath = join2(funcPath, "files");
|
|
389
389
|
const bundleFile = join2(funcPath, "bundle.zip");
|
|
390
|
-
debug("Bundle size of", style.info(join2(
|
|
390
|
+
debug("Bundle size of", style.info(join2(config.name, stack.artifactId, id)), "is", style.attr(filesize(bundle.byteLength)));
|
|
391
391
|
await mkdir(filesPath, { recursive: true });
|
|
392
392
|
await writeFile(bundleFile, bundle);
|
|
393
393
|
await Promise.all(files.map(async (file) => {
|
|
@@ -413,20 +413,20 @@ import { GetObjectCommand, ObjectCannedACL, PutObjectCommand, S3Client, StorageC
|
|
|
413
413
|
// src/stack/bootstrap.ts
|
|
414
414
|
import { CfnOutput, RemovalPolicy, Stack as Stack2 } from "aws-cdk-lib";
|
|
415
415
|
import { Bucket, BucketAccessControl } from "aws-cdk-lib/aws-s3";
|
|
416
|
-
var assetBucketName = (
|
|
417
|
-
return `awsless-bootstrap-${
|
|
416
|
+
var assetBucketName = (config) => {
|
|
417
|
+
return `awsless-bootstrap-${config.account}-${config.region}`;
|
|
418
418
|
};
|
|
419
|
-
var assetBucketUrl = (
|
|
420
|
-
const bucket = assetBucketName(
|
|
421
|
-
return `https://s3-${
|
|
419
|
+
var assetBucketUrl = (config, stackName) => {
|
|
420
|
+
const bucket = assetBucketName(config);
|
|
421
|
+
return `https://s3-${config.region}.amazonaws.com/${bucket}/${stackName}/cloudformation.json`;
|
|
422
422
|
};
|
|
423
423
|
var version = "2";
|
|
424
|
-
var bootstrapStack = (
|
|
424
|
+
var bootstrapStack = (config, app) => {
|
|
425
425
|
const stack = new Stack2(app, "bootstrap", {
|
|
426
426
|
stackName: `awsless-bootstrap`
|
|
427
427
|
});
|
|
428
428
|
new Bucket(stack, "assets", {
|
|
429
|
-
bucketName: assetBucketName(
|
|
429
|
+
bucketName: assetBucketName(config),
|
|
430
430
|
versioned: true,
|
|
431
431
|
accessControl: BucketAccessControl.PRIVATE,
|
|
432
432
|
removalPolicy: RemovalPolicy.DESTROY
|
|
@@ -444,17 +444,17 @@ var shouldDeployBootstrap = async (client, name) => {
|
|
|
444
444
|
};
|
|
445
445
|
|
|
446
446
|
// src/plugins/function/util/publish.ts
|
|
447
|
-
var publishFunctionAsset = async (
|
|
448
|
-
const bucket = assetBucketName(
|
|
449
|
-
const key = `${
|
|
450
|
-
const funcPath = join3(assetDir, "function",
|
|
447
|
+
var publishFunctionAsset = async (config, stack, id) => {
|
|
448
|
+
const bucket = assetBucketName(config);
|
|
449
|
+
const key = `${config.name}/${stack.artifactId}/function/${id}.zip`;
|
|
450
|
+
const funcPath = join3(assetDir, "function", config.name, stack.artifactId, id);
|
|
451
451
|
const bundleFile = join3(funcPath, "bundle.zip");
|
|
452
452
|
const hashFile = join3(funcPath, "HASH");
|
|
453
453
|
const hash = await readFile(hashFile, "utf8");
|
|
454
454
|
const file = await readFile(bundleFile);
|
|
455
455
|
const client = new S3Client({
|
|
456
|
-
credentials:
|
|
457
|
-
region:
|
|
456
|
+
credentials: config.credentials,
|
|
457
|
+
region: config.region
|
|
458
458
|
});
|
|
459
459
|
let getResult;
|
|
460
460
|
try {
|
|
@@ -589,8 +589,8 @@ var functionPlugin = definePlugin({
|
|
|
589
589
|
});
|
|
590
590
|
}
|
|
591
591
|
});
|
|
592
|
-
var toFunction = ({ config
|
|
593
|
-
const props = typeof fileOrProps === "string" ? { ...
|
|
592
|
+
var toFunction = ({ config, stack, assets }, id, fileOrProps) => {
|
|
593
|
+
const props = typeof fileOrProps === "string" ? { ...config.defaults?.function, file: fileOrProps } : { ...config.defaults?.function, ...fileOrProps };
|
|
594
594
|
const lambda = new Function(stack, toId("function", id), {
|
|
595
595
|
functionName: toName(stack, id),
|
|
596
596
|
handler: "index.default",
|
|
@@ -598,8 +598,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
598
598
|
...props,
|
|
599
599
|
memorySize: props.memorySize.toMebibytes()
|
|
600
600
|
});
|
|
601
|
-
lambda.addEnvironment("APP",
|
|
602
|
-
lambda.addEnvironment("STAGE",
|
|
601
|
+
lambda.addEnvironment("APP", config.name, { removeInEdge: true });
|
|
602
|
+
lambda.addEnvironment("STAGE", config.stage, { removeInEdge: true });
|
|
603
603
|
lambda.addEnvironment("STACK", stack.artifactId, { removeInEdge: true });
|
|
604
604
|
if (lambda.runtime.toString().startsWith("nodejs")) {
|
|
605
605
|
lambda.addEnvironment("AWS_NODEJS_CONNECTION_REUSE_ENABLED", "1", {
|
|
@@ -612,8 +612,8 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
612
612
|
resourceName: id,
|
|
613
613
|
async build() {
|
|
614
614
|
const result = await rollupBuild(props.file);
|
|
615
|
-
const bundle = await writeBuildFiles(
|
|
616
|
-
await writeBuildHash(
|
|
615
|
+
const bundle = await writeBuildFiles(config, stack, id, result.files);
|
|
616
|
+
await writeBuildHash(config, stack, id, result.hash);
|
|
617
617
|
const func = lambda.node.defaultChild;
|
|
618
618
|
func.handler = result.handler;
|
|
619
619
|
return {
|
|
@@ -621,11 +621,11 @@ var toFunction = ({ config: config2, stack, assets }, id, fileOrProps) => {
|
|
|
621
621
|
};
|
|
622
622
|
},
|
|
623
623
|
async publish() {
|
|
624
|
-
const version2 = await publishFunctionAsset(
|
|
624
|
+
const version2 = await publishFunctionAsset(config, stack, id);
|
|
625
625
|
const func = lambda.node.defaultChild;
|
|
626
626
|
func.code = {
|
|
627
|
-
s3Bucket: assetBucketName(
|
|
628
|
-
s3Key: `${
|
|
627
|
+
s3Bucket: assetBucketName(config),
|
|
628
|
+
s3Key: `${config.name}/${stack.artifactId}/function/${id}.zip`,
|
|
629
629
|
s3ObjectVersion: version2
|
|
630
630
|
};
|
|
631
631
|
}
|
|
@@ -694,9 +694,9 @@ var queuePlugin = definePlugin({
|
|
|
694
694
|
}).array()
|
|
695
695
|
}),
|
|
696
696
|
onStack(ctx) {
|
|
697
|
-
const { stack, config
|
|
697
|
+
const { stack, config, stackConfig, bind } = ctx;
|
|
698
698
|
return Object.entries(stackConfig.queues || {}).map(([id, functionOrProps]) => {
|
|
699
|
-
const props = typeof functionOrProps === "string" ? { ...
|
|
699
|
+
const props = typeof functionOrProps === "string" ? { ...config.defaults.queue, consumer: functionOrProps } : { ...config.defaults.queue, ...functionOrProps };
|
|
700
700
|
const queue2 = new Queue(stack, toId("queue", id), {
|
|
701
701
|
queueName: toName(stack, id),
|
|
702
702
|
...props,
|
|
@@ -860,20 +860,20 @@ var topicPlugin = definePlugin({
|
|
|
860
860
|
topics: z18.record(ResourceIdSchema, FunctionSchema).optional()
|
|
861
861
|
}).array()
|
|
862
862
|
}),
|
|
863
|
-
onBootstrap({ config
|
|
864
|
-
const allTopicNames =
|
|
863
|
+
onBootstrap({ config, stack }) {
|
|
864
|
+
const allTopicNames = config.stacks.map((stack2) => {
|
|
865
865
|
return Object.keys(stack2.topics || {});
|
|
866
866
|
}).flat();
|
|
867
867
|
const uniqueTopicNames = [...new Set(allTopicNames)];
|
|
868
868
|
uniqueTopicNames.forEach((id) => {
|
|
869
869
|
new Topic(stack, toId("topic", id), {
|
|
870
|
-
topicName: `${
|
|
870
|
+
topicName: `${config.name}-${id}`,
|
|
871
871
|
displayName: id
|
|
872
872
|
});
|
|
873
873
|
});
|
|
874
874
|
},
|
|
875
875
|
onStack(ctx) {
|
|
876
|
-
const { config
|
|
876
|
+
const { config, stack, stackConfig, bind } = ctx;
|
|
877
877
|
return Object.entries(stackConfig.topics || {}).map(([id, props]) => {
|
|
878
878
|
const lambda = toFunction(ctx, id, props);
|
|
879
879
|
const topic = Topic.fromTopicArn(
|
|
@@ -882,7 +882,7 @@ var topicPlugin = definePlugin({
|
|
|
882
882
|
Arn2.format({
|
|
883
883
|
arnFormat: ArnFormat.NO_RESOURCE_NAME,
|
|
884
884
|
service: "sns",
|
|
885
|
-
resource: `${
|
|
885
|
+
resource: `${config.name}-${id}`
|
|
886
886
|
}, stack)
|
|
887
887
|
);
|
|
888
888
|
lambda.addEventSource(new SnsEventSource(topic));
|
|
@@ -974,19 +974,19 @@ var graphqlPlugin = definePlugin({
|
|
|
974
974
|
})).optional()
|
|
975
975
|
}).array()
|
|
976
976
|
}),
|
|
977
|
-
onBootstrap({ config
|
|
977
|
+
onBootstrap({ config, stack, assets }) {
|
|
978
978
|
const list3 = /* @__PURE__ */ new Set();
|
|
979
|
-
Object.values(
|
|
979
|
+
Object.values(config.stacks).forEach((stackConfig) => {
|
|
980
980
|
Object.keys(stackConfig.graphql || {}).forEach((id) => {
|
|
981
981
|
list3.add(id);
|
|
982
982
|
});
|
|
983
983
|
});
|
|
984
984
|
list3.forEach((id) => {
|
|
985
|
-
const file = join4(assetDir, "graphql",
|
|
986
|
-
const authorization =
|
|
985
|
+
const file = join4(assetDir, "graphql", config.name, id, "schema.graphql");
|
|
986
|
+
const authorization = config.defaults.graphql?.[id]?.authorization;
|
|
987
987
|
const authProps = {};
|
|
988
988
|
if (authorization) {
|
|
989
|
-
const authorizer = toFunction({ config
|
|
989
|
+
const authorizer = toFunction({ config, assets, stack }, `${id}-authorizer`, authorization.authorizer);
|
|
990
990
|
authProps.additionalAuthenticationProviders = [{
|
|
991
991
|
authenticationType: AuthorizationType.LAMBDA,
|
|
992
992
|
lambdaAuthorizerConfig: {
|
|
@@ -1010,7 +1010,7 @@ var graphqlPlugin = definePlugin({
|
|
|
1010
1010
|
resourceName: id,
|
|
1011
1011
|
async build() {
|
|
1012
1012
|
const schemas = [];
|
|
1013
|
-
await Promise.all(Object.values(
|
|
1013
|
+
await Promise.all(Object.values(config.stacks).map(async (stackConfig) => {
|
|
1014
1014
|
const schemaFiles = toArray(stackConfig.graphql?.[id].schema || []);
|
|
1015
1015
|
await Promise.all(schemaFiles.map(async (schemaFile) => {
|
|
1016
1016
|
const schema3 = await readFile2(schemaFile, "utf8");
|
|
@@ -1029,9 +1029,9 @@ var graphqlPlugin = definePlugin({
|
|
|
1029
1029
|
});
|
|
1030
1030
|
},
|
|
1031
1031
|
onStack(ctx) {
|
|
1032
|
-
const { config
|
|
1032
|
+
const { config, stack, stackConfig } = ctx;
|
|
1033
1033
|
return Object.entries(stackConfig.graphql || {}).map(([id, props]) => {
|
|
1034
|
-
const defaults =
|
|
1034
|
+
const defaults = config.defaults.graphql?.[id] || {};
|
|
1035
1035
|
return Object.entries(props.resolvers || {}).map(([typeAndField, functionProps]) => {
|
|
1036
1036
|
const api = GraphqlApi.fromGraphqlApiAttributes(stack, toId("graphql", id), {
|
|
1037
1037
|
graphqlApiId: Fn.importValue(toId("graphql", id))
|
|
@@ -1054,6 +1054,48 @@ var graphqlPlugin = definePlugin({
|
|
|
1054
1054
|
}
|
|
1055
1055
|
});
|
|
1056
1056
|
|
|
1057
|
+
// src/plugins/pubsub.ts
|
|
1058
|
+
import { z as z22 } from "zod";
|
|
1059
|
+
import { CfnTopicRule } from "aws-cdk-lib/aws-iot";
|
|
1060
|
+
import { PolicyStatement as PolicyStatement3 } from "aws-cdk-lib/aws-iam";
|
|
1061
|
+
var pubsubPlugin = definePlugin({
|
|
1062
|
+
name: "pubsub",
|
|
1063
|
+
schema: z22.object({
|
|
1064
|
+
stacks: z22.object({
|
|
1065
|
+
pubsub: z22.record(ResourceIdSchema, z22.object({
|
|
1066
|
+
sql: z22.string(),
|
|
1067
|
+
sqlVersion: z22.enum(["2015-10-08", "2016-03-23", "beta"]).default("2016-03-23"),
|
|
1068
|
+
consumer: FunctionSchema
|
|
1069
|
+
})).optional()
|
|
1070
|
+
}).array()
|
|
1071
|
+
}),
|
|
1072
|
+
onStack(ctx) {
|
|
1073
|
+
const { stack, stackConfig, bind } = ctx;
|
|
1074
|
+
bind((lambda) => {
|
|
1075
|
+
lambda.addToRolePolicy(new PolicyStatement3({
|
|
1076
|
+
actions: ["iot:publish"],
|
|
1077
|
+
resources: ["*"]
|
|
1078
|
+
}));
|
|
1079
|
+
});
|
|
1080
|
+
return Object.entries(stackConfig.pubsub || {}).map(([id, props]) => {
|
|
1081
|
+
const lambda = toFunction(ctx, id, props.consumer);
|
|
1082
|
+
new CfnTopicRule(stack, toId("pubsub", id), {
|
|
1083
|
+
ruleName: toName(stack, id),
|
|
1084
|
+
topicRulePayload: {
|
|
1085
|
+
sql: props.sql,
|
|
1086
|
+
awsIotSqlVersion: props.sqlVersion,
|
|
1087
|
+
actions: [{
|
|
1088
|
+
lambda: {
|
|
1089
|
+
functionArn: lambda.functionArn
|
|
1090
|
+
}
|
|
1091
|
+
}]
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
return lambda;
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1057
1099
|
// src/plugins/index.ts
|
|
1058
1100
|
var defaultPlugins = [
|
|
1059
1101
|
functionPlugin,
|
|
@@ -1063,21 +1105,22 @@ var defaultPlugins = [
|
|
|
1063
1105
|
storePlugin,
|
|
1064
1106
|
topicPlugin,
|
|
1065
1107
|
searchPlugin,
|
|
1066
|
-
graphqlPlugin
|
|
1108
|
+
graphqlPlugin,
|
|
1109
|
+
pubsubPlugin
|
|
1067
1110
|
];
|
|
1068
1111
|
|
|
1069
1112
|
// src/stack/app-bootstrap.ts
|
|
1070
|
-
var appBootstrapStack = ({ config
|
|
1113
|
+
var appBootstrapStack = ({ config, app, assets }) => {
|
|
1071
1114
|
const stack = new Stack3(app, "bootstrap", {
|
|
1072
|
-
stackName: `${
|
|
1115
|
+
stackName: `${config.name}-bootstrap`
|
|
1073
1116
|
});
|
|
1074
1117
|
const plugins = [
|
|
1075
1118
|
...defaultPlugins,
|
|
1076
|
-
...
|
|
1119
|
+
...config.plugins || []
|
|
1077
1120
|
];
|
|
1078
1121
|
debug("Run plugin onBootstrap listeners");
|
|
1079
1122
|
const functions = plugins.map((plugin) => plugin.onBootstrap?.({
|
|
1080
|
-
config
|
|
1123
|
+
config,
|
|
1081
1124
|
app,
|
|
1082
1125
|
stack,
|
|
1083
1126
|
assets
|
|
@@ -1101,9 +1144,9 @@ var flattenDependencyTree = (stacks) => {
|
|
|
1101
1144
|
return list3;
|
|
1102
1145
|
};
|
|
1103
1146
|
var createDependencyTree = (stacks, startingLevel) => {
|
|
1104
|
-
const list3 = stacks.map(({ stack, config
|
|
1147
|
+
const list3 = stacks.map(({ stack, config }) => ({
|
|
1105
1148
|
stack,
|
|
1106
|
-
depends:
|
|
1149
|
+
depends: config?.depends?.map((dep) => dep.name) || []
|
|
1107
1150
|
}));
|
|
1108
1151
|
const findChildren = (list4, parents, level) => {
|
|
1109
1152
|
const children = [];
|
|
@@ -1175,11 +1218,11 @@ var Assets = class {
|
|
|
1175
1218
|
};
|
|
1176
1219
|
|
|
1177
1220
|
// src/app.ts
|
|
1178
|
-
var makeApp = (
|
|
1221
|
+
var makeApp = (config) => {
|
|
1179
1222
|
return new App4({
|
|
1180
1223
|
outdir: assemblyDir,
|
|
1181
1224
|
defaultStackSynthesizer: new DefaultStackSynthesizer({
|
|
1182
|
-
fileAssetsBucketName: assetBucketName(
|
|
1225
|
+
fileAssetsBucketName: assetBucketName(config),
|
|
1183
1226
|
fileAssetPublishingRoleArn: "",
|
|
1184
1227
|
generateBootstrapVersionRule: false
|
|
1185
1228
|
})
|
|
@@ -1196,26 +1239,26 @@ var getAllDepends = (filters) => {
|
|
|
1196
1239
|
walk(filters);
|
|
1197
1240
|
return list3;
|
|
1198
1241
|
};
|
|
1199
|
-
var toApp = async (
|
|
1242
|
+
var toApp = async (config, filters) => {
|
|
1200
1243
|
const assets = new Assets();
|
|
1201
|
-
const app = makeApp(
|
|
1244
|
+
const app = makeApp(config);
|
|
1202
1245
|
const stacks = [];
|
|
1203
1246
|
const plugins = [
|
|
1204
1247
|
...defaultPlugins,
|
|
1205
|
-
...
|
|
1248
|
+
...config.plugins || []
|
|
1206
1249
|
];
|
|
1207
1250
|
debug("Plugins detected:", plugins.map((plugin) => style.info(plugin.name)).join(", "));
|
|
1208
1251
|
debug("Run plugin onApp listeners");
|
|
1209
|
-
plugins.forEach((plugin) => plugin.onApp?.({ config
|
|
1210
|
-
const bootstrap2 = appBootstrapStack({ config
|
|
1252
|
+
plugins.forEach((plugin) => plugin.onApp?.({ config, app, assets }));
|
|
1253
|
+
const bootstrap2 = appBootstrapStack({ config, app, assets });
|
|
1211
1254
|
debug("Stack filters:", filters.map((filter) => style.info(filter)).join(", "));
|
|
1212
|
-
const filterdStacks = filters.length === 0 ?
|
|
1255
|
+
const filterdStacks = filters.length === 0 ? config.stacks : getAllDepends(
|
|
1213
1256
|
// config.stacks,
|
|
1214
|
-
|
|
1257
|
+
config.stacks.filter((stack) => filters.includes(stack.name))
|
|
1215
1258
|
);
|
|
1216
1259
|
for (const stackConfig of filterdStacks) {
|
|
1217
1260
|
const { stack, bindings } = toStack({
|
|
1218
|
-
config
|
|
1261
|
+
config,
|
|
1219
1262
|
stackConfig,
|
|
1220
1263
|
assets,
|
|
1221
1264
|
plugins,
|
|
@@ -1320,17 +1363,17 @@ var getCredentials = (profile) => {
|
|
|
1320
1363
|
};
|
|
1321
1364
|
|
|
1322
1365
|
// src/schema/app.ts
|
|
1323
|
-
import { z as
|
|
1366
|
+
import { z as z26 } from "zod";
|
|
1324
1367
|
|
|
1325
1368
|
// src/schema/stack.ts
|
|
1326
|
-
import { z as
|
|
1327
|
-
var StackSchema =
|
|
1369
|
+
import { z as z23 } from "zod";
|
|
1370
|
+
var StackSchema = z23.object({
|
|
1328
1371
|
name: ResourceIdSchema,
|
|
1329
|
-
depends:
|
|
1372
|
+
depends: z23.array(z23.lazy(() => StackSchema)).optional()
|
|
1330
1373
|
});
|
|
1331
1374
|
|
|
1332
1375
|
// src/schema/region.ts
|
|
1333
|
-
import { z as
|
|
1376
|
+
import { z as z24 } from "zod";
|
|
1334
1377
|
var US = ["us-east-2", "us-east-1", "us-west-1", "us-west-2"];
|
|
1335
1378
|
var AF = ["af-south-1"];
|
|
1336
1379
|
var AP = ["ap-east-1", "ap-south-2", "ap-southeast-3", "ap-southeast-4", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1"];
|
|
@@ -1347,29 +1390,29 @@ var regions = [
|
|
|
1347
1390
|
...ME,
|
|
1348
1391
|
...SA
|
|
1349
1392
|
];
|
|
1350
|
-
var RegionSchema =
|
|
1393
|
+
var RegionSchema = z24.enum(regions);
|
|
1351
1394
|
|
|
1352
1395
|
// src/schema/plugin.ts
|
|
1353
|
-
import { z as
|
|
1354
|
-
var PluginSchema =
|
|
1355
|
-
name:
|
|
1356
|
-
schema:
|
|
1396
|
+
import { z as z25 } from "zod";
|
|
1397
|
+
var PluginSchema = z25.object({
|
|
1398
|
+
name: z25.string(),
|
|
1399
|
+
schema: z25.custom().optional(),
|
|
1357
1400
|
// depends: z.array(z.lazy(() => PluginSchema)).optional(),
|
|
1358
|
-
onBootstrap:
|
|
1359
|
-
onStack:
|
|
1360
|
-
onApp:
|
|
1401
|
+
onBootstrap: z25.function().returns(z25.any()).optional(),
|
|
1402
|
+
onStack: z25.function().returns(z25.any()).optional(),
|
|
1403
|
+
onApp: z25.function().returns(z25.void()).optional()
|
|
1361
1404
|
// bind: z.function().optional(),
|
|
1362
1405
|
});
|
|
1363
1406
|
|
|
1364
1407
|
// src/schema/app.ts
|
|
1365
|
-
var AppSchema =
|
|
1408
|
+
var AppSchema = z26.object({
|
|
1366
1409
|
name: ResourceIdSchema,
|
|
1367
1410
|
region: RegionSchema,
|
|
1368
|
-
profile:
|
|
1369
|
-
stage:
|
|
1370
|
-
defaults:
|
|
1371
|
-
stacks:
|
|
1372
|
-
plugins:
|
|
1411
|
+
profile: z26.string(),
|
|
1412
|
+
stage: z26.string().regex(/[a-z]+/).default("prod"),
|
|
1413
|
+
defaults: z26.object({}).default({}),
|
|
1414
|
+
stacks: z26.array(StackSchema).min(1),
|
|
1415
|
+
plugins: z26.array(PluginSchema).optional()
|
|
1373
1416
|
});
|
|
1374
1417
|
|
|
1375
1418
|
// src/util/import.ts
|
|
@@ -1449,14 +1492,14 @@ var importConfig = async (options) => {
|
|
|
1449
1492
|
schema2 = schema2.and(plugin.schema);
|
|
1450
1493
|
}
|
|
1451
1494
|
}
|
|
1452
|
-
const
|
|
1453
|
-
debug("Load credentials", style.info(
|
|
1454
|
-
const credentials = getCredentials(
|
|
1495
|
+
const config = await schema2.parseAsync(appConfig);
|
|
1496
|
+
debug("Load credentials", style.info(config.profile));
|
|
1497
|
+
const credentials = getCredentials(config.profile);
|
|
1455
1498
|
debug("Load AWS account ID");
|
|
1456
|
-
const account = await getAccountId(credentials,
|
|
1499
|
+
const account = await getAccountId(credentials, config.region);
|
|
1457
1500
|
debug("Account ID:", style.info(account));
|
|
1458
1501
|
return {
|
|
1459
|
-
...
|
|
1502
|
+
...config,
|
|
1460
1503
|
account,
|
|
1461
1504
|
credentials
|
|
1462
1505
|
};
|
|
@@ -1478,14 +1521,14 @@ var list = (data) => {
|
|
|
1478
1521
|
};
|
|
1479
1522
|
|
|
1480
1523
|
// src/cli/ui/layout/header.ts
|
|
1481
|
-
var header = (
|
|
1524
|
+
var header = (config) => {
|
|
1482
1525
|
return [
|
|
1483
1526
|
br(),
|
|
1484
1527
|
list({
|
|
1485
|
-
App:
|
|
1486
|
-
Stage:
|
|
1487
|
-
Region:
|
|
1488
|
-
Profile:
|
|
1528
|
+
App: config.name,
|
|
1529
|
+
Stage: config.stage,
|
|
1530
|
+
Region: config.region,
|
|
1531
|
+
Profile: config.profile
|
|
1489
1532
|
}),
|
|
1490
1533
|
br()
|
|
1491
1534
|
];
|
|
@@ -1803,9 +1846,9 @@ var layout = async (cb) => {
|
|
|
1803
1846
|
term.out.write(logo());
|
|
1804
1847
|
try {
|
|
1805
1848
|
const options = program.optsWithGlobals();
|
|
1806
|
-
const
|
|
1807
|
-
term.out.write(header(
|
|
1808
|
-
await cb(
|
|
1849
|
+
const config = await importConfig(options);
|
|
1850
|
+
term.out.write(header(config));
|
|
1851
|
+
await cb(config, term.out.write.bind(term.out), term);
|
|
1809
1852
|
} catch (error) {
|
|
1810
1853
|
if (error instanceof Error) {
|
|
1811
1854
|
term.out.write(dialog("error", [error.message]));
|
|
@@ -1920,8 +1963,8 @@ var cleanUp = async () => {
|
|
|
1920
1963
|
// src/cli/command/build.ts
|
|
1921
1964
|
var build = (program2) => {
|
|
1922
1965
|
program2.command("build").argument("[stack...]", "Optionally filter stacks to build").description("Build your app").action(async (filters) => {
|
|
1923
|
-
await layout(async (
|
|
1924
|
-
const { app, assets } = await toApp(
|
|
1966
|
+
await layout(async (config, write) => {
|
|
1967
|
+
const { app, assets } = await toApp(config, filters);
|
|
1925
1968
|
await cleanUp();
|
|
1926
1969
|
await write(assetBuilder(assets));
|
|
1927
1970
|
app.synth();
|
|
@@ -1934,11 +1977,11 @@ import { CloudFormationClient, CreateStackCommand, DeleteStackCommand, DescribeS
|
|
|
1934
1977
|
import { S3Client as S3Client2, PutObjectCommand as PutObjectCommand2, ObjectCannedACL as ObjectCannedACL2, StorageClass as StorageClass2 } from "@aws-sdk/client-s3";
|
|
1935
1978
|
var StackClient = class {
|
|
1936
1979
|
// 30 seconds
|
|
1937
|
-
constructor(
|
|
1938
|
-
this.config =
|
|
1980
|
+
constructor(config) {
|
|
1981
|
+
this.config = config;
|
|
1939
1982
|
this.client = new CloudFormationClient({
|
|
1940
|
-
credentials:
|
|
1941
|
-
region:
|
|
1983
|
+
credentials: config.credentials,
|
|
1984
|
+
region: config.region
|
|
1942
1985
|
});
|
|
1943
1986
|
}
|
|
1944
1987
|
client;
|
|
@@ -2167,12 +2210,12 @@ var confirmPrompt = (label, options = {}) => {
|
|
|
2167
2210
|
};
|
|
2168
2211
|
|
|
2169
2212
|
// src/cli/ui/complex/bootstrap.ts
|
|
2170
|
-
var bootstrapDeployer = (
|
|
2213
|
+
var bootstrapDeployer = (config) => {
|
|
2171
2214
|
return async (term) => {
|
|
2172
2215
|
debug("Initializing bootstrap");
|
|
2173
|
-
const app = makeApp(
|
|
2174
|
-
const client = new StackClient(
|
|
2175
|
-
const bootstrap2 = bootstrapStack(
|
|
2216
|
+
const app = makeApp(config);
|
|
2217
|
+
const client = new StackClient(config);
|
|
2218
|
+
const bootstrap2 = bootstrapStack(config, app);
|
|
2176
2219
|
const shouldDeploy = await shouldDeployBootstrap(client, bootstrap2.stackName);
|
|
2177
2220
|
if (shouldDeploy) {
|
|
2178
2221
|
term.out.write(dialog("warning", [`Your app hasn't been bootstrapped yet`]));
|
|
@@ -2196,8 +2239,8 @@ var bootstrapDeployer = (config2) => {
|
|
|
2196
2239
|
// src/cli/command/bootstrap.ts
|
|
2197
2240
|
var bootstrap = (program2) => {
|
|
2198
2241
|
program2.command("bootstrap").description("Create the awsless bootstrap stack").action(async () => {
|
|
2199
|
-
await layout(async (
|
|
2200
|
-
await write(bootstrapDeployer(
|
|
2242
|
+
await layout(async (config, write) => {
|
|
2243
|
+
await write(bootstrapDeployer(config));
|
|
2201
2244
|
});
|
|
2202
2245
|
});
|
|
2203
2246
|
};
|
|
@@ -2241,14 +2284,14 @@ var stackTree = (nodes, statuses) => {
|
|
|
2241
2284
|
// src/cli/command/status.ts
|
|
2242
2285
|
var status = (program2) => {
|
|
2243
2286
|
program2.command("status").argument("[stacks...]", "Optionally filter stacks to lookup status").description("View the application status").action(async (filters) => {
|
|
2244
|
-
await layout(async (
|
|
2245
|
-
const { app, assets, dependencyTree } = await toApp(
|
|
2287
|
+
await layout(async (config, write) => {
|
|
2288
|
+
const { app, assets, dependencyTree } = await toApp(config, filters);
|
|
2246
2289
|
await cleanUp();
|
|
2247
2290
|
await write(assetBuilder(assets));
|
|
2248
2291
|
write(br());
|
|
2249
2292
|
const assembly = app.synth();
|
|
2250
2293
|
const doneLoading = write(loadingDialog("Loading stack information..."));
|
|
2251
|
-
const client = new StackClient(
|
|
2294
|
+
const client = new StackClient(config);
|
|
2252
2295
|
const statuses = [];
|
|
2253
2296
|
const stackStatuses = {};
|
|
2254
2297
|
assembly.stacks.forEach((stack) => {
|
|
@@ -2288,9 +2331,9 @@ var status = (program2) => {
|
|
|
2288
2331
|
// src/cli/command/deploy.ts
|
|
2289
2332
|
var deploy = (program2) => {
|
|
2290
2333
|
program2.command("deploy").argument("[stacks...]", "Optionally filter stacks to deploy").description("Deploy your app to AWS").action(async (filters) => {
|
|
2291
|
-
await layout(async (
|
|
2292
|
-
await write(bootstrapDeployer(
|
|
2293
|
-
const { app, stackNames, assets, dependencyTree } = await toApp(
|
|
2334
|
+
await layout(async (config, write) => {
|
|
2335
|
+
await write(bootstrapDeployer(config));
|
|
2336
|
+
const { app, stackNames, assets, dependencyTree } = await toApp(config, filters);
|
|
2294
2337
|
const formattedFilter = stackNames.map((i) => style.info(i)).join(style.placeholder(", "));
|
|
2295
2338
|
debug("Stacks to deploy", formattedFilter);
|
|
2296
2339
|
const deployAll = filters.length === 0;
|
|
@@ -2319,7 +2362,7 @@ var deploy = (program2) => {
|
|
|
2319
2362
|
write(br());
|
|
2320
2363
|
write(stackTree(dependencyTree, statuses));
|
|
2321
2364
|
write(br());
|
|
2322
|
-
const client = new StackClient(
|
|
2365
|
+
const client = new StackClient(config);
|
|
2323
2366
|
const deploymentLine = createDeploymentLine(dependencyTree);
|
|
2324
2367
|
for (const stacks of deploymentLine) {
|
|
2325
2368
|
const results = await Promise.allSettled(stacks.map(async (stack) => {
|
|
@@ -2408,35 +2451,35 @@ var textPrompt = (label, options = {}) => {
|
|
|
2408
2451
|
};
|
|
2409
2452
|
};
|
|
2410
2453
|
|
|
2411
|
-
// src/cli/command/
|
|
2454
|
+
// src/cli/command/secrets/set.ts
|
|
2412
2455
|
var set = (program2) => {
|
|
2413
|
-
program2.command("set <name>").description("Set a
|
|
2414
|
-
await layout(async (
|
|
2415
|
-
const params = new Params(
|
|
2456
|
+
program2.command("set <name>").description("Set a secret value").action(async (name) => {
|
|
2457
|
+
await layout(async (config, write) => {
|
|
2458
|
+
const params = new Params(config);
|
|
2416
2459
|
write(list({
|
|
2417
|
-
"Set
|
|
2460
|
+
"Set secret parameter": style.info(name)
|
|
2418
2461
|
}));
|
|
2419
2462
|
write(br());
|
|
2420
|
-
const value = await write(textPrompt("Enter
|
|
2463
|
+
const value = await write(textPrompt("Enter secret value"));
|
|
2421
2464
|
if (value === "") {
|
|
2422
|
-
write(dialog("error", [`Provided
|
|
2465
|
+
write(dialog("error", [`Provided secret value can't be empty`]));
|
|
2423
2466
|
} else {
|
|
2424
|
-
const done = write(loadingDialog(`Saving remote
|
|
2467
|
+
const done = write(loadingDialog(`Saving remote secret parameter`));
|
|
2425
2468
|
await params.set(name, value);
|
|
2426
|
-
done(`Done saving remote
|
|
2469
|
+
done(`Done saving remote secret parameter`);
|
|
2427
2470
|
}
|
|
2428
2471
|
});
|
|
2429
2472
|
});
|
|
2430
2473
|
};
|
|
2431
2474
|
|
|
2432
|
-
// src/cli/command/
|
|
2475
|
+
// src/cli/command/secrets/get.ts
|
|
2433
2476
|
var get = (program2) => {
|
|
2434
|
-
program2.command("get <name>").description("Get a
|
|
2435
|
-
await layout(async (
|
|
2436
|
-
const params = new Params(
|
|
2437
|
-
const done = write(loadingDialog(`Getting remote
|
|
2477
|
+
program2.command("get <name>").description("Get a secret value").action(async (name) => {
|
|
2478
|
+
await layout(async (config, write) => {
|
|
2479
|
+
const params = new Params(config);
|
|
2480
|
+
const done = write(loadingDialog(`Getting remote secret parameter`));
|
|
2438
2481
|
const value = await params.get(name);
|
|
2439
|
-
done(`Done getting remote
|
|
2482
|
+
done(`Done getting remote secret parameter`);
|
|
2440
2483
|
write(br());
|
|
2441
2484
|
write(list({
|
|
2442
2485
|
Name: name,
|
|
@@ -2446,20 +2489,20 @@ var get = (program2) => {
|
|
|
2446
2489
|
});
|
|
2447
2490
|
};
|
|
2448
2491
|
|
|
2449
|
-
// src/cli/command/
|
|
2492
|
+
// src/cli/command/secrets/delete.ts
|
|
2450
2493
|
var del = (program2) => {
|
|
2451
|
-
program2.command("delete <name>").description("Delete a
|
|
2452
|
-
await layout(async (
|
|
2453
|
-
const params = new Params(
|
|
2454
|
-
write(dialog("warning", [`Your deleting the ${style.info(name)}
|
|
2494
|
+
program2.command("delete <name>").description("Delete a secret value").action(async (name) => {
|
|
2495
|
+
await layout(async (config, write) => {
|
|
2496
|
+
const params = new Params(config);
|
|
2497
|
+
write(dialog("warning", [`Your deleting the ${style.info(name)} secret parameter`]));
|
|
2455
2498
|
const confirm = await write(confirmPrompt("Are you sure?"));
|
|
2456
2499
|
if (!confirm) {
|
|
2457
2500
|
throw new Cancelled();
|
|
2458
2501
|
}
|
|
2459
|
-
const done = write(loadingDialog(`Deleting remote
|
|
2502
|
+
const done = write(loadingDialog(`Deleting remote secret parameter`));
|
|
2460
2503
|
const value = await params.get(name);
|
|
2461
2504
|
await params.delete(name);
|
|
2462
|
-
done(`Done deleting remote
|
|
2505
|
+
done(`Done deleting remote secret parameter`);
|
|
2463
2506
|
write(br());
|
|
2464
2507
|
write(list({
|
|
2465
2508
|
Name: name,
|
|
@@ -2469,33 +2512,33 @@ var del = (program2) => {
|
|
|
2469
2512
|
});
|
|
2470
2513
|
};
|
|
2471
2514
|
|
|
2472
|
-
// src/cli/command/
|
|
2515
|
+
// src/cli/command/secrets/list.ts
|
|
2473
2516
|
var list2 = (program2) => {
|
|
2474
|
-
program2.command("list").description(`List all
|
|
2475
|
-
await layout(async (
|
|
2476
|
-
const params = new Params(
|
|
2477
|
-
const done = write(loadingDialog("Loading
|
|
2517
|
+
program2.command("list").description(`List all secret value's`).action(async () => {
|
|
2518
|
+
await layout(async (config, write) => {
|
|
2519
|
+
const params = new Params(config);
|
|
2520
|
+
const done = write(loadingDialog("Loading secret parameters..."));
|
|
2478
2521
|
const values = await params.list();
|
|
2479
|
-
done("Done loading
|
|
2522
|
+
done("Done loading secret values");
|
|
2480
2523
|
if (Object.keys(values).length > 0) {
|
|
2481
2524
|
write(br());
|
|
2482
2525
|
write(list(values));
|
|
2483
2526
|
} else {
|
|
2484
|
-
write(dialog("warning", ["No
|
|
2527
|
+
write(dialog("warning", ["No secret parameters found"]));
|
|
2485
2528
|
}
|
|
2486
2529
|
});
|
|
2487
2530
|
});
|
|
2488
2531
|
};
|
|
2489
2532
|
|
|
2490
|
-
// src/cli/command/
|
|
2533
|
+
// src/cli/command/secrets/index.ts
|
|
2491
2534
|
var commands = [
|
|
2492
2535
|
set,
|
|
2493
2536
|
get,
|
|
2494
2537
|
del,
|
|
2495
2538
|
list2
|
|
2496
2539
|
];
|
|
2497
|
-
var
|
|
2498
|
-
const command = program2.command("
|
|
2540
|
+
var secrets = (program2) => {
|
|
2541
|
+
const command = program2.command("secrets").description(`Manage app secrets`);
|
|
2499
2542
|
commands.forEach((cb) => cb(command));
|
|
2500
2543
|
};
|
|
2501
2544
|
|
|
@@ -2516,7 +2559,7 @@ var commands2 = [
|
|
|
2516
2559
|
status,
|
|
2517
2560
|
build,
|
|
2518
2561
|
deploy,
|
|
2519
|
-
|
|
2562
|
+
secrets
|
|
2520
2563
|
// diff,
|
|
2521
2564
|
// remove,
|
|
2522
2565
|
// test,
|