Skip to content

Guarantees ​

Guarantees are the core of EnsuraScript - declarative constraints that must be satisfied.

The Ensure Statement ​

ens
ensure <condition> [on <resource>] [with <handler> <args>] [when <guard>]

Basic Guarantee ​

ens
ensure exists on file "config.yaml"

With Handler ​

ens
ensure encrypted on file "secrets.db" with AES:256 key "env:SECRET_KEY"

With Guard ​

ens
ensure encrypted on file "secrets.db" when environment == "prod"

Conditions ​

Conditions describe what should be true about a resource.

Filesystem Conditions ​

ConditionDescriptionImplies
existsResource exists-
readableFile is readableexists
writableFile is writableexists
encryptedFile is encryptedexists, readable, writable
permissionsFile has specific permissionsexists
checksumFile has specific checksumexists, readable
contentFile has specific contentexists

HTTP Conditions ​

ConditionDescriptionImplies
reachableEndpoint is reachable-
status_codeReturns specific statusreachable
tlsUses valid TLSreachable

Service Conditions ​

ConditionDescriptionImplies
runningService is running-
stoppedService is stopped-
listeningService is listeningrunning
healthyService is healthyrunning

Dependencies ​

Requires ​

Specify that one guarantee depends on another:

ens
ensure backed_up on file "secrets.db" requires encrypted

After/Before ​

Specify ordering without hard dependencies:

ens
ensure backed_up on file "secrets.db" after database "main" stable

Context Blocks ​

Group guarantees for a single resource:

ens
on file "secrets.db" {
  ensure exists
  ensure encrypted with AES:256 key "env:SECRET_KEY"
  ensure permissions with posix mode "0600"
}

Statements inside the block inherit the subject.

How Guarantees Are Processed ​

  1. Parse: Read the ensure statements
  2. Bind: Resolve implicit subjects
  3. Expand: Add implied prerequisites
  4. Order: Topologically sort by dependencies
  5. Execute: Check and repair in order
  6. Loop: Continuously monitor for drift

Released under the MIT License.