Skip to content

Commit

Permalink
feat: add smd service values endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSopenaBallesteros committed Jul 7, 2024
1 parent d683408 commit c191651
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/hsm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
pub mod service {

pub mod values {

pub mod role {
pub mod r#struct {
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Role {
#[serde(rename(serialize = "Role"))]
pub role: Vec<String>,
}
}

pub mod http_client {
use crate::error::Error;

use super::r#struct::Role;

/// Get list of Roles
pub async fn get(
shasta_token: &str,
shasta_base_url: &str,
shasta_root_cert: &[u8],
) -> Result<Vec<String>, Error> {
let client_builder = reqwest::Client::builder()
.add_root_certificate(reqwest::Certificate::from_pem(shasta_root_cert)?);

// Build client
let client = if let Ok(socks5_env) = std::env::var("SOCKS5") {
// socks5 proxy
log::debug!("SOCKS5 enabled");
let socks5proxy = reqwest::Proxy::all(socks5_env)?;

// rest client to authenticate
client_builder.proxy(socks5proxy).build()?
} else {
client_builder.build()?
};

let api_url: String =
shasta_base_url.to_owned() + "/smd/hsm/v2/service/values/role";

let payload = client
.get(api_url)
.bearer_auth(shasta_token)
.send()
.await
.map_err(|error| Error::NetError(error))?
.json::<Role>()
.await;

payload
.map(|role| role.role)
.map_err(|error| Error::NetError(error))
}
}

pub mod hardcoded_values {
pub fn get() -> Vec<String> {
vec![
"Storage".to_string(),
"Management".to_string(),
"Compute".to_string(),
"Service".to_string(),
"System".to_string(),
"Application".to_string(),
]
}
}
}
}
}

/// Refs:
/// Member/node state --> https://apidocs.svc.cscs.ch/iaas/hardware-state-manager/overview/#section/Valid-State-Transistions
pub mod group {
Expand Down

0 comments on commit c191651

Please sign in to comment.