Skip to content

Commit

Permalink
Update resolver config
Browse files Browse the repository at this point in the history
  • Loading branch information
sugyan committed Sep 6, 2024
1 parent 3c53e71 commit aedbfa2
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 14 deletions.
6 changes: 3 additions & 3 deletions atrium-oauth/oauth-client/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ struct HickoryDnsTxtResolver {
resolver: TokioAsyncResolver,
}

impl HickoryDnsTxtResolver {
pub fn new() -> Self {
impl Default for HickoryDnsTxtResolver {
fn default() -> Self {
Self {
resolver: TokioAsyncResolver::tokio_from_system_conf()
.expect("failed to create resolver"),
Expand Down Expand Up @@ -50,7 +50,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
resolver: OAuthResolverConfig {
did: DidResolverConfig::default(),
handle: HandleResolverConfig {
r#impl: HandleResolverImpl::Atproto(Arc::new(HickoryDnsTxtResolver::new())),
r#impl: HandleResolverImpl::Atproto(Arc::new(HickoryDnsTxtResolver::default())),
},
},
state_store: MemoryStateStore::default(),
Expand Down
1 change: 1 addition & 0 deletions atrium-oauth/oauth-client/src/identity/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ use super::Resolver;
use atrium_api::did_doc::DidDocument;
use atrium_api::types::string::Did;
pub use common_resolver::{CommonDidResolver, CommonDidResolverConfig};
pub(crate) use plc_resolver::DEFAULT_PLC_DIRECTORY_URL;

pub trait DidResolver: Resolver<Input = Did, Output = DidDocument> {}
4 changes: 2 additions & 2 deletions atrium-oauth/oauth-client/src/identity/did/common_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use super::web_resolver::{WebDidResolver, WebDidResolverConfig};
use super::DidResolver;
use std::sync::Arc;

#[derive(Default)]
#[derive(Clone, Debug)]
pub struct CommonDidResolverConfig<T> {
pub plc_directory_url: Option<String>,
pub plc_directory_url: String,
pub http_client: Arc<T>,
}

Expand Down
10 changes: 4 additions & 6 deletions atrium-oauth/oauth-client/src/identity/did/plc_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use atrium_xrpc::http::{Request, Uri};
use atrium_xrpc::HttpClient;
use std::sync::Arc;

const DEFAULT_PLC_DIRECTORY_URL: &str = "https://plc.directory/";
pub(crate) const DEFAULT_PLC_DIRECTORY_URL: &str = "https://plc.directory/";

#[derive(Clone, Debug)]
pub struct PlcDidResolverConfig<T> {
pub plc_directory_url: Option<String>,
pub plc_directory_url: String,
pub http_client: Arc<T>,
}

Expand All @@ -23,10 +24,7 @@ pub struct PlcDidResolver<T> {
impl<T> PlcDidResolver<T> {
pub fn new(config: PlcDidResolverConfig<T>) -> Result<Self> {
Ok(Self {
plc_directory_url: config
.plc_directory_url
.unwrap_or(DEFAULT_PLC_DIRECTORY_URL.into())
.parse()?,
plc_directory_url: config.plc_directory_url.parse()?,
http_client: config.http_client,
})
}
Expand Down
1 change: 1 addition & 0 deletions atrium-oauth/oauth-client/src/identity/did/web_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;

const DID_WEB_PREFIX: &str = "did:web:";

#[derive(Clone, Debug)]
pub struct WebDidResolverConfig<T> {
pub http_client: Arc<T>,
}
Expand Down
11 changes: 11 additions & 0 deletions atrium-oauth/oauth-client/src/identity/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ impl Resolver for DynamicHandleResolver {

impl HandleResolver for DynamicHandleResolver {}

#[derive(Clone)]
pub enum HandleResolverImpl {
Atproto(Arc<dyn DnsTxtResolver + Send + Sync + 'static>),
AppView(String),
}

impl std::fmt::Debug for HandleResolverImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HandleResolverImpl::Atproto(_) => write!(f, "Atproto"),
HandleResolverImpl::AppView(url) => write!(f, "AppView({url})"),
}
}
}

#[derive(Clone, Debug)]
pub struct HandleResolverConfig<T> {
pub r#impl: HandleResolverImpl,
pub http_client: Arc<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use atrium_xrpc::http::{Request, Uri};
use atrium_xrpc::HttpClient;
use std::sync::Arc;

#[derive(Clone, Debug)]
pub struct AppViewHandleResolverConfig<T> {
pub service_url: String,
pub http_client: Arc<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use atrium_xrpc::HttpClient;
use futures::future::select_ok;
use std::sync::Arc;

#[derive(Clone, Debug)]
pub struct AtprotoHandleResolverConfig<R, T> {
pub dns_txt_resolver: R,
pub http_client: Arc<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl DnsTxtResolver for DynamicDnsTxtResolver {
}
}

#[derive(Clone, Debug)]
pub struct DnsHandleResolverConfig<T> {
pub dns_txt_resolver: T,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::sync::Arc;

const WELL_KNWON_PATH: &str = "/.well-known/atproto-did";

#[derive(Clone, Debug)]
pub struct WellKnownHandleResolverConfig<T> {
pub http_client: Arc<T>,
}
Expand Down
16 changes: 13 additions & 3 deletions atrium-oauth/oauth-client/src/identity/identity_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::did::{CommonDidResolver, CommonDidResolverConfig};
use super::did::{CommonDidResolver, CommonDidResolverConfig, DEFAULT_PLC_DIRECTORY_URL};
use super::error::{Error, Result};
use super::handle::{DynamicHandleResolver, HandleResolverImpl};
use super::Resolver;
Expand All @@ -15,15 +15,25 @@ pub struct ResolvedIdentity {
pub pds: String,
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct DidResolverConfig {
pub plc_directory_url: Option<String>,
pub plc_directory_url: String,
}

impl Default for DidResolverConfig {
fn default() -> Self {
Self {
plc_directory_url: DEFAULT_PLC_DIRECTORY_URL.to_string(),
}
}
}

#[derive(Clone, Debug)]
pub struct HandleResolverConfig {
pub r#impl: HandleResolverImpl,
}

#[derive(Clone, Debug)]
pub struct IdentityResolverConfig<T> {
pub did: DidResolverConfig,
pub handle: HandleResolverConfig,
Expand Down
1 change: 1 addition & 0 deletions atrium-oauth/oauth-client/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use oauth_authorization_server_resolver::DefaultOAuthAuthorizationServerResolver
use oauth_protected_resource_resolver::OAuthProtectedResourceMetadata;
use std::sync::Arc;

#[derive(Clone, Debug)]
pub struct OAuthResolverConfig {
pub did: DidResolverConfig,
pub handle: HandleResolverConfig,
Expand Down

0 comments on commit aedbfa2

Please sign in to comment.