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

fix: Consider DOZER_MASTER_SECRET in dozer security generate-token #2048

Merged
merged 1 commit into from
Sep 20, 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
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