Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions devolutions-agent/proto/psu_agent.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package devolutions.psu.agent.poc.v1;

option csharp_namespace = "Devolutions.Psu.Agent.Protocol";

import "google/protobuf/timestamp.proto";

service AgentControl {
Expand Down
1 change: 1 addition & 0 deletions devolutions-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod enrollment;
pub mod log;
pub mod psu_event_hub;
pub mod psu_grpc_agent;
pub(crate) mod psu_powershell;
pub mod remote_desktop;
pub mod tunnel;
mod tunnel_helpers;
Expand Down
9 changes: 4 additions & 5 deletions devolutions-agent/src/psu_event_hub/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use tokio::task::JoinSet;
use uuid::Uuid;

use crate::config::dto::PsuEventHubConnectionConf;
use crate::psu_event_hub::models::WebsocketEventResponse;
use crate::psu_event_hub::powershell_worker::PowerShellWorker;
use crate::psu_event_hub::result_store::ResultStore;
use crate::psu_powershell::{PowerShellWorker, PowerShellWorkerResponse};

#[derive(Debug, Clone)]
pub(super) struct EventHubExecutor {
Expand Down Expand Up @@ -92,7 +91,7 @@ impl EventHubExecutor {
Err(error) if return_result => {
result_store.insert(
stored_execution_id,
WebsocketEventResponse::terminating_error(error.to_string()),
PowerShellWorkerResponse::terminating_error(error.to_string()),
);
}
Err(error) => warn!(error = format!("{error:#}"), "PSU command execution failed"),
Expand All @@ -108,7 +107,7 @@ impl EventHubExecutor {
if return_result {
self.result_store.insert(
execution_id.clone(),
WebsocketEventResponse::terminating_error("No script block found."),
PowerShellWorkerResponse::terminating_error("No script block found."),
);
}
return execution_id;
Expand All @@ -125,7 +124,7 @@ impl EventHubExecutor {
Err(error) if return_result => {
result_store.insert(
stored_execution_id,
WebsocketEventResponse::terminating_error(error.to_string()),
PowerShellWorkerResponse::terminating_error(error.to_string()),
);
}
Err(error) => warn!(error = format!("{error:#}"), "PSU script execution failed"),
Expand Down
4 changes: 1 addition & 3 deletions devolutions-agent/src/psu_event_hub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub(crate) mod compat;
mod executor;
mod models;
mod powershell_worker;
mod result_store;
mod signalr;

Expand All @@ -14,7 +12,7 @@ use tokio::task::JoinSet;

use crate::config::{ConfHandle, dto};
use crate::psu_event_hub::executor::EventHubExecutor;
use crate::psu_event_hub::powershell_worker::PowerShellWorker;
use crate::psu_powershell::PowerShellWorker;

pub struct PsuEventHubTask {
conf_handle: ConfHandle,
Expand Down
170 changes: 0 additions & 170 deletions devolutions-agent/src/psu_event_hub/models.rs

This file was deleted.

26 changes: 13 additions & 13 deletions devolutions-agent/src/psu_event_hub/result_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::{Duration, Instant};

use parking_lot::Mutex;

use crate::psu_event_hub::models::WebsocketEventResponse;
use crate::psu_powershell::PowerShellWorkerResponse;

const RESULT_TTL: Duration = Duration::from_secs(15 * 60);
const MAX_RESULTS: usize = 1024;
Expand All @@ -25,7 +25,7 @@ impl ResultStore {
}
}

pub(super) fn insert(&self, execution_id: String, response: WebsocketEventResponse) {
pub(super) fn insert(&self, execution_id: String, response: PowerShellWorkerResponse) {
let mut inner = self.inner.lock();
let now = Instant::now();

Expand All @@ -41,14 +41,14 @@ impl ResultStore {
inner.enforce_limit(self.max_results);
}

pub(super) fn take(&self, execution_id: &str) -> WebsocketEventResponse {
pub(super) fn take(&self, execution_id: &str) -> PowerShellWorkerResponse {
let mut inner = self.inner.lock();
inner.remove_expired(Instant::now(), self.ttl);
inner
.results
.remove(execution_id)
.map(|stored| stored.response)
.unwrap_or_else(WebsocketEventResponse::pending)
.unwrap_or_else(PowerShellWorkerResponse::pending)
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ impl ResultStoreInner {
#[derive(Debug)]
struct StoredResult {
inserted_at: Instant,
response: WebsocketEventResponse,
response: PowerShellWorkerResponse,
}

#[cfg(test)]
Expand All @@ -113,9 +113,9 @@ mod tests {
let store = ResultStore::default();
store.insert(
"execution-id".to_owned(),
WebsocketEventResponse {
PowerShellWorkerResponse {
complete: true,
..WebsocketEventResponse::default()
..PowerShellWorkerResponse::default()
},
);

Expand All @@ -128,16 +128,16 @@ mod tests {
let store = ResultStore::test_with_limits(Duration::from_secs(60), 1);
store.insert(
"first".to_owned(),
WebsocketEventResponse {
PowerShellWorkerResponse {
complete: true,
..WebsocketEventResponse::default()
..PowerShellWorkerResponse::default()
},
);
store.insert(
"second".to_owned(),
WebsocketEventResponse {
PowerShellWorkerResponse {
complete: true,
..WebsocketEventResponse::default()
..PowerShellWorkerResponse::default()
},
);

Expand All @@ -150,9 +150,9 @@ mod tests {
let store = ResultStore::test_with_limits(Duration::ZERO, 10);
store.insert(
"execution-id".to_owned(),
WebsocketEventResponse {
PowerShellWorkerResponse {
complete: true,
..WebsocketEventResponse::default()
..PowerShellWorkerResponse::default()
},
);

Expand Down
Loading
Loading