refactor: 💡 use constants for target types (#1538)
* refactor: 💡 use constants for target types * chore: 🤖 import types rather than * * chore: 🤖 use capitalized TYPES_TARGET constant name
This commit is contained in:
1 parent
473ebcc397
commit
69dfc7c784
13 files changed
+44
-32
No files matched your search
@@ -2,7 +2,9 @@ import GeneratedTargetModel from '../generated/models/target';
|
||||
import { attr } from '@ember-data/model';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export const types = ['tcp', 'ssh'];
|
||||
export const TYPE_TARGET_TCP = 'tcp';
|
||||
export const TYPE_TARGET_SSH = 'ssh';
|
||||
export const TYPES_TARGET = Object.freeze([TYPE_TARGET_TCP, TYPE_TARGET_SSH]);
|
||||
|
||||
export default class TargetModel extends GeneratedTargetModel {
|
||||
// =services
|
||||
@@ -321,7 +323,7 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isTCP() {
|
||||
return this.type === 'tcp';
|
||||
return this.type === TYPE_TARGET_TCP;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,6 +331,6 @@ export default class TargetModel extends GeneratedTargetModel {
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isSSH() {
|
||||
return this.type === 'ssh';
|
||||
return this.type === TYPE_TARGET_SSH;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@ import { trait } from 'ember-cli-mirage';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import permissions from '../helpers/permissions';
|
||||
import generateId from '../helpers/id';
|
||||
import { TYPES_TARGET } from 'api/models/target';
|
||||
|
||||
const randomBoolean = (chance = 0.5) => Math.random() < chance;
|
||||
const hostSetChance = 0.3;
|
||||
const types = ['tcp', 'ssh'];
|
||||
const types = [...TYPES_TARGET];
|
||||
|
||||
export default factory.extend({
|
||||
authorized_actions: () =>
|
||||
@@ -35,13 +36,11 @@ export default factory.extend({
|
||||
* Generates attributes fields by type.
|
||||
*/
|
||||
afterCreate(target) {
|
||||
if (target.type === 'tcp' || target.type === 'ssh') {
|
||||
target.update({
|
||||
attributes: {
|
||||
default_port: faker.datatype.number(),
|
||||
},
|
||||
});
|
||||
}
|
||||
target.update({
|
||||
attributes: {
|
||||
default_port: faker.datatype.number(),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Factory } from 'ember-cli-mirage';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { TYPE_TARGET_TCP } from 'api/models/target';
|
||||
|
||||
/**
|
||||
* GeneratedTargetModelFactory
|
||||
*/
|
||||
export default Factory.extend({
|
||||
type: 'tcp',
|
||||
type: TYPE_TARGET_TCP,
|
||||
name: () => faker.random.words(),
|
||||
session_max_seconds: () => faker.datatype.number(),
|
||||
session_connection_limit: () => faker.datatype.number(),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
|
||||
module('Unit | Model | target', function (hooks) {
|
||||
setupTest(hooks);
|
||||
@@ -383,7 +384,7 @@ module('Unit | Model | target', function (hooks) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelSSH = store.createRecord('target', {
|
||||
type: 'ssh',
|
||||
type: TYPE_TARGET_SSH,
|
||||
});
|
||||
assert.true(modelSSH.isSSH);
|
||||
assert.false(modelSSH.isTCP);
|
||||
@@ -393,7 +394,7 @@ module('Unit | Model | target', function (hooks) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelTCP = store.createRecord('target', {
|
||||
type: 'tcp',
|
||||
type: TYPE_TARGET_TCP,
|
||||
});
|
||||
assert.true(modelTCP.isTCP);
|
||||
assert.false(modelTCP.isSSH);
|
||||
|
||||
@@ -182,7 +182,6 @@ module('Unit | Serializer | auth method', function (hooks) {
|
||||
signing_algorithms,
|
||||
idp_ca_certs,
|
||||
} = record;
|
||||
console.log(record);
|
||||
assert.deepEqual(account_claim_maps, [
|
||||
{ from: 'from', to: 'to' },
|
||||
{ from: 'foo', to: 'bar' },
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
|
||||
|
||||
module('Unit | Serializer | target', function (hooks) {
|
||||
setupTest(hooks);
|
||||
@@ -26,7 +27,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
},
|
||||
default_port: 1234,
|
||||
version: 1,
|
||||
type: 'tcp',
|
||||
type: TYPE_TARGET_TCP,
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
snapshot.adapterOptions = {};
|
||||
@@ -35,7 +36,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: 'tcp',
|
||||
type: TYPE_TARGET_TCP,
|
||||
scope_id: 'org_1',
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
@@ -124,7 +125,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: 'ssh',
|
||||
type: TYPE_TARGET_SSH,
|
||||
worker_filter: 'worker',
|
||||
default_port: 1234,
|
||||
scope: {
|
||||
@@ -137,7 +138,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
name: 'User',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
type: 'ssh',
|
||||
type: TYPE_TARGET_SSH,
|
||||
scope_id: 'org_1',
|
||||
session_max_seconds: 28800,
|
||||
session_connection_limit: null,
|
||||
|
||||
Reference in new issue
Block a user