diff --git a/lib/ResourceTagCollection.js b/lib/ResourceTagCollection.js index e12ec958..43abfb2d 100644 --- a/lib/ResourceTagCollection.js +++ b/lib/ResourceTagCollection.js @@ -2,10 +2,18 @@ const tagNamespaceRegExp = new RegExp("^[a-z][a-z0-9]*$"); // part before the co const tagNameRegExp = new RegExp("^[A-Z][A-Za-z0-9]+$"); // part after the colon class ResourceTagCollection { - constructor({allowedTags}) { + constructor({allowedTags, superCollection}) { if (!allowedTags || !allowedTags.length) { throw new Error(`Missing parameter 'allowedTags'`); } + + if (superCollection) { + this._superCollection = superCollection; + this._superTags = this._superCollection.getAcceptedTags(); + } else { + this._superTags = []; + } + // No validation of tag names here since we might remove/ignore // this parameter in the future and generally allow all tags this._allowedTags = Object.freeze(allowedTags); @@ -13,6 +21,10 @@ class ResourceTagCollection { } setTag(resource, tag, value = true) { + if (this._superTags.includes(tag)) { + return this._superCollection.setTag(resource, tag, value); + } + this._validateResource(resource); this._validateTag(tag); this._validateValue(value); @@ -25,6 +37,10 @@ class ResourceTagCollection { } clearTag(resource, tag) { + if (this._superTags.includes(tag)) { + return this._superCollection.clearTag(resource, tag); + } + this._validateResource(resource); this._validateTag(tag); @@ -35,6 +51,10 @@ class ResourceTagCollection { } getTag(resource, tag) { + if (this._superTags.includes(tag)) { + return this._superCollection.getTag(resource, tag); + } + this._validateResource(resource); this._validateTag(tag); @@ -44,6 +64,10 @@ class ResourceTagCollection { } } + getAcceptedTags() { + return [...this._allowedTags, ...this._superTags]; + } + _validateResource(resource) { const path = resource.getPath(); if (!path) {