code0-flow 0.0.30

Crate for managing the code0-flows inside of the Flow Queue & FlowStore
Documentation
use std::str::FromStr;
use tonic::metadata::{MetadataMap, MetadataValue};

/// get_authorization_metadata
///
/// Creates a `MetadataMap` that contains the defined token as a value of the `authorization` key
/// Used for setting the runtime_token to authorize Sagittarius request
///
/// # Examples
///
/// ```
/// use code0_flow::flow_service::auth::get_authorization_metadata;
/// let token = String::from("token");
/// let metadata = get_authorization_metadata(&token);
/// assert!(metadata.get("authorization").is_some());
/// assert_eq!(metadata.get("authorization").unwrap(), "token");
/// ```
pub fn get_authorization_metadata(token: &str) -> MetadataMap {
    let metadata_value = MetadataValue::from_str(token).unwrap_or_else(|error| {
        panic!(
            "An error occurred trying to convert runtime_token into metadata: {}",
            error
        );
    });

    let mut map = MetadataMap::new();
    map.insert("authorization", metadata_value);
    map
}