From 386eac072cd940a8cd2477709b63a89fbee955c8 Mon Sep 17 00:00:00 2001 From: Todd Date: Mon, 15 May 2023 15:47:41 -0700 Subject: [PATCH] Add recording_channel_ssh_aggregate view --- .../70/12_session_recording_views.up.sql | 19 ++++++++++++++++++ .../tests/recording/recording_channel_ssh.sql | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/internal/db/schema/migrations/oss/postgres/70/12_session_recording_views.up.sql b/internal/db/schema/migrations/oss/postgres/70/12_session_recording_views.up.sql index a4642f5e66..938b423cd4 100644 --- a/internal/db/schema/migrations/oss/postgres/70/12_session_recording_views.up.sql +++ b/internal/db/schema/migrations/oss/postgres/70/12_session_recording_views.up.sql @@ -3,6 +3,25 @@ begin; +create view recording_channel_ssh_aggregate as +select + rch.public_id, + rch.recording_connection_id, + rch.create_time, + rch.update_time, + rch.start_time, + rch.end_time, + rch.bytes_up, + rch.bytes_down, + rch.channel_type, + rchsc.program as channel_program +from recording_channel_ssh rch + left join recording_channel_ssh_session_channel rchsc on + rch.public_id = rchsc.recording_channel_id; +comment on view recording_channel_ssh_aggregate is + 'recording_channel_ssh_aggregate contains the ssh channel recording info along with other info needed for displaying it on the api.'; + + create view session_recording_aggregate as select rs.public_id, diff --git a/internal/db/sqltest/tests/recording/recording_channel_ssh.sql b/internal/db/sqltest/tests/recording/recording_channel_ssh.sql index 1ac297d99b..67aae16c05 100644 --- a/internal/db/sqltest/tests/recording/recording_channel_ssh.sql +++ b/internal/db/sqltest/tests/recording/recording_channel_ssh.sql @@ -11,9 +11,11 @@ -- subsystem_shorter_than_1024_bytes begin; - select plan(12); + select plan(14); select wtt_load('widgets', 'iam', 'kms', 'auth', 'hosts', 'targets', 'sessions'); + select has_view('recording_channel_ssh_aggregate', 'view for aggregating channel recording info does not exist'); + insert into recording_session (public_id, storage_bucket_id, session_id, state) values @@ -91,6 +93,22 @@ begin; values ('chr_456789123', 'sftp'); + prepare select_session_recordings as + select public_id::text, recording_connection_id::text, bytes_up::int, bytes_down::int, + channel_type::text, channel_program::text + from recording_channel_ssh_aggregate + order by public_id; + + select results_eq( + 'select_session_recordings', + $$VALUES + ('chr_123456789', 'cr_123456789', 10, 10, 'session', 'none'), + ('chr_234567891', 'cr_123456789', 10, 10, 'session', 'shell'), + ('chr_345678912', 'cr_123456789', 10, 10, 'session', 'exec'), + ('chr_456789123', 'cr_123456789', 10, 10, 'session', 'subsystem'), + ('chr_567891234', 'cr_123456789', 10, 10, 'x11', null)$$ + ); + -- Check that the rows were inserted select is(count(*), 5::bigint) from recording_channel_ssh where recording_connection_id = 'cr_123456789'; select is(count(*), 5::bigint) from recording_channel where recording_connection_id = 'cr_123456789';