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

ambee/giterated-api

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

Add authentication back into the API

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨c3639d1

⁨src/main.rs⁩ - ⁨1975⁩ bytes
Raw
1 use std::str::FromStr;
2
3 use giterated_api::{daemon_backend::NetworkOperationState, DaemonConnectionPool};
4 use giterated_models::{
5 authenticated::{InstanceAuthenticator, UserAuthenticator},
6 instance::Instance,
7 object_backend::ObjectBackend,
8 repository::{AccessList, Repository},
9 settings::AnySetting,
10 user::{DisplayName, User},
11 };
12
13 use color_eyre::eyre::Result;
14 use tokio::{fs::File, io::AsyncReadExt};
15 use tracing::info;
16
17 #[tokio::main]
18 async fn main() -> Result<()> {
19 tracing_subscriber::fmt::init();
20 color_eyre::install()?;
21
22 let pool = DaemonConnectionPool::connect_other(
23 Instance::from_str("giterated.dev")?,
24 ("127.0.0.1:1111").parse().unwrap(),
25 )
26 .unwrap();
27
28 let mut operation_state = NetworkOperationState::new();
29
30 let mut user = pool
31 .get_object::<User>("ambee:giterated.dev", &operation_state)
32 .await?;
33
34 info!("Getting display name for {}!", user);
35
36 let display_name = user.get::<DisplayName>(&operation_state).await?;
37
38 info!("{}'s display name is {}", user, display_name);
39
40 let repositories = user
41 .repositories(
42 &Instance::from_str("giterated.dev").unwrap(),
43 &operation_state,
44 )
45 .await?;
46
47 // info!("Repository: {:#?}", repositories);
48
49 let mut repository = pool
50 .get_object::<Repository>(
51 &repositories.first().unwrap().repository.to_string(),
52 &operation_state,
53 )
54 .await?;
55
56 // info!("First repository: {}", repository.object().to_string());
57
58 // info!("First repository description: {}", repository.get::<Description>().await?);
59 // info!("First repository visibility: {:?}", repository.get::<Visibility>().await?);
60 // info!("First repository default branch: {}", repository.get::<DefaultBranch>().await?);
61
62 info!(
63 "First repository info: {:#?}",
64 repository.info(false, None, None, &operation_state).await?
65 );
66
67 Ok(())
68 }
69