use std::str::FromStr; use giterated_api::DaemonConnectionPool; use giterated_api::{ messages::user::{UserBioRequest, UserBioResponse}, model::{instance::Instance, user::User}, }; use serde::{Deserialize, Serialize}; // use jwt::SignWithKey; #[macro_use] extern crate tracing; // #[tokio::main] // async fn main() -> Result<(), anyhow::Error> { // tracing_subscriber::fmt::init(); // let pool = DaemonConnectionPool::connect(Instance::from_str("giterated.dev")?).unwrap(); // let mut api = GiteratedApiBuilder::from_local("giterated.dev") // .unwrap() // .private_key(include_str!("example_keys/giterated.key")) // .public_key(include_str!("example_keys/giterated.key.pub")) // .build() // .await // .unwrap(); // info!("Lets try to make an account!"); // let response = api // .register( // String::from("ambee"), // None, // String::from("lolthisisinthecommithistory"), // &pool, // ) // .await; // info!("Registration response: {:?}", response); // let token = api // .authentication_token( // String::from("foobar"), // String::from("ambee"), // String::from("password"), // &pool, // ) // .await // .unwrap(); // println!("Token: {}", token); // let public_key = api.public_key().await; // println!("Server public key:\n{}", public_key); // let verification_key = DecodingKey::from_rsa_pem(public_key.as_bytes()).unwrap(); // let data: TokenData = decode( // &token, // &verification_key, // &Validation::new(Algorithm::RS256), // ) // .unwrap(); // println!("The token was valid! Data:\n{:#?}", data.claims); // info!("Lets extend that token!"); // let new_token = api // .extend_token(String::from("foobar"), token.clone(), &pool) // .await // .unwrap(); // info!("New Token Returned:\n{:?}", new_token); // info!("Try to create a repository? uwu"); // let repository = api // .create_repository( // new_token.unwrap(), // String::from("super-repository"), // None, // RepositoryVisibility::Public, // String::from("master"), // User::from_str("ambee:giterated.dev").unwrap(), // &pool, // ) // .await // .unwrap(); // assert!(repository); // info!("Lets view our repository!"); // let view = api // .repository_info( // &token, // Repository::from_str("ambee:giterated.dev/super-repository@giterated.dev").unwrap(), // &pool, // ) // .await // .unwrap(); // info!("Repository Info:\n{:#?}", view); // Ok(()) // } #[tokio::main] async fn main() -> Result<(), anyhow::Error> { tracing_subscriber::fmt::init(); let pool = DaemonConnectionPool::connect(Instance::from_str("giterated.dev")?).unwrap(); let request = UserBioRequest { user: User::from_str("ambeae:giterated.dev").unwrap(), }; let response = giterated_api::request::request_local(&request) .execute_expect::(&pool) .await?; info!("Response: {:?}", response); Ok(()) } #[derive(Debug, Serialize, Deserialize)] struct UserTokenMetadata { user: User, generated_for: Instance, exp: u64, }