feat: extract client

This commit is contained in:
Kasper Juul Hermansen 2023-03-18 21:30:25 +01:00
parent 384294b390
commit ab6141ffb4
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
10 changed files with 242 additions and 63 deletions

61
Cargo.lock generated
View File

@ -36,6 +36,17 @@ dependencies = [
"tokio",
]
[[package]]
name = "async-trait"
version = "0.1.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.0",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -241,7 +252,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
dependencies = [
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -287,9 +298,12 @@ dependencies = [
name = "dagger-core"
version = "0.2.8"
dependencies = [
"async-trait",
"base64",
"dirs",
"eyre",
"flate2",
"gql_client",
"graphql-introspection-query",
"graphql_client",
"hex",
@ -310,13 +324,11 @@ dependencies = [
name = "dagger-sdk"
version = "0.2.19"
dependencies = [
"base64",
"dagger-core",
"derive_builder",
"eyre",
"futures",
"genco",
"gql_client",
"pretty_assertions",
"rand",
"serde",
@ -348,7 +360,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn",
"syn 1.0.109",
]
[[package]]
@ -359,7 +371,7 @@ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
dependencies = [
"darling_core",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -380,7 +392,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -390,7 +402,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
dependencies = [
"derive_builder_core",
"syn",
"syn 1.0.109",
]
[[package]]
@ -593,7 +605,7 @@ checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -645,7 +657,7 @@ checksum = "c85fd34848b1f708e6344a4af6f7bfc05172ae20ce4b35c8e417efffb4f306aa"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -732,7 +744,7 @@ dependencies = [
"quote",
"serde",
"serde_json",
"syn",
"syn 1.0.109",
]
[[package]]
@ -743,7 +755,7 @@ checksum = "d52fc9cde811f44b15ec0692b31e56a3067f6f431c5ace712f286e47c1dacc98"
dependencies = [
"graphql_client_codegen",
"proc-macro2",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1134,7 +1146,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1477,7 +1489,7 @@ checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1574,6 +1586,17 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cff13bb1732bccfe3b246f3fdb09edfd51c01d6f5299b7ccd9457c2e4e37774"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tar"
version = "0.4.38"
@ -1624,7 +1647,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1680,7 +1703,7 @@ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1734,7 +1757,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1806,7 +1829,7 @@ checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08"
dependencies = [
"lazy_static",
"quote",
"syn",
"syn 1.0.109",
]
[[package]]
@ -1929,7 +1952,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
"wasm-bindgen-shared",
]
@ -1963,7 +1986,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.109",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]

View File

@ -247,7 +247,7 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
return $(output_type) {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}
};
}
@ -273,7 +273,7 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
return vec![$(output_type) {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}]
};
}

View File

@ -12,15 +12,15 @@ use crate::utility::OptionExt;
pub fn render_object(funcs: &CommonFunctions, t: &FullType) -> eyre::Result<rust::Tokens> {
let selection = rust::import("crate::querybuilder", "Selection");
let child = rust::import("tokio::process", "Child");
let conn = rust::import("dagger_core::connect_params", "ConnectParams");
let graphql_client = rust::import("dagger_core::graphql_client", "DynGraphQLClient");
let arc = rust::import("std::sync", "Arc");
Ok(quote! {
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct $(t.name.pipe(|s| format_name(s))) {
pub proc: $arc<$child>,
pub selection: $selection,
pub conn: $conn,
pub graphql_client: $graphql_client
}
$(t.fields.pipe(|f| render_optional_args(funcs, f)))

View File

@ -17,6 +17,8 @@ tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
base64 = "0.21.0"
gql_client = "1.0.7"
dirs = "4.0.0"
flate2 = { version = "1.0.25", features = ["zlib"] }
graphql-introspection-query = "0.2.0"
@ -28,3 +30,4 @@ reqwest = { version = "0.11.14", features = ["stream", "deflate"] }
sha2 = "0.10.6"
tar = "0.4.38"
tempfile = "3.3.0"
async-trait = "0.1.67"

View File

@ -0,0 +1,54 @@
use std::collections::HashMap;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use base64::engine::general_purpose;
use base64::Engine;
use gql_client::ClientConfig;
use serde::Deserialize;
use crate::connect_params::ConnectParams;
pub trait GraphQLClient {
fn query<K>(&self, query: String) -> Pin<Box<dyn Future<Output = eyre::Result<Option<K>>>>>
where
K: for<'de> Deserialize<'de>;
}
pub type DynGraphQLClient = Arc<dyn GraphQLClient + Send + Sync>;
#[derive(Debug)]
pub struct DefaultGraphQLClient {
client: gql_client::Client,
}
impl DefaultGraphQLClient {
pub fn new(conn: &ConnectParams) -> Self {
let token = general_purpose::URL_SAFE.encode(format!("{}:", conn.session_token));
let mut headers = HashMap::new();
headers.insert("Authorization".to_string(), format!("Basic {}", token));
Self {
client: gql_client::Client::new_with_config(ClientConfig {
endpoint: conn.url(),
timeout: Some(1000),
headers: Some(headers),
proxy: None,
}),
}
}
}
impl GraphQLClient for DefaultGraphQLClient {
fn query<K>(&self, query: String) -> Pin<Box<dyn Future<Output = eyre::Result<Option<K>>>>>
where
Self: Sized,
K: for<'de> Deserialize<'de>,
{
let res = self.client.query::<K>(&query);
return Box::pin(res);
}
}

View File

@ -7,6 +7,7 @@ pub mod config;
pub mod connect_params;
pub mod downloader;
pub mod engine;
pub mod graphql_client;
pub mod introspection;
pub mod logger;
pub mod schema;

View File

@ -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]

View File

@ -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)]

View File

@ -1,6 +1,7 @@
use crate::client::graphql_client;
use crate::querybuilder::Selection;
use dagger_core::connect_params::ConnectParams;
use dagger_core::graphql_client::DynGraphQLClient;
use derive_builder::Builder;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
@ -114,11 +115,12 @@ pub struct PipelineLabel {
pub name: String,
pub value: String,
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct CacheVolume {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl CacheVolume {
@ -128,11 +130,12 @@ impl CacheVolume {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Container {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
#[derive(Builder, Debug, PartialEq)]
@ -296,6 +299,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -323,6 +327,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves default arguments for future commands.
@ -346,6 +351,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves an endpoint that clients can use to reach this container.
@ -408,6 +414,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}];
}
/// Retrieves this container after executing the specified command inside it.
@ -422,6 +429,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -456,6 +464,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Exit code of the last executed command. Zero means success.
@ -514,6 +523,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}];
}
/// Retrieves a file at the given path.
@ -531,6 +541,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Initializes this container from a pulled base image.
@ -549,6 +560,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container's root filesystem. Mounts are not included.
@ -559,6 +571,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves a hostname which can be used by clients to reach this container.
@ -596,6 +609,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}];
}
/// Retrieves the list of paths where a directory is mounted.
@ -619,6 +633,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -647,6 +662,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// The platform this container executes and publishes as.
@ -705,6 +721,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// The error stream of the last executed command.
@ -739,6 +756,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -758,6 +776,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a directory written at the given path.
@ -777,6 +796,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -808,6 +828,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container but with a different command entrypoint.
@ -827,6 +848,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus the given environment variable.
@ -849,6 +871,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container after executing the specified command inside it.
@ -869,6 +892,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -912,6 +936,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Expose a network port.
@ -933,6 +958,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -965,6 +991,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Initializes this container from this DirectoryID.
@ -977,6 +1004,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus the contents of the given file copied to the given path.
@ -996,6 +1024,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1024,6 +1053,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus the given label.
@ -1042,6 +1072,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a cache volume mounted at the given path.
@ -1061,6 +1092,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1092,6 +1124,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a directory mounted at the given path.
@ -1114,6 +1147,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a file mounted at the given path.
@ -1132,6 +1166,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a secret mounted into a file at the given path.
@ -1150,6 +1185,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a temporary directory mounted at the given path.
@ -1166,6 +1202,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a new file written at the given path.
@ -1183,6 +1220,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1211,6 +1249,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container with a registry authentication for a given address.
@ -1237,6 +1276,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Initializes this container from this DirectoryID.
@ -1249,6 +1289,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus an env variable containing the given secret.
@ -1267,6 +1308,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Establish a runtime dependency on a service. The service will be started automatically when needed and detached when it is no longer needed.
@ -1292,6 +1334,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container plus a socket forwarded to the given Unix socket path.
@ -1310,6 +1353,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container with a different command user.
@ -1326,6 +1370,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container with a different working directory.
@ -1342,6 +1387,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container minus the given environment variable.
@ -1358,6 +1404,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Unexpose a previously exposed port.
@ -1376,6 +1423,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1402,6 +1450,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container minus the given environment label.
@ -1418,6 +1467,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container after unmounting everything at the given path.
@ -1434,6 +1484,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container without the registry authentication of a given address.
@ -1451,6 +1502,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this container with a previously added Unix socket removed.
@ -1467,6 +1519,7 @@ impl Container {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves the working directory for all commands.
@ -1476,11 +1529,12 @@ impl Container {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Directory {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
#[derive(Builder, Debug, PartialEq)]
@ -1560,6 +1614,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves a directory at the given path.
@ -1576,6 +1631,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Builds a new Docker container from this directory.
@ -1590,6 +1646,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1618,6 +1675,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Returns a list of files and directories at the given path.
@ -1674,6 +1732,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// The content-addressed identifier of the directory.
@ -1692,6 +1751,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Creates a named sub-pipeline
@ -1709,6 +1769,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1737,6 +1798,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory plus a directory written at the given path.
@ -1756,6 +1818,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1787,6 +1850,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory plus the contents of the given file copied to the given path.
@ -1806,6 +1870,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1834,6 +1899,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory plus a new directory created at the given path.
@ -1851,6 +1917,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1876,6 +1943,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory plus a new file written at the given path.
@ -1895,6 +1963,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -1923,6 +1992,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory with all file/dir timestamps set to the given time.
@ -1941,6 +2011,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory with the directory at the given path removed.
@ -1957,6 +2028,7 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves this directory with the file at the given path removed.
@ -1973,14 +2045,16 @@ impl Directory {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct EnvVariable {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl EnvVariable {
@ -1997,11 +2071,12 @@ impl EnvVariable {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct File {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl File {
@ -2037,6 +2112,7 @@ impl File {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Gets the size of the file, in bytes.
@ -2061,14 +2137,16 @@ impl File {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct GitRef {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
#[derive(Builder, Debug, PartialEq)]
@ -2098,6 +2176,7 @@ impl GitRef {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2120,14 +2199,16 @@ impl GitRef {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct GitRepository {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl GitRepository {
@ -2145,6 +2226,7 @@ impl GitRepository {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Lists of branches on the repository.
@ -2167,6 +2249,7 @@ impl GitRepository {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Returns details on one tag.
@ -2183,6 +2266,7 @@ impl GitRepository {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Lists of tags on the repository.
@ -2192,11 +2276,12 @@ impl GitRepository {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Host {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
#[derive(Builder, Debug, PartialEq)]
@ -2234,6 +2319,7 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2262,6 +2348,7 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Accesses an environment variable on the host.
@ -2278,6 +2365,7 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Accesses a Unix socket on the host.
@ -2294,6 +2382,7 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Retrieves the current working directory on the host.
@ -2308,6 +2397,7 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2330,14 +2420,16 @@ impl Host {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct HostVariable {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl HostVariable {
@ -2349,6 +2441,7 @@ impl HostVariable {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// The value of this variable.
@ -2358,11 +2451,12 @@ impl HostVariable {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Label {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl Label {
@ -2379,11 +2473,12 @@ impl Label {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Port {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl Port {
@ -2406,11 +2501,12 @@ impl Port {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Project {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl Project {
@ -2422,6 +2518,7 @@ impl Project {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}];
}
/// Code files generated by the SDKs in the project
@ -2432,6 +2529,7 @@ impl Project {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// install the project's schema
@ -2459,11 +2557,11 @@ impl Project {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Query {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
#[derive(Builder, Debug, PartialEq)]
@ -2523,6 +2621,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Loads a container from ID.
@ -2540,6 +2639,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2565,6 +2665,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// The default platform of the builder.
@ -2585,6 +2686,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2604,6 +2706,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Loads a file by ID.
@ -2616,6 +2719,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Queries a git repository.
@ -2635,6 +2739,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2661,6 +2766,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Queries the host environment.
@ -2671,6 +2777,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Returns a file containing an http remote url content.
@ -2688,6 +2795,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2709,6 +2817,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Creates a named sub-pipeline.
@ -2726,6 +2835,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2750,6 +2860,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Look up a project by name
@ -2762,6 +2873,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Loads a secret from its ID.
@ -2774,6 +2886,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
/// Loads a socket by its ID.
@ -2788,6 +2901,7 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
@ -2807,14 +2921,16 @@ impl Query {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
};
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Secret {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl Secret {
@ -2831,11 +2947,12 @@ impl Secret {
query.execute(&graphql_client(&self.conn)).await
}
}
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Socket {
pub proc: Arc<Child>,
pub selection: Selection,
pub conn: ConnectParams,
pub graphql_client: DynGraphQLClient,
}
impl Socket {

View File

@ -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>,
{