* feat: 🎸 create canSetWorkerTags ability for workers ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 add create-tags route ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 update worker serializer for adding api_tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 add setApiTags method on worker model ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * style: 💄 update list-wrapper styles after hds upgrade ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 add create-tags component for workers ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 add creat-tags route and view ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 add acceptance tests for worker create-tags workflow ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 add test for worker tag creation ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 fix test setup for workers ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 add license headers and update setupTest import ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 fix normal serialize test for worker ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 create worker PKI type const ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 add comments to methods and actions ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * feat: 🎸 create Tag class to use in multiple places ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 move apiTags to route controller ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 move routeWillChange logic to route ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 routeWillChange logic updates ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 remove unused services ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * test: 💍 add missing controller tests ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 small update to API tags description ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 add tracked to Tag class ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 use willTransition vs routeWillChange event ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895 * refactor: 💡 use controllerFor in route ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13895
136 lines
3.1 KiB
JavaScript
136 lines
3.1 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import GeneratedWorkerModel from '../generated/models/worker';
|
|
import { attr } from '@ember-data/model';
|
|
|
|
export const TYPE_WORKER_PKI = 'pki';
|
|
|
|
export const TAG_TYPE_CONFIG = 'config';
|
|
export const TAG_TYPE_API = 'api';
|
|
|
|
export default class WorkerModel extends GeneratedWorkerModel {
|
|
// =attributes
|
|
|
|
/**
|
|
* Names are optional on models in our API. Thus we need to fallback on ID
|
|
* for display purposes.
|
|
* @type {string}
|
|
*/
|
|
get displayName() {
|
|
return this.name || this.id;
|
|
}
|
|
|
|
/**
|
|
* Returns whether the worker is a pki worker.
|
|
* @type {boolean}
|
|
*/
|
|
get isPki() {
|
|
return this.type === TYPE_WORKER_PKI;
|
|
}
|
|
|
|
/**
|
|
* Returns the number of canonical tags present on the worker.
|
|
* @type {number}
|
|
*/
|
|
get tagCount() {
|
|
if (!this.canonical_tags) {
|
|
return 0;
|
|
}
|
|
return Object.values(this.canonical_tags).reduce(
|
|
(previousCount, currentTags) => previousCount + currentTags.length,
|
|
0,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns the config tags as an array of key/value pair objects.
|
|
* @type {[object]}
|
|
*/
|
|
get configTagList() {
|
|
if (!this.config_tags) {
|
|
return null;
|
|
}
|
|
|
|
return Object.entries(this.config_tags).flatMap(([key, value]) =>
|
|
value.map((tag) => ({ key, value: tag, type: 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: 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 ' +
|
|
'from its configuration and any tags added through other means.\nOutput only.',
|
|
readOnly: true,
|
|
})
|
|
canonical_tags;
|
|
|
|
@attr({
|
|
description:
|
|
"The tags set in the worker's configuration file.\nOutput only.",
|
|
readOnly: true,
|
|
})
|
|
config_tags;
|
|
|
|
@attr({
|
|
description: 'The api tags set for the worker.\nOutput only.',
|
|
})
|
|
api_tags;
|
|
|
|
/**
|
|
* Method to modify the adapter to handle custom POST route for creating worker.
|
|
* @param {string} workerGeneratedAuthToken
|
|
* @param {object} options
|
|
* @param {object} options.adapterOptions
|
|
* @return {Promise}
|
|
*/
|
|
createWorkerLed(workerGeneratedAuthToken, options = { adapterOptions: {} }) {
|
|
const defaultAdapterOptions = {
|
|
method: 'create:worker-led',
|
|
workerGeneratedAuthToken,
|
|
};
|
|
return super.save({
|
|
...options,
|
|
adapterOptions: {
|
|
...defaultAdapterOptions,
|
|
...options.adapterOptions,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Method to set api tags on the worker.
|
|
* @param {object} apiTags
|
|
* @return {Promise}
|
|
*/
|
|
setApiTags(apiTags) {
|
|
return this.save({
|
|
adapterOptions: { method: 'set-worker-tags', apiTags },
|
|
});
|
|
}
|
|
}
|