Merge branch 'main' into feat-typed-host-set
This commit is contained in:
5 files changed
+130
-33
No files matched your search
@@ -1,9 +0,0 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
export default class FragmentHostAttributesModel extends Fragment {
|
||||
@attr('string', {
|
||||
description: 'The address (DNS or IP name) used to reach the host',
|
||||
})
|
||||
address;
|
||||
}
|
||||
@@ -1,12 +1,35 @@
|
||||
import GeneratedHostModel from '../generated/models/host';
|
||||
import { fragment } from 'ember-data-model-fragments/attributes';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
export default class HostModel extends GeneratedHostModel {
|
||||
/**
|
||||
* Attributes of this resource, if any, represented as a JSON fragment.
|
||||
* @type {FragmentHostAttributesModel}
|
||||
*/
|
||||
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
|
||||
// =attributes
|
||||
|
||||
// Static specific fields
|
||||
@attr('string', {
|
||||
description: 'The address (DNS or IP name) used to reach the host',
|
||||
isNestedAttribute: true,
|
||||
})
|
||||
address;
|
||||
|
||||
// Plugin specific fields
|
||||
@attr({
|
||||
readOnly: true,
|
||||
emptyArrayIfMissing: true,
|
||||
})
|
||||
ip_addresses;
|
||||
|
||||
@attr('string', {
|
||||
description: '',
|
||||
readOnly: true,
|
||||
})
|
||||
external_id;
|
||||
|
||||
// Aws specific
|
||||
@attr({
|
||||
readOnly: true,
|
||||
emptyArrayIfMissing: true,
|
||||
})
|
||||
dns_names;
|
||||
|
||||
/**
|
||||
* True if the host is static.
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from 'api/models/fragment-host-attributes';
|
||||
@@ -47,19 +47,30 @@ export default factory.extend({
|
||||
case 'aws':
|
||||
return {
|
||||
disable_credential_rotation: datatype.boolean(),
|
||||
tenant_id: datatype.hexaDecimal(6),
|
||||
client_id: datatype.hexaDecimal(6),
|
||||
subscription_id: datatype.hexaDecimal(8),
|
||||
secret_id: datatype.hexaDecimal(6),
|
||||
secret_value: datatype.string(12),
|
||||
region: address.state(),
|
||||
};
|
||||
case 'azure':
|
||||
return {
|
||||
disable_credential_rotation: datatype.boolean(),
|
||||
region: address.state(),
|
||||
tenant_id: datatype.hexaDecimal(6),
|
||||
client_id: datatype.hexaDecimal(6),
|
||||
subscription_id: datatype.hexaDecimal(8),
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
secrets() {
|
||||
switch (this.plugin?.name) {
|
||||
case 'aws':
|
||||
return {
|
||||
access_key_id: datatype.hexaDecimal(8),
|
||||
secret_access_key: datatype.string(12),
|
||||
};
|
||||
case 'azure':
|
||||
return {
|
||||
secret_id: datatype.hexaDecimal(6),
|
||||
secret_value: datatype.string(12),
|
||||
};
|
||||
}
|
||||
},
|
||||
withChildren: trait({
|
||||
|
||||
@@ -4,19 +4,92 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Serializer | host', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let serializer = store.serializerFor('host');
|
||||
|
||||
assert.ok(serializer);
|
||||
test('it serializes host with type static as expected', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('host', {
|
||||
name: 'Host 1',
|
||||
compositeType: 'static',
|
||||
description: 'Description',
|
||||
host_catalog_id: '123',
|
||||
version: 1,
|
||||
address: '188e:68a9:b342:c05c:2595:2f46:499c:759f',
|
||||
});
|
||||
assert.deepEqual(record.serialize(), {
|
||||
name: 'Host 1',
|
||||
description: 'Description',
|
||||
type: 'static',
|
||||
host_catalog_id: '123',
|
||||
version: 1,
|
||||
attributes: {
|
||||
address: '188e:68a9:b342:c05c:2595:2f46:499c:759f',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes records', function (assert) {
|
||||
let store = this.owner.lookup('service:store');
|
||||
let record = store.createRecord('host', {});
|
||||
test('it normalizes type static record as expected', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('host');
|
||||
const host = store.createRecord('host').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'host test',
|
||||
type: 'static',
|
||||
authorized_actions: ['no-op', 'read'],
|
||||
address: '10.0.0.1',
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(store, host, payload);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'host',
|
||||
attributes: {
|
||||
name: 'host test',
|
||||
type: 'static',
|
||||
authorized_actions: ['no-op', 'read'],
|
||||
address: '10.0.0.1',
|
||||
dns_names: [],
|
||||
ip_addresses: [],
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
let serializedRecord = record.serialize();
|
||||
|
||||
assert.ok(serializedRecord);
|
||||
test('it normalizes type plugin (aws) record as expected', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('host');
|
||||
const host = store.createRecord('host').constructor;
|
||||
const payload = {
|
||||
id: '1',
|
||||
name: 'host test',
|
||||
type: 'plugin',
|
||||
plugin: {
|
||||
name: 'aws',
|
||||
},
|
||||
authorized_actions: ['no-op', 'read'],
|
||||
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
|
||||
dns_names: ['test.example.internal', 'test.example.external'],
|
||||
};
|
||||
const normalized = serializer.normalizeSingleResponse(store, host, payload);
|
||||
assert.deepEqual(normalized, {
|
||||
included: [],
|
||||
data: {
|
||||
id: '1',
|
||||
type: 'host',
|
||||
attributes: {
|
||||
name: 'host test',
|
||||
type: 'plugin',
|
||||
authorized_actions: ['no-op', 'read'],
|
||||
ip_addresses: ['10.0.0.1', '10.0.0.2', '10.0.0.3'],
|
||||
dns_names: ['test.example.internal', 'test.example.external'],
|
||||
plugin: { name: 'aws' },
|
||||
},
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user