1 unstable release
0.3.1 | Nov 18, 2024 |
---|
#192 in Cryptography
151 downloads per month
65KB
1.5K
SLoC
Ship is a powerful configuration service that sails your HCL configurations to different formats (JSON, YAML, TOML) while providing a rich fleet of built-in functions for data transformation.
Features
-
Built-in Functions
- String Operations:
upper
,lower
,trim
,trimspace
,trimprefix
,trimsuffix
- String manipulation and formatting
- Numeric Operations:
abs
,ceil
,floor
,max
,min
,sum
,parseint
- Mathematical calculations and number parsing
- Array/Map Operations:
join
,split
,range
,merge
,length
,unique
,compact
,flatten
- Collection manipulation and transformation
- Cryptographic Functions:
base64encode/decode
,urlencode/decode
- Multiple hash functions:
md5_hash
,sha1_hash
,sha256_hash
,sha512_hash
- UUID generation:
uuid_gen
,uuidv5
- Date/Time Functions:
timestamp
,timeadd
,parseduration
,formatdate
- Time manipulation and formatting
- Network Functions:
cidrnetmask
,cidrrange
,cidrhost
,cidrsubnets
- CIDR calculations and subnet operations
- HTTP Client:
http_get
,http_post
,http_json
,http_put
- RESTful API interactions
- File Operations:
file
,filemd5
,filesha1
,filesha256
,filesha512
- File reading and hashing
- Vault Integration:
vault_kv
for HashiCorp Vault key-value store integration
- String Operations:
Configuration
The service is configured via a config.hcl
file with the following structure:
settings {
listen = "<address:port>" # Service listen address
storage = "<path>" # Storage path for HCL files
vault { # Optional Vault configuration
url = "<vault-url>"
token = "<vault-token>"
}
}
API Usage
[!CAUTION]
Security Notes
- The service should be configured with appropriate access controls
- Vault token should be kept secure
- Consider network security when exposing HTTP endpoints
- File operations are restricted to the configured storage path
Convert HCL File
GET /<path>?lang=<format>
Parameters:
path
: Path to the HCL file relative to the storage directorylang
: Target format (json
,yaml
,yml
, ortoml
)
The service will:
- Read the HCL file
- Process any variables and locals
- Execute functions
- Convert to the requested format
- Return the result as a downloadable file
Special HCL Blocks
The service supports several special HCL blocks:
locals
: For defining local variableslet/var/vars
: For variable definitionsconst
: For constant values that cannot be overriddenmeta
: For metadata about the configuration
Error Handling
The service provides detailed error messages in the format:
(message)
<error description>
(error)
<status code>
Development
To build and run the service:
- Ensure you have Rust installed
- Clone the repository
- Run
cargo build
to compile - Create a
config.hcl
file - Run
cargo run
to start the service
Dependencies
~18–31MB
~494K SLoC