guardia-rs-urn

Crates.ioguardia-rs-urn
lib.rsguardia-rs-urn
version1.0.0
created_at2025-02-23 02:21:46.165997+00
updated_at2025-05-16 11:58:51.305294+00
descriptionThis lib provides a command-line tool for generating Uniform Resource Names (URNs) to uniquely identify resources within the Guardia system.
homepage
repositoryhttps://github.com/guardiafinance/guardia-rs-urn
max_upload_size
id1565997
size78,129
Douglas Picolotto (dopic)

documentation

README

Guardia URN Generator

This project provides a library for generating and validating Uniform Resource Names (URNs) to identify resources within the Guardia system.

Features

  • URN Generation: Create URNs with mandatory field validation
  • Validation: Ensures required fields and product-specific rules
  • Environment Variable Support: Configuration via environment variables
  • URN Parser: Analyze and validate existing URNs
  • Integration Tests: BDD tests using Cucumber

Usage

API

use guardia_rs_urn::UrnBuilder;

// Generating a URN
let urn = UrnBuilder::new()
    .with_organization_id("a5b1d001-3b82-4deb-8602-9463f733646e")
    .with_tenant_id("a5b1d001-3b82-4deb-8602-9463f733646e")
    .with_product("lke")
    .with_entity_type("user")
    .with_entity_id("a5b1d001-3b82-4deb-8602-9463f733646e")
    .build()?;

println!("Generated URN: {}", urn);

// Parsing an existing URN
let urn_str = "urn:guardia:org:a5b1d001-3b82-4deb-8602-9463f733646e:tenant:a5b1d001-3b82-4deb-8602-9463f733646e:lke:user:a5b1d001-3b82-4deb-8602-9463f733646e";
let parsed_urn = GuardiaUrn::parse(urn_str)?;

// Accessing URN fields
println!("Organization ID: {}", parsed_urn.organization_id.unwrap());
println!("Product: {}", parsed_urn.product.unwrap());

Environment Variables

export ORGANIZATION_ID=a5b1d001-3b82-4deb-8602-9463f733646e
export TENANT_ID=a5b1d001-3b82-4deb-8602-9463f733646e
export PRODUCT=lke
export ENTITY_TYPE=user
export ENTITY_ID=a5b1d001-3b82-4deb-8602-9463f733646e

# The URN will be generated automatically when running the program

Supported Products

  • LKE: Basic URN without additional fields
  • PSA/BSA: Requires rail and provider
  • DWA: Requires rail, protocol, and provider

Development

Prerequisites

  • Rust and Cargo installed
  • Cucumber for integration testing

Project Structure

.
├── src/
│   └── lib.rs           # Core implementation
├── tests/
│   ├── cucumber.rs      # Test configuration
│   ├── features/        # Cucumber feature files
│   │   ├── urn.feature      # Generation tests
│   │   └── urn_parsing.feature  # Parsing tests
│   └── steps/          # Step definitions
│       ├── mod.rs
│       ├── builder_steps.rs  # Steps for generation
│       └── parser_steps.rs   # Steps for parsing
└── Cargo.toml

Running Tests

# Unit tests
cargo test

# Integration tests with Cucumber
cargo test --test cucumber

Contributing

Contributions are welcome! Please open an issue or submit a pull request for improvements or bug fixes.

Commit count: 0

cargo fmt