feat: complete Epic 1 production foundation
This commit is contained in:
1 parent
767428436d
commit
182bde8ac0
298 files changed
+35711
-5291
No files matched your search
@@ -1,7 +1,8 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
MachineAccessMode, Membership, OperationSecurityLevel, PlatformApiKeyScope, User, WorkspaceId,
|
||||
MachineAccessMode, Membership, OperationSecurityLevel, PlatformApiKeyId, PlatformApiKeyScope,
|
||||
User, WorkspaceId,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -10,6 +11,7 @@ pub struct VerifiedMachineCredential {
|
||||
pub machine_access_mode: MachineAccessMode,
|
||||
pub max_security_level: OperationSecurityLevel,
|
||||
pub scopes: Vec<PlatformApiKeyScope>,
|
||||
pub platform_api_key_id: Option<PlatformApiKeyId>,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -21,14 +27,26 @@ pub struct ResponseCacheScope {
|
||||
pub agent_key: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RuntimeRequestContext {
|
||||
pub request_id: RequestId,
|
||||
pub trace_context: TraceContext,
|
||||
pub response_cache_scope: Option<ResponseCacheScope>,
|
||||
pub metering_context: Option<MeteringContext>,
|
||||
dispatch_started: Option<Arc<AtomicBool>>,
|
||||
}
|
||||
|
||||
impl PartialEq for RuntimeRequestContext {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.request_id == other.request_id
|
||||
&& self.trace_context == other.trace_context
|
||||
&& self.response_cache_scope == other.response_cache_scope
|
||||
&& self.metering_context == other.metering_context
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for RuntimeRequestContext {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct MeteringContext {
|
||||
pub workspace_id: WorkspaceId,
|
||||
@@ -43,6 +61,7 @@ impl RuntimeRequestContext {
|
||||
trace_context,
|
||||
response_cache_scope: None,
|
||||
metering_context: None,
|
||||
dispatch_started: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,22 +130,43 @@ impl RuntimeRequestContext {
|
||||
pub fn metering_context(&self) -> Option<&MeteringContext> {
|
||||
self.metering_context.as_ref()
|
||||
}
|
||||
|
||||
pub fn with_dispatch_started(mut self, dispatch_started: Arc<AtomicBool>) -> Self {
|
||||
self.dispatch_started = Some(dispatch_started);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mark_dispatch_started(&self) {
|
||||
if let Some(dispatch_started) = &self.dispatch_started {
|
||||
dispatch_started.store(true, Ordering::Release);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Clone, PartialEq, Default)]
|
||||
pub struct PreparedRequest {
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub path_params: BTreeMap<String, String>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub query_params: BTreeMap<String, String>,
|
||||
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub headers: BTreeMap<String, String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub trusted_header_names: BTreeSet<String>,
|
||||
pub body: Option<Value>,
|
||||
#[serde(default)]
|
||||
pub timeout_ms: u64,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for PreparedRequest {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter
|
||||
.debug_struct("PreparedRequest")
|
||||
.field("path_param_count", &self.path_params.len())
|
||||
.field("query_param_count", &self.query_params.len())
|
||||
.field("header_count", &self.headers.len())
|
||||
.field("trusted_header_count", &self.trusted_header_names.len())
|
||||
.field("body_configured", &self.body.is_some())
|
||||
.field("timeout_ms", &self.timeout_ms)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AdapterResponse {
|
||||
pub status_code: u16,
|
||||
@@ -143,8 +183,33 @@ pub enum ProtocolAdapterError {
|
||||
protocol: Protocol,
|
||||
mode: ExecutionMode,
|
||||
},
|
||||
#[error("{0}")]
|
||||
Message(String),
|
||||
#[error("adapter configuration is invalid")]
|
||||
InvalidConfiguration,
|
||||
#[error("prepared request is invalid")]
|
||||
InvalidPreparedRequest,
|
||||
#[error("upstream request exceeded the configured limit")]
|
||||
RequestTooLarge,
|
||||
#[error("outbound target was rejected")]
|
||||
TargetRejected,
|
||||
#[error("upstream transport failed")]
|
||||
Transport { dispatch: DispatchEvidence },
|
||||
#[error("upstream request timed out")]
|
||||
Timeout { dispatch: DispatchEvidence },
|
||||
#[error("upstream response exceeded the configured limit")]
|
||||
ResponseTooLarge { dispatch: DispatchEvidence },
|
||||
#[error("upstream returned status {status}")]
|
||||
UnexpectedStatus {
|
||||
status: u16,
|
||||
dispatch: DispatchEvidence,
|
||||
},
|
||||
#[error("upstream response could not be decoded")]
|
||||
InvalidResponse { dispatch: DispatchEvidence },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum DispatchEvidence {
|
||||
NotDispatched,
|
||||
MayHaveDispatched,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
Reference in new issue
Block a user