diff --git a/addons/api/addon/abilities/target.js b/addons/api/addon/abilities/target.js index ee2040fa6..00030ea3b 100644 --- a/addons/api/addon/abilities/target.js +++ b/addons/api/addon/abilities/target.js @@ -53,18 +53,4 @@ export default class TargetAbility extends ModelAbility { get canRemoveCredentialSources() { return this.hasAuthorizedAction('remove-credential-sources'); } - - /** - * @type {boolean} - */ - get canSetStorageBucket() { - return this.model.isSSH && this.hasAuthorizedAction('set-storage-bucket'); - } - - /** - * @type {boolean} - */ - get canRemoveStorageBucket() { - return this.hasAuthorizedAction('remove-storage-bucket'); - } } diff --git a/addons/api/addon/adapters/session-recording.js b/addons/api/addon/adapters/session-recording.js index 38f992bdc..a5d47e336 100644 --- a/addons/api/addon/adapters/session-recording.js +++ b/addons/api/addon/adapters/session-recording.js @@ -38,7 +38,7 @@ export default class SessionRecordingAdapter extends ApplicationAdapter { mime_type: mimeType, }); - const response = await fetch(url); + const response = await fetch(url, { headers: this.headers }); return response.text(); } diff --git a/addons/api/addon/generated/models/target.js b/addons/api/addon/generated/models/target.js index 0cc726387..19ee4b2f3 100644 --- a/addons/api/addon/generated/models/target.js +++ b/addons/api/addon/generated/models/target.js @@ -86,6 +86,13 @@ export default class GeneratedTargetModel extends BaseModel { @attr('string', { description: 'The storage bucket associated with this target.', + isNestedAttribute: true, }) storage_bucket_id; + + @attr('boolean', { + description: 'Whether session recording is enabled on the target.', + isNestedAttribute: true, + }) + enable_session_recording; } diff --git a/addons/api/addon/models/target.js b/addons/api/addon/models/target.js index bea1c006b..ae5060563 100644 --- a/addons/api/addon/models/target.js +++ b/addons/api/addon/models/target.js @@ -324,44 +324,6 @@ export default class TargetModel extends GeneratedTargetModel { ); } - /** - * @param {object} options - * @param {object} options.adapterOptions - * @returns {Promise} - */ - setStorageBucket(options = { adapterOptions: {} }) { - const defaultAdapterOptions = { - method: 'set-storage-bucket', - }; - - return this.save({ - ...options, - adapterOptions: { - ...defaultAdapterOptions, - ...options.adapterOptions, - }, - }); - } - - /** - * @param {object} options - * @param {object} options.adapterOptions - * @returns {Promise} - */ - removeStorageBucket(options = { adapterOptions: {} }) { - const defaultAdapterOptions = { - method: 'remove-storage-bucket', - }; - - return this.save({ - ...options, - adapterOptions: { - ...defaultAdapterOptions, - ...options.adapterOptions, - }, - }); - } - /** * True if the target type is tcp. * @type {boolean} diff --git a/addons/api/mirage/factories/target.js b/addons/api/mirage/factories/target.js index 36b990584..f09fdeb8c 100644 --- a/addons/api/mirage/factories/target.js +++ b/addons/api/mirage/factories/target.js @@ -74,7 +74,10 @@ export default factory.extend({ ); if (randomlySelectedStorageBucket && target.type === TYPE_TARGET_SSH) { - target.update({ storage_bucket_id: randomlySelectedStorageBucket.id }); + target.update({ + storage_bucket_id: randomlySelectedStorageBucket.id, + enable_session_recording: true, + }); } target.update({ diff --git a/addons/api/mirage/route-handlers/target.js b/addons/api/mirage/route-handlers/target.js index 81b99b254..ae2f1212e 100644 --- a/addons/api/mirage/route-handlers/target.js +++ b/addons/api/mirage/route-handlers/target.js @@ -101,13 +101,5 @@ export function targetHandler({ targets }, { params: { idMethod } }) { } } - if (method === 'set-storage-bucket') { - updatedAttrs.storage_bucket_id = attrs.storageBucketId; - } - - if (method === 'remove-storage-bucket') { - updatedAttrs.storage_bucket_id = null; - } - return target.update(updatedAttrs); } diff --git a/addons/api/tests/unit/abilities/target-test.js b/addons/api/tests/unit/abilities/target-test.js index 6d170579d..b5303504d 100644 --- a/addons/api/tests/unit/abilities/target-test.js +++ b/addons/api/tests/unit/abilities/target-test.js @@ -95,46 +95,4 @@ module('Unit | Abilities | Target', function (hooks) { ) ); }); - - test('it reflects when a given ssh target may set a storage bucket', function (assert) { - assert.expect(3); - const model = { - authorized_actions: ['set-storage-bucket'], - isSSH: true, - }; - const modelWithoutAuthorizedActions = { - authorized_actions: [], - isSSH: true, - }; - const modelWithoutSSHType = { - authorized_actions: ['set-storage-bucket'], - }; - - assert.true(canService.can('setStorageBucket target', model)); - assert.false( - canService.can('setStorageBucket target', modelWithoutAuthorizedActions) - ); - assert.false( - canService.can('setStorageBucket target', modelWithoutSSHType) - ); - }); - - test('it reflects when a given target may remove a storage bucket', function (assert) { - assert.expect(2); - const model = { - authorized_actions: ['remove-storage-bucket'], - }; - const modelWithoutAuthorizedActions = { - authorized_actions: [], - isSSH: true, - }; - - assert.true(canService.can('removeStorageBucket target', model)); - assert.false( - canService.can( - 'removeStorageBucket target', - modelWithoutAuthorizedActions - ) - ); - }); }); diff --git a/addons/api/tests/unit/models/target-test.js b/addons/api/tests/unit/models/target-test.js index 680ae429f..32555baa3 100644 --- a/addons/api/tests/unit/models/target-test.js +++ b/addons/api/tests/unit/models/target-test.js @@ -404,71 +404,4 @@ module('Unit | Model | target', function (hooks) { assert.true(modelTCP.isTCP); assert.false(modelTCP.isSSH); }); - - test('it has a `setStorageBucket` method that targets a specific POST API endpoint and serialization', async function (assert) { - assert.expect(1); - this.server.post( - '/v1/targets/123abc:set-storage-bucket', - (schema, request) => { - const body = JSON.parse(request.requestBody); - assert.deepEqual(body, { - storage_bucket_id: 'bucketID', - version: 1, - }); - return { id: '123abc' }; - } - ); - const store = this.owner.lookup('service:store'); - store.push({ - data: { - id: '123abc', - type: 'target', - attributes: { - name: 'Target', - description: 'Description', - storage_bucket_id: 'bucketID', - version: 1, - scope: { - scope_id: 'o_1', - type: 'scope', - }, - }, - }, - }); - const model = store.peekRecord('target', '123abc'); - await model.setStorageBucket(); - }); - - test('it has a `removeStorageBucket` method that targets a specific POST API endpoint and serialization', async function (assert) { - assert.expect(1); - this.server.post( - '/v1/targets/123abc:remove-storage-bucket', - (schema, request) => { - const body = JSON.parse(request.requestBody); - assert.deepEqual(body, { - version: 1, - }); - return { id: '123abc' }; - } - ); - const store = this.owner.lookup('service:store'); - store.push({ - data: { - id: '123abc', - type: 'target', - attributes: { - name: 'Target', - description: 'Description', - storage_bucket_id: null, - version: 1, - scope: { - scope_id: 'o_1', - type: 'scope', - }, - }, - }, - }); - const model = store.peekRecord('target', '123abc'); - await model.removeStorageBucket(); - }); }); diff --git a/addons/api/tests/unit/serializers/target-test.js b/addons/api/tests/unit/serializers/target-test.js index f81809c66..676dde493 100644 --- a/addons/api/tests/unit/serializers/target-test.js +++ b/addons/api/tests/unit/serializers/target-test.js @@ -49,9 +49,10 @@ module('Unit | Serializer | target', function (hooks) { worker_filter: null, egress_worker_filter: null, ingress_worker_filter: null, - storage_bucket_id: null, attributes: { default_port: 1234, + enable_session_recording: false, + storage_bucket_id: null, }, address: '0.0.0.0', }); @@ -128,46 +129,41 @@ module('Unit | Serializer | target', function (hooks) { }); }); - test('it serializes only storage_bucket_id and version when an `adapterOptions.method` is passed for set storage bucket', function (assert) { + test('it serializes the storage_bucket_id attribute if present', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const serializer = store.serializerFor('target'); const record = store.createRecord('target', { name: 'User', description: 'Description', - storage_bucket_id: 'bucketID', version: 1, + type: TYPE_TARGET_SSH, + enable_session_recording: true, + storage_bucket_id: 'bucketID', + default_port: 1234, + scope: { + scope_id: 'org_1', + }, }); const snapshot = record._createSnapshot(); - snapshot.adapterOptions = { - method: 'set-storage-bucket', - }; const serializedRecord = serializer.serialize(snapshot); - assert.deepEqual(serializedRecord, { - storage_bucket_id: 'bucketID', - version: 1, - }); - }); - - test('it serializes only version when an `adapterOptions.method` is passed for remove storage bucket', function (assert) { - assert.expect(1); - const store = this.owner.lookup('service:store'); - const serializer = store.serializerFor('target'); - const record = store.createRecord('target', { name: 'User', description: 'Description', - storage_bucket_id: 'bucketID', - version: 1, - }); - const snapshot = record._createSnapshot(); - snapshot.adapterOptions = { - method: 'remove-storage-bucket', - }; - const serializedRecord = serializer.serialize(snapshot); - - assert.deepEqual(serializedRecord, { version: 1, + type: TYPE_TARGET_SSH, + scope_id: 'org_1', + session_max_seconds: 28800, + session_connection_limit: null, + worker_filter: null, + egress_worker_filter: null, + ingress_worker_filter: null, + attributes: { + default_port: 1234, + enable_session_recording: true, + storage_bucket_id: 'bucketID', + }, + address: null, }); }); @@ -199,9 +195,10 @@ module('Unit | Serializer | target', function (hooks) { worker_filter: 'worker', egress_worker_filter: null, ingress_worker_filter: null, - storage_bucket_id: null, attributes: { default_port: 1234, + enable_session_recording: false, + storage_bucket_id: null, }, address: null, }); @@ -235,9 +232,10 @@ module('Unit | Serializer | target', function (hooks) { worker_filter: null, egress_worker_filter: 'egress worker', ingress_worker_filter: null, - storage_bucket_id: null, attributes: { default_port: 1234, + enable_session_recording: false, + storage_bucket_id: null, }, address: null, }); @@ -271,9 +269,10 @@ module('Unit | Serializer | target', function (hooks) { worker_filter: null, egress_worker_filter: null, ingress_worker_filter: 'ingress worker', - storage_bucket_id: null, attributes: { default_port: 1234, + enable_session_recording: false, + storage_bucket_id: null, }, address: null, }); @@ -495,6 +494,7 @@ module('Unit | Serializer | target', function (hooks) { id: '1', name: 'Target 1', storage_bucket_id: 'bucketID', + enable_session_recording: true, }; const normalized = serializer.normalizeSingleResponse( store, @@ -513,6 +513,7 @@ module('Unit | Serializer | target', function (hooks) { brokered_credential_source_ids: [], injected_application_credential_source_ids: [], storage_bucket_id: 'bucketID', + enable_session_recording: true, }, relationships: {}, }, diff --git a/ui/admin/app/components/form/target/enable-session-recording/index.hbs b/ui/admin/app/components/form/target/enable-session-recording/index.hbs index ca8f0631c..1ea694806 100644 --- a/ui/admin/app/components/form/target/enable-session-recording/index.hbs +++ b/ui/admin/app/components/form/target/enable-session-recording/index.hbs @@ -6,7 +6,7 @@