diff --git a/Cargo.lock b/Cargo.lock index 508c0b2..dc7cb4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1279,6 +1279,22 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "myoauth" +version = "0.1.0" +dependencies = [ + "async-std", + "crypto-hash", + "futures", + "rand 0.8.5", + "serde", + "serde_json", + "tide", + "tokio", + "tokio-postgres", + "uuid", +] + [[package]] name = "num-traits" version = "0.2.18" @@ -1298,22 +1314,6 @@ dependencies = [ "libc", ] -[[package]] -name = "oauth" -version = "0.1.0" -dependencies = [ - "async-std", - "crypto-hash", - "futures", - "rand 0.8.5", - "serde", - "serde_json", - "tide", - "tokio", - "tokio-postgres", - "uuid", -] - [[package]] name = "object" version = "0.32.2" diff --git a/Cargo.toml b/Cargo.toml index 9de0fae..16aa525 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "oauth" +name = "myoauth" version = "0.1.0" edition = "2021" @@ -13,6 +13,6 @@ serde_json = "1.0" tokio = { version = "1.37.0", features = ["full"] } tokio-postgres = { version = "0.7.10", features = ["with-uuid-1"] } futures = "0.3.30" -uuid = { verion = "1.0.0", features = ["v4", "fast-rng", "macro-diagnostics"] } +uuid = { version = "1.0.0", features = ["v4", "fast-rng", "macro-diagnostics"] } rand = "0.8.5" crypto-hash = "0.3.4" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8710f83 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM rust:1.74.1 as builder +WORKDIR /app +ADD . /app +RUN cargo build --release + +FROM debian:12.5 +RUN mkdir /myoauth +COPY --from=builder /app/target/release/myoauth /myoauth +CMD ["/myoauth/myoauth"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d16e3dd --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +pack: + sudo docker build -t myoauth . --no-cache + +publish: + sudo docker tag myoauth arielherself/myoauth && sudo docker push arielherself/myoauth diff --git a/src/main.rs b/src/main.rs index c775724..e80683c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,10 +6,18 @@ mod misc; #[tokio::main] async fn main() { - let mut b = db::OAuthDatabase::connect("localhost", 5432, "postgres", "configjson", "myoauth").await.unwrap(); - // b.init().await.unwrap(); - let u = b.trusted_register_user().await.unwrap(); - println!("Successfully registered user with uid = {}", u.user_id); + let postgres_host = std::env::var("POSTGRES_HOST").unwrap_or(String::from("localhost")); + let postgres_port = std::env::var("POSTGRES_PORT").unwrap_or(String::from("5432")); + let postgres_user = std::env::var("POSTGRES_USER").unwrap_or(String::from("postgres")); + let postgres_password = std::env::var("POSTGRES_PASSWORD").unwrap(); + loop { + if let Ok(mut b) = db::OAuthDatabase::connect(postgres_host.as_str(), str::parse(postgres_port.as_str()).unwrap(), postgres_user.as_str(), postgres_password.as_str(), "myoauth").await { + b.init().await.unwrap(); + break; + } + } + // let u = b.trusted_register_user().await.unwrap(); + // println!("Successfully registered user with uid = {}", u.user_id); } #[tokio::test]