Skip to content

Commit

Permalink
fix: Consider DOZER_MASTER_SECRET in dozer security generate-token (
Browse files Browse the repository at this point in the history
  • Loading branch information
chubei authored Sep 20, 2023
1 parent d94b53b commit 79bfd28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions dozer-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use tonic_reflection;
pub use tonic_web;
pub use tower_http;
mod api_helper;
pub use api_helper::get_api_security;

#[derive(Debug)]
pub struct CacheEndpoint {
Expand Down
24 changes: 11 additions & 13 deletions dozer-cli/src/simple/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::utils::{
use crate::{flatten_join_handle, join_handle_map_err};
use dozer_api::auth::{Access, Authorizer};
use dozer_api::grpc::internal::internal_pipeline_server::start_internal_pipeline_server;
use dozer_api::{grpc, rest, CacheEndpoint};
use dozer_api::{get_api_security, grpc, rest, CacheEndpoint};
use dozer_cache::cache::LmdbRwCacheManager;
use dozer_cache::dozer_log::camino::Utf8PathBuf;
use dozer_cache::dozer_log::home_dir::HomeDir;
Expand Down Expand Up @@ -276,18 +276,16 @@ impl SimpleOrchestrator {
}

pub fn generate_token(&self, ttl_in_secs: Option<i32>) -> Result<String, OrchestrationError> {
if let Some(api_config) = &self.config.api {
if let Some(api_security) = &api_config.api_security {
match api_security {
dozer_types::models::api_security::ApiSecurity::Jwt(secret) => {
let auth = Authorizer::new(secret, None, None);
let duration =
ttl_in_secs.map(|f| std::time::Duration::from_secs(f as u64));
let token = auth
.generate_token(Access::All, duration)
.map_err(OrchestrationError::GenerateTokenFailed)?;
return Ok(token);
}
if let Some(api_security) = get_api_security(get_api_security_config(&self.config).cloned())
{
match api_security {
dozer_types::models::api_security::ApiSecurity::Jwt(secret) => {
let auth = Authorizer::new(&secret, None, None);
let duration = ttl_in_secs.map(|f| std::time::Duration::from_secs(f as u64));
let token = auth
.generate_token(Access::All, duration)
.map_err(OrchestrationError::GenerateTokenFailed)?;
return Ok(token);
}
}
}
Expand Down

0 comments on commit 79bfd28

Please sign in to comment.