#resources #uniform-resource #generate #identify #system #name #urn

bin+lib guardia-rs-urn

This lib provides a command-line tool for generating Uniform Resource Names (URNs) to uniquely identify resources within the Guardia system

2 releases

new 0.0.2 Mar 7, 2025
0.0.1 Feb 23, 2025

#376 in Testing

Download history 121/week @ 2025-02-19 23/week @ 2025-02-26

144 downloads per month

AGPL-3.0-or-later

21KB
447 lines

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("1234567890")
    .with_tenant_id("1234567890")
    .with_product("lke")
    .with_entity_type("user")
    .with_entity_id("1234567890")
    .build()?;

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

// Parsing an existing URN
let urn_str = "urn:guardia:org:1234567890:tenant:1234567890:lke:user:1234567890";
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=1234567890
export TENANT_ID=1234567890
export PRODUCT=lke
export ENTITY_TYPE=user
export ENTITY_ID=1234567890

# 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.

Dependencies

~5–13MB
~142K SLoC