mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-07-25 19:09:22 +02:00
feat: extract client (#48)
This extracts the client (strategy pattern), this is so that it is will be possible to test the actual querier, without hitting / requiring the dagger-engine running.
This commit is contained in:
@@ -20,9 +20,7 @@ serde_json = { workspace = true }
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
|
||||
base64 = "0.21.0"
|
||||
futures = "0.3.27"
|
||||
gql_client = "1.0.7"
|
||||
derive_builder = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@@ -1,12 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use base64::engine::general_purpose;
|
||||
use base64::Engine;
|
||||
use gql_client::ClientConfig;
|
||||
use dagger_core::graphql_client::DefaultGraphQLClient;
|
||||
|
||||
use dagger_core::config::Config;
|
||||
use dagger_core::connect_params::ConnectParams;
|
||||
use dagger_core::engine::Engine as DaggerEngine;
|
||||
|
||||
use crate::gen::Query;
|
||||
@@ -25,26 +21,12 @@ pub async fn connect_opts(cfg: Config) -> eyre::Result<DaggerConn> {
|
||||
let (conn, proc) = DaggerEngine::new().start(&cfg).await?;
|
||||
|
||||
Ok(Arc::new(Query {
|
||||
conn,
|
||||
proc: Arc::new(proc),
|
||||
selection: query(),
|
||||
graphql_client: Arc::new(DefaultGraphQLClient::new(&conn)),
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn graphql_client(conn: &ConnectParams) -> gql_client::Client {
|
||||
let token = general_purpose::URL_SAFE.encode(format!("{}:", conn.session_token));
|
||||
|
||||
let mut headers = HashMap::new();
|
||||
headers.insert("Authorization".to_string(), format!("Basic {}", token));
|
||||
|
||||
gql_client::Client::new_with_config(ClientConfig {
|
||||
endpoint: conn.url(),
|
||||
timeout: Some(1000),
|
||||
headers: Some(headers),
|
||||
proxy: None,
|
||||
})
|
||||
}
|
||||
|
||||
// Conn will automatically close on drop of proc
|
||||
|
||||
#[cfg(test)]
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
use std::{collections::HashMap, ops::Add, sync::Arc};
|
||||
|
||||
use dagger_core::graphql_client::DynGraphQLClient;
|
||||
use eyre::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -116,7 +117,7 @@ impl Selection {
|
||||
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
|
||||
}
|
||||
|
||||
pub async fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
|
||||
pub async fn execute<D>(&self, gql_client: DynGraphQLClient) -> eyre::Result<D>
|
||||
where
|
||||
D: for<'de> Deserialize<'de>,
|
||||
{
|
||||
|
Reference in New Issue
Block a user