import { Rule } from "../rule"; import { Context } from "../context"; import { Options } from "../options"; import { Client } from "../client"; export default class ResourceGroupTag extends Rule { private readonly tagName: string; private readonly tagPattern: string; constructor(context: Context, options: Options) { super(context, options); this.tagName = options.string("name"); this.tagPattern = options.string("pattern"); } async run(client: Client): Promise { const pattern = new RegExp(`^${this.tagPattern}$`); const resourceGroups = await client.listResourceGroups(); for (const resourceGroup of resourceGroups) { const tagValue = resourceGroup.tags ? resourceGroup.tags[this.tagName] : null; if (tagValue == null) { this.report(resourceGroup, "resourceGroupTagMissing", { name: resourceGroup.name, tag: this.tagName }); } else if (!tagValue.match(pattern)) { this.report(resourceGroup, "resourceGroupTagDoesNotMatchPattern", { name: resourceGroup.name, tag: this.tagName, value: tagValue, pattern: pattern.toString() }); } } } }