Skip to content
Merged
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
29 changes: 21 additions & 8 deletions infra-cdk/lib/utils/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,21 @@ export class ConfigManager {
}

private _loadConfig(configFile: string): AppConfig {
const configPath = path.join(__dirname, "..", "..", configFile) // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

let configPath: string

// Uses the specified configFile if the file exists
// otherwise fallsback to existing behavior where the configFile should be
// named config.yaml and be in the infra-cdk directory. Throws an error if the
// configFile does not exist and is not the default "config.yaml"
if (fs.existsSync(configFile)) {
configPath = configFile
} else {
if (path.basename(configFile) !== "config.yaml") {
throw new Error(`Configuration file '${configFile}' not found.`)
}
const defaultConfigPath = path.join(__dirname, "..", "..", configFile) // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
configPath = defaultConfigPath
}
if (!fs.existsSync(configPath)) {
throw new Error(`Configuration file ${configPath} does not exist. Please create config.yaml file.`)
}
Expand All @@ -59,12 +72,12 @@ export class ConfigManager {

const deploymentType = parsedConfig.backend?.deployment_type || "docker"
if (deploymentType !== "docker" && deploymentType !== "zip") {
throw new Error(`Invalid deployment_type '${deploymentType}'. Must be 'docker' or 'zip'.`)
throw new Error(`Invalid deployment_type '${deploymentType}' in ${configPath}. Must be 'docker' or 'zip'.`)
}

const stackNameBase = parsedConfig.stack_name_base
if (!stackNameBase) {
throw new Error("stack_name_base is required in config.yaml")
throw new Error(`stack_name_base is required in ${configPath}`)
}
if (stackNameBase.length > MAX_STACK_NAME_BASE_LENGTH) {
throw new Error(
Expand All @@ -76,20 +89,20 @@ export class ConfigManager {
// Validate network_mode if provided
const networkMode = parsedConfig.backend?.network_mode || "PUBLIC"
if (networkMode !== "PUBLIC" && networkMode !== "VPC") {
throw new Error(`Invalid network_mode '${networkMode}'. Must be 'PUBLIC' or 'VPC'.`)
throw new Error(`Invalid network_mode '${networkMode}' in ${configPath}. Must be 'PUBLIC' or 'VPC'.`)
}

// Validate VPC configuration when network_mode is VPC
const vpcConfig = parsedConfig.backend?.vpc
if (networkMode === "VPC") {
if (!vpcConfig) {
throw new Error("backend.vpc configuration is required when network_mode is 'VPC'.")
throw new Error(`backend.vpc configuration is required in ${configPath} when network_mode is 'VPC'.`)
}
if (!vpcConfig.vpc_id) {
throw new Error("backend.vpc.vpc_id is required when network_mode is 'VPC'.")
throw new Error(`backend.vpc.vpc_id is required in ${configPath} when network_mode is 'VPC'.`)
}
if (!vpcConfig.subnet_ids || vpcConfig.subnet_ids.length === 0) {
throw new Error("backend.vpc.subnet_ids must contain at least one subnet ID when network_mode is 'VPC'.")
throw new Error(`backend.vpc.subnet_ids must contain at least one subnet ID in ${configPath} when network_mode is 'VPC'.`)
}
}

Expand Down
Loading