JavaScript is disabled, refresh for a better experience. ambee/giterated-api

ambee/giterated-api

Git repository hosting, collaboration, and discovery for the Fediverse.

Update to new structure

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b49b7cd

⁨src/main.rs⁩ - ⁨3521⁩ bytes
Raw
1 use std::str::FromStr;
2
3 use giterated_api::DaemonConnectionPool;
4 use giterated_api::{
5 messages::user::{UserBioRequest, UserBioResponse},
6 model::{instance::Instance, user::User},
7 };
8
9 use serde::{Deserialize, Serialize};
10 // use jwt::SignWithKey;
11
12 #[macro_use]
13 extern crate tracing;
14
15 // #[tokio::main]
16 // async fn main() -> Result<(), anyhow::Error> {
17 // tracing_subscriber::fmt::init();
18
19 // let pool = DaemonConnectionPool::connect(Instance::from_str("giterated.dev")?).unwrap();
20
21 // let mut api = GiteratedApiBuilder::from_local("giterated.dev")
22 // .unwrap()
23 // .private_key(include_str!("example_keys/giterated.key"))
24 // .public_key(include_str!("example_keys/giterated.key.pub"))
25 // .build()
26 // .await
27 // .unwrap();
28
29 // info!("Lets try to make an account!");
30
31 // let response = api
32 // .register(
33 // String::from("ambee"),
34 // None,
35 // String::from("lolthisisinthecommithistory"),
36 // &pool,
37 // )
38 // .await;
39
40 // info!("Registration response: {:?}", response);
41
42 // let token = api
43 // .authentication_token(
44 // String::from("foobar"),
45 // String::from("ambee"),
46 // String::from("password"),
47 // &pool,
48 // )
49 // .await
50 // .unwrap();
51
52 // println!("Token: {}", token);
53
54 // let public_key = api.public_key().await;
55
56 // println!("Server public key:\n{}", public_key);
57 // let verification_key = DecodingKey::from_rsa_pem(public_key.as_bytes()).unwrap();
58 // let data: TokenData<UserTokenMetadata> = decode(
59 // &token,
60 // &verification_key,
61 // &Validation::new(Algorithm::RS256),
62 // )
63 // .unwrap();
64
65 // println!("The token was valid! Data:\n{:#?}", data.claims);
66
67 // info!("Lets extend that token!");
68
69 // let new_token = api
70 // .extend_token(String::from("foobar"), token.clone(), &pool)
71 // .await
72 // .unwrap();
73 // info!("New Token Returned:\n{:?}", new_token);
74
75 // info!("Try to create a repository? uwu");
76
77 // let repository = api
78 // .create_repository(
79 // new_token.unwrap(),
80 // String::from("super-repository"),
81 // None,
82 // RepositoryVisibility::Public,
83 // String::from("master"),
84 // User::from_str("ambee:giterated.dev").unwrap(),
85 // &pool,
86 // )
87 // .await
88 // .unwrap();
89
90 // assert!(repository);
91
92 // info!("Lets view our repository!");
93
94 // let view = api
95 // .repository_info(
96 // &token,
97 // Repository::from_str("ambee:giterated.dev/[email protected]").unwrap(),
98 // &pool,
99 // )
100 // .await
101 // .unwrap();
102
103 // info!("Repository Info:\n{:#?}", view);
104
105 // Ok(())
106 // }
107
108 #[tokio::main]
109 async fn main() -> Result<(), anyhow::Error> {
110 tracing_subscriber::fmt::init();
111 let pool = DaemonConnectionPool::connect(Instance::from_str("giterated.dev")?).unwrap();
112
113 let request = UserBioRequest {
114 user: User::from_str("ambeae:giterated.dev").unwrap(),
115 };
116
117 let response = giterated_api::request::request_local(&request)
118 .execute_expect::<UserBioResponse>(&pool)
119 .await?;
120
121 info!("Response: {:?}", response);
122
123 Ok(())
124 }
125
126 #[derive(Debug, Serialize, Deserialize)]
127 struct UserTokenMetadata {
128 user: User,
129 generated_for: Instance,
130 exp: u64,
131 }
132