tangled
alpha
login
or
join now
bad-example.com
/
microcosm-links
7
fork
atom
APIs for links and references in the ATmosphere
7
fork
atom
overview
issues
pulls
pipelines
propagate hickory init error
instead of panicking
bad-example.com
8 months ago
a6bf7d38
95c60ce3
+16
-15
1 changed file
expand all
collapse all
unified
split
who-am-i
src
oauth.rs
+16
-15
who-am-i/src/oauth.rs
···
46
46
}
47
47
48
48
#[derive(Debug, Error)]
49
49
-
#[error(transparent)]
50
50
-
pub struct AuthSetupError(#[from] atrium_oauth::Error);
49
49
+
pub enum AuthSetupError {
50
50
+
#[error("failed to intiialize atrium client: {0}")]
51
51
+
AtriumClientError(atrium_oauth::Error),
52
52
+
#[error("failed to initialize hickory dns resolver: {0}")]
53
53
+
HickoryResolverError(hickory_resolver::ResolveError),
54
54
+
}
51
55
52
56
#[derive(Debug, Error)]
53
57
#[error(transparent)]
···
93
97
http_client: http_client.clone(),
94
98
})
95
99
};
100
100
+
let dns_txt_resolver =
101
101
+
HickoryDnsTxtResolver::new().map_err(AuthSetupError::HickoryResolverError)?;
96
102
let client_config = OAuthClientConfig {
97
103
client_metadata: AtprotoLocalhostClientMetadata {
98
104
redirect_uris: Some(vec![String::from("http://127.0.0.1:9997/authorized")]),
···
102
108
resolver: OAuthResolverConfig {
103
109
did_resolver: did_resolver(),
104
110
handle_resolver: AtprotoHandleResolver::new(AtprotoHandleResolverConfig {
105
105
-
dns_txt_resolver: HickoryDnsTxtResolver::default(),
111
111
+
dns_txt_resolver,
106
112
http_client: Arc::clone(&http_client),
107
113
}),
108
114
authorization_server_metadata: Default::default(),
···
112
118
session_store: MemorySessionStore::default(),
113
119
};
114
120
115
115
-
let client = OAuthClient::new(client_config)?;
121
121
+
let client = OAuthClient::new(client_config).map_err(AuthSetupError::AtriumClientError)?;
116
122
117
123
Ok(Self {
118
124
client: Arc::new(client),
···
185
191
}
186
192
}
187
193
188
188
-
pub struct HickoryDnsTxtResolver {
189
189
-
resolver: TokioResolver,
190
190
-
}
194
194
+
pub struct HickoryDnsTxtResolver(TokioResolver);
191
195
192
192
-
impl Default for HickoryDnsTxtResolver {
193
193
-
fn default() -> Self {
194
194
-
Self {
195
195
-
resolver: TokioResolver::builder_tokio()
196
196
-
.expect("failed to create resolver")
197
197
-
.build(),
198
198
-
}
196
196
+
impl HickoryDnsTxtResolver {
197
197
+
fn new() -> Result<Self, hickory_resolver::ResolveError> {
198
198
+
let resolver = TokioResolver::builder_tokio()?.build();
199
199
+
Ok(Self(resolver))
199
200
}
200
201
}
201
202
···
205
206
query: &str,
206
207
) -> core::result::Result<Vec<String>, Box<dyn std::error::Error + Send + Sync>> {
207
208
Ok(self
208
208
-
.resolver
209
209
+
.0
209
210
.txt_lookup(query)
210
211
.await?
211
212
.iter()