move code to dagger-core

This commit is contained in:
Kasper Juul Hermansen 2023-02-05 22:26:58 +01:00
parent 9f0021b708
commit ec0d0b22e6
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
18 changed files with 132 additions and 33 deletions

87
Cargo.lock generated
View File

@ -200,7 +200,22 @@ dependencies = [
name = "dagger-core"
version = "0.1.0"
dependencies = [
"clap",
"dirs",
"eyre",
"flate2",
"genco",
"graphql-introspection-query",
"graphql_client",
"hex",
"hex-literal",
"platform-info",
"reqwest",
"serde",
"serde_json",
"sha2",
"tar",
"tempfile",
]
[[package]]
@ -233,7 +248,9 @@ version = "0.1.0"
dependencies = [
"dagger-core",
"eyre",
"futures",
"genco",
"gql_client",
"pretty_assertions",
"serde",
"serde_json",
@ -384,31 +401,58 @@ dependencies = [
]
[[package]]
name = "futures-channel"
version = "0.3.25"
name = "futures"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed"
checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac"
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
[[package]]
name = "futures-executor"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb"
checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531"
[[package]]
name = "futures-macro"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d"
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
dependencies = [
"proc-macro2",
"quote",
@ -417,22 +461,23 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9"
checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364"
[[package]]
name = "futures-task"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea"
checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366"
[[package]]
name = "futures-util"
version = "0.3.25"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6"
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
@ -487,6 +532,18 @@ dependencies = [
"wasi",
]
[[package]]
name = "gql_client"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e57f4862d3e5cd4ffe8df03fa2137e620e33578bbc1895e6f8f569630e17b1db"
dependencies = [
"log",
"reqwest",
"serde",
"serde_json",
]
[[package]]
name = "graphql-introspection-query"
version = "0.2.0"

View File

@ -6,4 +6,22 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "4.1.4"
dirs = "4.0.0"
eyre = "0.6.8"
flate2 = { version = "1.0.25", features = ["zlib"] }
genco = "0.17.3"
graphql-introspection-query = "0.2.0"
graphql_client = { version = "0.12.0", features = [
"reqwest",
"reqwest-blocking",
] }
hex = "0.4.3"
hex-literal = "0.3.4"
platform-info = "1.0.2"
reqwest = { version = "0.11.14", features = ["stream", "blocking", "deflate"] }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.91"
sha2 = "0.10.6"
tar = "0.4.38"
tempfile = "3.3.0"

View File

@ -17,6 +17,4 @@ impl Client {
inner: Arc::new(InnerClient {}),
})
}
// pub fn container(&self) -> Container {}
}

View File

@ -1,4 +1,12 @@
pub mod cli_session;
pub mod config;
pub mod connect_params;
pub mod dagger;
pub mod downloader;
pub mod engine;
pub mod introspection;
pub mod schema;
pub mod session;
pub struct Scalar(String);

View File

@ -1,5 +1,4 @@
use dagger_core::introspection::IntrospectionResponse;
use crate::introspection::IntrospectionResponse;
use crate::{config::Config, engine::Engine, session::Session};
pub fn get_schema() -> eyre::Result<IntrospectionResponse> {

View File

@ -1,11 +1,10 @@
use dagger_core::introspection::{self, IntrospectionResponse};
use graphql_client::GraphQLQuery;
use reqwest::{
blocking::{Client, RequestBuilder},
header::{HeaderMap, HeaderValue, ACCEPT, CONTENT_TYPE},
};
use crate::{config::Config, connect_params::ConnectParams};
use crate::{config::Config, connect_params::ConnectParams, introspection::IntrospectionResponse};
#[derive(GraphQLQuery)]
#[graphql(
@ -65,7 +64,7 @@ impl Session {
return Err(eyre::anyhow!(error_message));
}
let json: introspection::IntrospectionResponse = res.json()?;
let json: IntrospectionResponse = res.json()?;
Ok(json)
}

View File

@ -11,8 +11,10 @@ description = "A dagger sdk for rust, written in rust"
[dependencies]
dagger-core = { path = "../dagger-core" }
eyre = "0.6.8"
futures = "0.3.26"
genco = "0.17.3"
gql_client = "1.0.7"
pretty_assertions = "1.3.0"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.92"

View File

@ -0,0 +1,10 @@
#[cfg(example_test)]
mod examples {
#[test]
fn test_example_container() {
unimplemented!();
}
}

View File

@ -1,6 +1,7 @@
use std::{collections::HashMap, ops::Add, sync::Arc};
use serde::Serialize;
use futures::executor::block_on;
use serde::{Deserialize, Serialize};
pub fn query() -> Selection {
Selection::default()
@ -92,6 +93,20 @@ impl Selection {
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
}
pub fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<Option<D>>
where
D: for<'de> Deserialize<'de>,
{
let query = self.build()?;
let resp: Option<D> = match block_on(gql_client.query(&query)) {
Ok(r) => r,
Err(e) => eyre::bail!(e),
};
Ok(resp)
}
fn path(&self) -> Vec<Selection> {
let mut selections: Vec<Selection> = vec![];
let mut cur = self;

View File

@ -2,8 +2,9 @@ use std::io::Write;
use clap::{Arg, ArgMatches};
use dagger_codegen::codegen::CodeGeneration;
use crate::{config::Config, engine::Engine, session::Session};
use dagger_core::config::Config;
use dagger_core::engine::Engine;
use dagger_core::session::Session;
#[allow(dead_code)]
pub struct GenerateCommand;

View File

@ -2,14 +2,6 @@ use cli::Cli;
pub mod cli;
mod cli_generate;
mod cli_session;
mod config;
mod connect_params;
pub mod dagger;
mod downloader;
mod engine;
mod schema;
mod session;
fn main() -> eyre::Result<()> {
let args = std::env::args();