Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const deploy = async (
) => {
const context = constructActionContext({ ...options, stackName });
logger.info('Validating yaml...');
const iac = parseYaml(context.iacLocation);
const iac = parseYaml(context);
logger.info('Yaml is valid! 🎉');

logger.info('Deploying stack...');
Expand Down
2 changes: 1 addition & 1 deletion src/commands/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const template = (
options: { format: TemplateFormat; location: string; stage: string | undefined },
) => {
const context = constructActionContext({ ...options, stackName });
const iac = parseYaml(context.iacLocation);
const iac = parseYaml(context);
const { template } = generateStackTemplate(stackName, iac, context);

const output =
Expand Down
2 changes: 1 addition & 1 deletion src/commands/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseYaml } from '../parser';

export const validate = (location: string | undefined, stage: string | undefined) => {
const context = constructActionContext({ location, stage });
parseYaml(context.iacLocation);
parseYaml(context);
logger.info('Yaml is valid! 🎉');
logger.debug('Yaml is valid! debug🎉');
};
8 changes: 4 additions & 4 deletions src/parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { existsSync, readFileSync } from 'node:fs';
import { ServerlessIac, ServerlessIacRaw } from '../types';
import { ActionContext, ServerlessIac, ServerlessIacRaw } from '../types';
import { parseFunction } from './functionParser';
import { parseEvent } from './eventParser';
import { parseDatabase } from './databaseParser';
Expand Down Expand Up @@ -27,10 +27,10 @@ const transformYaml = (iacJson: ServerlessIacRaw): ServerlessIac => {
};
};

export const parseYaml = (yamlPath: string): ServerlessIac => {
validateExistence(yamlPath);
export const parseYaml = (context: ActionContext): ServerlessIac => {
validateExistence(context.iacLocation);

const yamlContent = readFileSync(yamlPath, 'utf8');
const yamlContent = readFileSync(context.iacLocation, 'utf8');
const iacJson = parse(yamlContent) as ServerlessIacRaw;

validateYaml(iacJson);
Expand Down
11 changes: 5 additions & 6 deletions src/parser/tagParser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TagDomain, Tags } from '../types';
import { isEmpty } from 'lodash';

export const parseTag = (tags?: Tags): Array<TagDomain> => {
const tagList = [{ key: 'iac-provider', value: 'ServerlessInsight' }];
if (isEmpty(tags)) return tagList;

return [...tagList, ...Object.entries(tags).map(([key, value]) => ({ key, value }))];
export const parseTag = (tags: Tags | undefined): Array<TagDomain> => {
return [
{ key: 'iac-provider', value: 'ServerlessInsight' },
...Object.entries(tags ?? {}).map(([key, value]) => ({ key, value })),
];
};
4 changes: 2 additions & 2 deletions src/stack/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as ros from '@alicloud/ros-cdk-core';
import { ActionContext, ServerlessIac } from '../types';
import { logger, rosStackDeploy } from '../common';
import { IacStack } from './iacStack';
import { RosStack } from './rosStack/rosStack';

export const generateStackTemplate = (
stackName: string,
iac: ServerlessIac,
context: ActionContext,
) => {
const app = new ros.App();
new IacStack(app, iac, context);
new RosStack(app, iac, context);

const assembly = app.synth();
const stackArtifact = assembly.getStackByName(stackName);
Expand Down
255 changes: 0 additions & 255 deletions src/stack/iacStack.ts

This file was deleted.

52 changes: 52 additions & 0 deletions src/stack/rosStack/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as ros from '@alicloud/ros-cdk-core';
import { replaceReference } from '../../common';
import { ActionContext, DatabaseDomain, DatabaseEngineMode, DatabaseEnum } from '../../types';
import { isEmpty } from 'lodash';
import * as esServerless from '@alicloud/ros-cdk-elasticsearchserverless';

export const resolveDatabases = (
scope: ros.Construct,
databases: Array<DatabaseDomain> | undefined,
context: ActionContext,
) => {
if (isEmpty(databases)) {
return undefined;
}
databases!.forEach((db) => {
if ([DatabaseEnum.ELASTICSEARCH_SERVERLESS].includes(db.type)) {
new esServerless.App(
scope,
replaceReference(db.key, context),
{
appName: replaceReference(db.name, context),
appVersion: db.version,
authentication: {
basicAuth: [
{
password: replaceReference(db.security.basicAuth.password, context),
},
],
},
quotaInfo: {
cu: db.cu,
storage: db.storageSize,
appType: db.engineMode === DatabaseEngineMode.TIMESERIES ? 'TRIAL' : 'STANDARD',
},
// network: [
// {
// type: 'PUBLIC_KIBANA',
// enabled: true,
// whiteIpGroup: [{ groupName: 'default', ips: ['0.0.0.0/24'] }],
// },
// {
// type: 'PUBLIC_ES',
// enabled: true,
// whiteIpGroup: [{ groupName: 'default', ips: ['0.0.0.0/24'] }],
// },
// ],
},
true,
);
}
});
};
Loading
Loading