diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..75c37b6 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,15 @@ +[net] +git-fetch-with-cli = true + +#[patch."https://github.com/OMGeeky/backup_config.git"] +#backup-config = { path = "../backup_config" } +# +#[patch."https://github.com/OMGeeky/twitch_backup.local_db.git"] +#local-db = { path = "../local_db" } +# +#[patch."https://github.com/OMGeeky/twba_reqwest_backoff.git"] +#reqwest-backoff = { path = "../reqwest_backoff" } + +[patch.crates-io] +yup-oauth2 = { git = "https://github.com/dermesser/yup-oauth2.git" } +google-youtube3 = { git = "https://github.com/OMGeeky/google-apis-rs.git", branch = "scope-derives" } diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index a07df59..afd13cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1964,6 +1964,7 @@ dependencies = [ "http", "http-body", "hyper", + "hyper-rustls", "hyper-tls", "ipnet", "js-sys", @@ -1973,12 +1974,16 @@ dependencies = [ "once_cell", "percent-encoding 2.3.0", "pin-project-lite", + "rustls", + "rustls-native-certs", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", "system-configuration", "tokio", "tokio-native-tls", + "tokio-rustls", "tower-service", "url 2.4.1", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index d112dd8..4d5c6a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ thiserror = "1.0" anyhow = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -reqwest = "0.11" +reqwest = { version = "0.11" , features = ["rustls-tls-native-roots"], default-features = false} chrono = "0.4" futures = "0.3" futures-util = "0.3" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..336f641 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,73 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/engine/reference/builder/ + +################################################################################ +# Create a stage for building the application. + +ARG RUST_VERSION=1.73.0 +ARG APP_NAME=uploader +FROM rust:${RUST_VERSION}-slim-bullseye AS build +ARG APP_NAME +WORKDIR /app +RUN apt-get update +RUN apt-get install -y pkg-config +RUN apt-get install -y libssl-dev +RUN apt-get install -y libudev-dev +RUN apt-get install -y git +# Build the application. +# Leverage a cache mount to /usr/local/cargo/registry/ +# for downloaded dependencies and a cache mount to /app/target/ for +# compiled dependencies which will speed up subsequent builds. +# Leverage a bind mount to the src directory to avoid having to copy the +# source code into the container. Once built, copy the executable to an +# output directory before the cache mounted /app/target is unmounted. +RUN --mount=type=bind,source=src,target=src \ + --mount=type=bind,source=Cargo.toml,target=Cargo.toml \ + --mount=type=bind,source=Cargo.lock,target=Cargo.lock \ + --mount=type=bind,source=.cargo/config.toml,target=.cargo/config.toml \ + --mount=type=cache,target=/app/target/ \ + --mount=type=cache,target=/usr/local/cargo/registry/ \ +# --mount=type=bind,source=migrations,target=migrations \ + < CustomFlowDelegate { } } impl InstalledFlowDelegate for CustomFlowDelegate { - #[tracing::instrument] + #[tracing::instrument(skip(self))] fn redirect_uri(&self) -> Option<&str> { if !(&crate::CONF.google.local_auth_redirect) { let url = "https://game-omgeeky.de:7443/googleapi/auth"; @@ -48,7 +48,7 @@ impl InstalledFlowDelegate for CustomFlowDelegate { } } impl CustomFlowDelegate { - #[tracing::instrument] + #[tracing::instrument(skip(self, url, need_code))] async fn present_user_url(&self, url: &str, need_code: bool) -> StdResult { let user: String = self .user @@ -114,6 +114,10 @@ async fn get_auth_code() -> Result { break; } + println!( + "sleeping for {} second before trying again", + crate::CONF.google.auth_file_read_timeout + ); tokio::time::sleep(tokio::time::Duration::from_secs( crate::CONF.google.auth_file_read_timeout, )) diff --git a/src/main.rs b/src/main.rs index f51abf0..3198c5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,19 @@ pub mod prelude; lazy_static! { pub(crate) static ref CONF: Conf = Conf::builder() .env() + .file( + std::env::var("TWBA_CONFIG") + .map(|v| { + dbg!(&v); + info!("using {} as primary config source after env", v); + v + }) + .unwrap_or_else(|x| { + dbg!(x); + error!("could not get config location from env"); + "./settings.toml".to_string() + }) + ) .file("./settings.toml") .file(shellexpand::tilde("~/twba/config.toml").into_owned()) .load() @@ -39,7 +52,7 @@ async fn run() -> Result<()> { let x = &CONF.google; debug!("{:?}", x); - trace!("creating db-connection"); + trace!("creating db-connection with db url: {}", &CONF.db_url); let db = local_db::open_database(Some(&CONF.db_url)).await?; trace!("migrating db"); local_db::migrate_db(&db).await?;