2021-03-02 20:44:55 +00:00
|
|
|
import type { PackageDependency } from '../types';
|
2020-07-01 15:17:40 +00:00
|
|
|
|
|
|
|
export const keyValueExtractionRegex = /^\s*(?<key>[^\s]+)\s+=\s+"(?<value>[^"]+)"\s*$/;
|
2020-07-28 10:27:17 +00:00
|
|
|
export const resourceTypeExtractionRegex = /^\s*resource\s+"(?<type>[^\s]+)"\s+"(?<name>[^"]+)"\s*{/;
|
2020-07-01 15:17:40 +00:00
|
|
|
|
|
|
|
export interface ExtractionResult {
|
|
|
|
lineNumber: number;
|
|
|
|
dependencies: PackageDependency[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum TerraformDependencyTypes {
|
|
|
|
unknown = 'unknown',
|
|
|
|
module = 'module',
|
|
|
|
provider = 'provider',
|
|
|
|
required_providers = 'required_providers',
|
2020-07-02 17:20:30 +00:00
|
|
|
resource = 'resource',
|
2021-02-21 16:51:41 +00:00
|
|
|
terraform_version = 'terraform_version',
|
2020-07-01 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 10:27:17 +00:00
|
|
|
export interface TerraformManagerData {
|
|
|
|
terraformDependencyType: TerraformDependencyTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum TerraformResourceTypes {
|
|
|
|
unknown = 'unknown',
|
|
|
|
/**
|
|
|
|
* https://www.terraform.io/docs/providers/docker/r/container.html
|
|
|
|
*/
|
|
|
|
docker_container = 'docker_container',
|
|
|
|
/**
|
|
|
|
* https://www.terraform.io/docs/providers/docker/r/image.html
|
|
|
|
*/
|
|
|
|
docker_image = 'docker_image',
|
|
|
|
/**
|
|
|
|
* https://www.terraform.io/docs/providers/docker/r/service.html
|
|
|
|
*/
|
|
|
|
docker_service = 'docker_service',
|
|
|
|
/**
|
|
|
|
* https://www.terraform.io/docs/providers/helm/r/release.html
|
|
|
|
*/
|
|
|
|
helm_release = 'helm_release',
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ResourceManagerData extends TerraformManagerData {
|
|
|
|
resourceType?: TerraformResourceTypes;
|
|
|
|
chart?: string;
|
|
|
|
image?: string;
|
|
|
|
name?: string;
|
|
|
|
repository?: string;
|
|
|
|
}
|
|
|
|
|
2020-07-01 15:17:40 +00:00
|
|
|
export function getTerraformDependencyType(
|
|
|
|
value: string
|
|
|
|
): TerraformDependencyTypes {
|
|
|
|
switch (value) {
|
|
|
|
case 'module': {
|
|
|
|
return TerraformDependencyTypes.module;
|
|
|
|
}
|
|
|
|
case 'provider': {
|
|
|
|
return TerraformDependencyTypes.provider;
|
|
|
|
}
|
|
|
|
case 'required_providers': {
|
|
|
|
return TerraformDependencyTypes.required_providers;
|
|
|
|
}
|
2020-07-02 17:20:30 +00:00
|
|
|
case 'resource': {
|
|
|
|
return TerraformDependencyTypes.resource;
|
|
|
|
}
|
2021-02-21 16:51:41 +00:00
|
|
|
case 'terraform': {
|
|
|
|
return TerraformDependencyTypes.terraform_version;
|
|
|
|
}
|
2020-07-01 15:17:40 +00:00
|
|
|
default: {
|
|
|
|
return TerraformDependencyTypes.unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function checkFileContainsDependency(
|
|
|
|
content: string,
|
|
|
|
checkList: string[]
|
|
|
|
): boolean {
|
2020-12-11 08:35:56 +00:00
|
|
|
return checkList.some((check) => content.includes(check));
|
2020-07-01 15:17:40 +00:00
|
|
|
}
|
2020-07-02 17:20:30 +00:00
|
|
|
|
|
|
|
const pathStringRegex = /(.|..)?(\/[^/])+/;
|
|
|
|
export function checkIfStringIsPath(path: string): boolean {
|
|
|
|
const match = pathStringRegex.exec(path);
|
|
|
|
return !!match;
|
|
|
|
}
|