Skip to content

Commit 3316113

Browse files
committed
AppBuilder: Add trustpub_providers() fn
1 parent 345367b commit 3316113

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/app.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use crate::storage::{Storage, StorageConfig};
1212
use axum::extract::{FromRef, FromRequestParts, State};
1313
use bon::Builder;
1414
use crates_io_github::GitHubClient;
15-
use crates_io_trustpub::keystore::OidcKeyStore;
15+
use crates_io_trustpub::github::GITHUB_ISSUER_URL;
16+
use crates_io_trustpub::keystore::{OidcKeyStore, RealOidcKeyStore};
1617
use deadpool_diesel::Runtime;
1718
use derive_more::Deref;
1819
use diesel_async::AsyncPgConnection;
@@ -94,6 +95,36 @@ impl<S: app_builder::State> AppBuilder<S> {
9495
self.github_oauth(github_oauth)
9596
}
9697

98+
/// Set the "Trusted Publishing" providers supported by the application.
99+
///
100+
/// This method configures the OIDC key stores for the specified providers
101+
/// and expects a list of provider names as input.
102+
///
103+
/// Currently, only "github" is supported as a provider.
104+
pub fn trustpub_providers(
105+
self,
106+
providers: &[String],
107+
) -> AppBuilder<app_builder::SetOidcKeyStores<S>>
108+
where
109+
S::OidcKeyStores: app_builder::IsUnset,
110+
{
111+
let mut key_stores: HashMap<String, Box<dyn OidcKeyStore>> = HashMap::new();
112+
113+
for provider in providers {
114+
match provider.as_str() {
115+
"github" => {
116+
let key_store = RealOidcKeyStore::new(GITHUB_ISSUER_URL.into());
117+
key_stores.insert(GITHUB_ISSUER_URL.into(), Box::new(key_store));
118+
}
119+
provider => {
120+
warn!("Unknown Trusted Publishing provider: {provider}");
121+
}
122+
}
123+
}
124+
125+
self.oidc_key_stores(key_stores)
126+
}
127+
97128
pub fn databases_from_config(
98129
self,
99130
config: &config::DatabasePools,

0 commit comments

Comments
 (0)