Skip to content

Commit c83d381

Browse files
committed
AppBuilder: Extract github_oauth_from_config() fn
1 parent d77501e commit c83d381

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/app.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ pub struct App {
6262
pub rate_limiter: RateLimiter,
6363
}
6464

65-
impl App {
66-
/// Creates a new `App` with a given `Config` and an optional HTTP `Client`
67-
///
68-
/// Configures and sets up:
69-
///
70-
/// - GitHub OAuth
71-
/// - Database connection pools
72-
/// - A `git2::Repository` instance from the index repo checkout (that server.rs ensures exists)
73-
pub fn new(config: config::Server, emails: Emails, github: Box<dyn GitHubClient>) -> App {
65+
impl<S: app_builder::State> AppBuilder<S> {
66+
pub fn github_oauth_from_config(
67+
self,
68+
config: &config::Server,
69+
) -> AppBuilder<app_builder::SetGithubOauth<S>>
70+
where
71+
S::GithubOauth: app_builder::IsUnset,
72+
{
7473
use oauth2::{AuthUrl, TokenUrl};
7574

7675
let auth_url = "https://github.com/login/oauth/authorize";
@@ -83,6 +82,19 @@ impl App {
8382
.set_auth_uri(auth_url)
8483
.set_token_uri(token_url);
8584

85+
self.github_oauth(github_oauth)
86+
}
87+
}
88+
89+
impl App {
90+
/// Creates a new `App` with a given `Config` and an optional HTTP `Client`
91+
///
92+
/// Configures and sets up:
93+
///
94+
/// - GitHub OAuth
95+
/// - Database connection pools
96+
/// - A `git2::Repository` instance from the index repo checkout (that server.rs ensures exists)
97+
pub fn new(config: config::Server, emails: Emails, github: Box<dyn GitHubClient>) -> App {
8698
let primary_database = {
8799
use secrecy::ExposeSecret;
88100

@@ -133,7 +145,7 @@ impl App {
133145
.primary_database(primary_database)
134146
.maybe_replica_database(replica_database)
135147
.github(github)
136-
.github_oauth(github_oauth)
148+
.github_oauth_from_config(&config)
137149
.emails(emails)
138150
.storage(Arc::new(Storage::from_config(&config.storage)))
139151
.rate_limiter(RateLimiter::new(config.rate_limiter.clone()))

0 commit comments

Comments
 (0)