Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api-keys): small fixes #3499

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/api-keys/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct Cli {
pub async fn run() -> anyhow::Result<()> {
let cli = Cli::parse();

println!("config: {:?}", cli.config);
let config = Config::from_path(cli.config, EnvOverride { db_con: cli.pg_con })?;

run_cmd(config).await?;
Expand All @@ -33,7 +32,6 @@ pub async fn run() -> anyhow::Result<()> {
}

async fn run_cmd(config: Config) -> anyhow::Result<()> {
println!("Running server");
let pool = db::init_pool(&config.db).await?;
let app = crate::app::ApiKeysApp::new(pool, config.app);
crate::server::run_server(config.server, app).await
Expand Down
19 changes: 12 additions & 7 deletions core/api-keys/src/server/jwks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl RemoteJwksDecoder {
pub fn new(jwks_url: String) -> Self {
Self {
jwks_url,
cache_duration: std::time::Duration::from_secs(60 * 60),
cache_duration: std::time::Duration::from_secs(30 * 60),
keys_cache: RwLock::new(Vec::new()),
validation: Validation::new(Algorithm::RS256),
client: reqwest::Client::new(),
retry_count: 3,
backoff: std::time::Duration::from_secs(1),
retry_count: 10,
backoff: std::time::Duration::from_secs(2),
}
}

Expand All @@ -108,7 +108,6 @@ impl RemoteJwksDecoder {
}
}

// Last attempt failed, return the error
Err(err.unwrap())
}

Expand Down Expand Up @@ -143,16 +142,22 @@ impl RemoteJwksDecoder {
/// succeeds or the universe ends, whichever comes first.
pub async fn refresh_keys_periodically(&self) {
loop {
let mut err = None;
match self.refresh_keys().await {
Ok(_) => {}
Err(err) => {
// log the error and continue with stale keys
Ok(_) => {
err = None;
}
Err(e) => {
eprintln!(
"Failed to refresh JWKS after {} attempts: {:?}",
self.retry_count, err
);
err = Some(e);
}
}
if err.is_some() {
continue;
}
tokio::time::sleep(self.cache_duration).await;
}
}
Expand Down
Loading