wami 0.17.1

Who Am I - Multicloud Identity, IAM, STS, and SSO operations library for Rust
Documentation
//! Service-Specific Credential Builder

use super::model::*;
use chrono::Utc;
use uuid::Uuid;
use wami_core::arn::{Service, WamiArn};
use wami_core::context::WamiContext;
use wami_core::error::Result;

/// Build a new ServiceSpecificCredential resource with context-based identifiers
#[allow(clippy::result_large_err)]
pub fn build_service_credential(
    user_name: String,
    service_name: String,
    context: &WamiContext,
) -> Result<ServiceSpecificCredential> {
    let credential_id = Uuid::new_v4().to_string();

    // Build WAMI ARN using context
    let wami_arn = WamiArn::builder()
        .service(Service::Iam)
        .tenant_path(context.tenant_path().clone())
        .wami_instance(context.instance_id())
        .resource("service-credential", &credential_id)
        .build()?;

    // Generate service-specific password (for CodeCommit, IoT, etc.)
    let password = uuid::Uuid::new_v4().to_string().replace('-', "");

    let service_user_name = format!("{}-{}", user_name, &credential_id[..8]);

    Ok(ServiceSpecificCredential {
        user_name,
        service_name,
        service_user_name,
        service_password: Some(password),
        service_specific_credential_id: credential_id,
        status: "Active".to_string(),
        create_date: Utc::now(),
        wami_arn,
        providers: Vec::new(),
    })
}