Skip to content

Commit

Permalink
fix: migrate hsm validation function calls from mesa crate to backend…
Browse files Browse the repository at this point in the history
… dispatcher
  • Loading branch information
Masber committed Jan 4, 2025
1 parent d1cc7db commit 32faf64
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/cli/commands/config_set_hsm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::{fs, io::Write, path::PathBuf};

use backend_dispatcher::contracts::BackendTrait;
use directories::ProjectDirs;
use mesa::{common::jwt_ops, hsm};
use mesa::hsm;
use toml_edit::{value, Document};

use crate::backend_dispatcher::StaticBackendDispatcher;

pub async fn exec(
backend: &StaticBackendDispatcher,
shasta_token: &str,
shasta_base_url: &str,
shasta_root_cert: &[u8],
Expand Down Expand Up @@ -36,8 +40,12 @@ pub async fn exec(
.parse::<Document>()
.expect("ERROR: could not parse configuration file to TOML");

let mut settings_hsm_available_vec =
jwt_ops::get_hsm_name_available(shasta_token).unwrap_or_default();
let mut settings_hsm_available_vec = backend
.get_hsm_name_available(shasta_token)
.await
.unwrap_or_default();
/* let mut settings_hsm_available_vec =
jwt_ops::get_hsm_name_available(shasta_token).unwrap_or_default(); */

settings_hsm_available_vec
.retain(|role| !role.eq("offline_access") && !role.eq("uma_authorization"));
Expand Down
12 changes: 10 additions & 2 deletions src/cli/commands/config_set_parent_hsm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::{fs, io::Write, path::PathBuf};

use backend_dispatcher::contracts::BackendTrait;
use directories::ProjectDirs;
use mesa::hsm;
use toml_edit::{value, Document};

use crate::backend_dispatcher::StaticBackendDispatcher;

pub async fn exec(
backend: &StaticBackendDispatcher,
shasta_token: &str,
shasta_base_url: &str,
shasta_root_cert: &[u8],
Expand Down Expand Up @@ -36,8 +40,12 @@ pub async fn exec(
.parse::<Document>()
.expect("ERROR: could not parse configuration file to TOML");

let mut settings_hsm_available_vec =
mesa::common::jwt_ops::get_hsm_name_available(shasta_token).unwrap_or(Vec::new());
let mut settings_hsm_available_vec = backend
.get_hsm_name_available(shasta_token)
.await
.unwrap_or(Vec::new());
/* let mut settings_hsm_available_vec =
mesa::common::jwt_ops::get_hsm_name_available(shasta_token).unwrap_or(Vec::new()); */

settings_hsm_available_vec
.retain(|role| !role.eq("offline_access") && !role.eq("uma_authorization"));
Expand Down
14 changes: 10 additions & 4 deletions src/cli/commands/config_unset_parent_hsm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::{fs, io::Write, path::PathBuf};

use backend_dispatcher::contracts::BackendTrait;
use directories::ProjectDirs;
use mesa::common::jwt_ops;
use toml_edit::Document;

pub async fn exec(shasta_token: &str) {
use crate::backend_dispatcher::StaticBackendDispatcher;

pub async fn exec(backend: &StaticBackendDispatcher, shasta_token: &str) {
// Read configuration file

// XDG Base Directory Specification
Expand All @@ -30,8 +32,12 @@ pub async fn exec(shasta_token: &str) {
.parse::<Document>()
.expect("ERROR: could not parse configuration file to TOML");

let mut settings_hsm_available_vec =
jwt_ops::get_hsm_name_available(shasta_token).unwrap_or(Vec::new());
let mut settings_hsm_available_vec = backend
.get_hsm_name_available(shasta_token)
.await
.unwrap_or(Vec::new());
/* let mut settings_hsm_available_vec =
jwt_ops::get_hsm_name_available(shasta_token).unwrap_or(Vec::new()); */

/* let mut settings_hsm_available_vec = jwt_ops::get_claims_from_jwt_token(shasta_token)
.unwrap()
Expand Down
4 changes: 3 additions & 1 deletion src/cli/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub async fn process_cli(
let shasta_token = backend.get_api_token(&site_name).await?;

config_set_hsm::exec(
&backend,
&shasta_token,
shasta_base_url,
shasta_root_cert,
Expand All @@ -106,6 +107,7 @@ pub async fn process_cli(
let shasta_token = backend.get_api_token(&site_name).await?;

config_set_parent_hsm::exec(
&backend,
&shasta_token,
shasta_base_url,
shasta_root_cert,
Expand Down Expand Up @@ -143,7 +145,7 @@ pub async fn process_cli(
)
.await?;

config_unset_parent_hsm::exec(shasta_token).await;
config_unset_parent_hsm::exec(&backend, shasta_token).await;
}
if let Some(_cli_config_unset_auth) = cli_config_unset.subcommand_matches("auth") {
config_unset_auth::exec().await;
Expand Down

0 comments on commit 32faf64

Please sign in to comment.