1use std::collections::HashMap;
18
19use session::context::QueryContext;
20use table::metadata::TableId;
21
22use crate::Error;
23pub type FlowId = u64;
26pub type TableName = [String; 3];
27
28#[derive(Clone)]
29pub struct FlowAuthHeader {
30 auth_schema: api::v1::auth_header::AuthScheme,
31}
32
33impl std::fmt::Debug for FlowAuthHeader {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 match self.auth() {
36 api::v1::auth_header::AuthScheme::Basic(basic) => f
37 .debug_struct("Basic")
38 .field("username", &basic.username)
39 .field("password", &"<RETRACTED>")
40 .finish(),
41 api::v1::auth_header::AuthScheme::Token(_) => f
42 .debug_struct("Token")
43 .field("token", &"<RETRACTED>")
44 .finish(),
45 }
46 }
47}
48
49impl FlowAuthHeader {
50 pub fn from_user_pwd(username: &str, pwd: &str) -> Self {
51 Self {
52 auth_schema: api::v1::auth_header::AuthScheme::Basic(api::v1::Basic {
53 username: username.to_string(),
54 password: pwd.to_string(),
55 }),
56 }
57 }
58
59 pub fn auth(&self) -> &api::v1::auth_header::AuthScheme {
60 &self.auth_schema
61 }
62}
63
64#[derive(Debug, Clone)]
66pub struct CreateFlowArgs {
67 pub flow_id: FlowId,
68 pub sink_table_name: TableName,
69 pub source_table_ids: Vec<TableId>,
70 pub create_if_not_exists: bool,
71 pub or_replace: bool,
72 pub expire_after: Option<i64>,
73 pub comment: Option<String>,
74 pub sql: String,
75 pub flow_options: HashMap<String, String>,
76 pub query_ctx: Option<QueryContext>,
77}
78
79pub trait FlowEngine {
80 async fn create_flow(&self, args: CreateFlowArgs) -> Result<Option<FlowId>, Error>;
82 async fn remove_flow(&self, flow_id: FlowId) -> Result<(), Error>;
84 async fn flush_flow(&self, flow_id: FlowId) -> Result<usize, Error>;
86 async fn flow_exist(&self, flow_id: FlowId) -> Result<bool, Error>;
88 async fn list_flows(&self) -> Result<impl IntoIterator<Item = FlowId>, Error>;
90 async fn handle_flow_inserts(
92 &self,
93 request: api::v1::region::InsertRequests,
94 ) -> Result<(), Error>;
95}