feat: 🎸 create get allTags method that includes tag type (#2349)
* feat: 🎸 create getAllTags method that includes tag type ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891 * refactor: 💡 use canonical_tags to get tagCount on a worker ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891 * refactor: 💡 add type to api and config tag list methods ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891 * refactor: 💡 change worker functions to getters ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13891
This commit is contained in:
1 parent
1bea4882ca
commit
f51124cfdb
3 files changed
+135
-8
No files matched your search
@@ -27,15 +27,14 @@ export default class WorkerModel extends GeneratedWorkerModel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of config tags present on the worker.
|
||||
* Returns the number of canonical tags present on the worker.
|
||||
* @type {number}
|
||||
*/
|
||||
get tagCount() {
|
||||
if (!this.config_tags) {
|
||||
if (!this.canonical_tags) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Object.values(this.config_tags).reduce(
|
||||
return Object.values(this.canonical_tags).reduce(
|
||||
(previousCount, currentTags) => previousCount + currentTags.length,
|
||||
0,
|
||||
);
|
||||
@@ -45,16 +44,38 @@ export default class WorkerModel extends GeneratedWorkerModel {
|
||||
* Returns the config tags as an array of key/value pair objects.
|
||||
* @type {[object]}
|
||||
*/
|
||||
getConfigTagList() {
|
||||
get configTagList() {
|
||||
if (!this.config_tags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.entries(this.config_tags).flatMap(([key, value]) =>
|
||||
value.map((tag) => ({ key, value: tag })),
|
||||
value.map((tag) => ({ key, value: tag, type: 'config' })),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the api tags as an array of key/value pair objects.
|
||||
* @type {[object]}
|
||||
*/
|
||||
get apiTagList() {
|
||||
if (!this.api_tags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.entries(this.api_tags).flatMap(([key, value]) =>
|
||||
value.map((tag) => ({ key, value: tag, type: 'api' })),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all tags as an array of key/value pair objects with tag type.
|
||||
* @type {[object]}
|
||||
*/
|
||||
get allTags() {
|
||||
return [...(this.configTagList ?? []), ...(this.apiTagList ?? [])];
|
||||
}
|
||||
|
||||
@attr({
|
||||
description:
|
||||
'The deduplicated union of the tags reported by the worker ' +
|
||||
@@ -70,6 +91,12 @@ export default class WorkerModel extends GeneratedWorkerModel {
|
||||
})
|
||||
config_tags;
|
||||
|
||||
@attr({
|
||||
description: 'The api tags set for the worker.\nOutput only.',
|
||||
readOnly: true,
|
||||
})
|
||||
api_tags;
|
||||
|
||||
/**
|
||||
* Method to modify the adapter to handle custom POST route for creating worker.
|
||||
* @param {string} workerGeneratedAuthToken
|
||||
|
||||
Reference in new issue
Block a user