API Reference
Overview
This documentation describes the functionality that is available for configuration authors.
Please see the main sections
- Bootstrap schema: Documentation describing the bootstrap schema.
- Workflow schema: Documentation describing the workflow schema.
- Workflow Javascript Contexts: Documentation describing the javascript functionality for workflow execution.
- Testing schema: Documentation describing the testing schema.
- Error Codes: Documentation for all known opscotch error codes.
opscotch configuration model
The opscotch model is relatively straight forward, and uses repeated patterns - once you grasp these you should be able to understand the entire structure.
Here is the outline of the entire structure of the two configurations: the bootstrap and the workflow. Note that not every field is required, so be sure to check the detailed descriptions.
The bootstrap schema overview
[
{
"enabled" : true,
"agentPrivateKey": "",
"deploymentId": "",
"remoteConfiguration": "",
"remoteConfigurationAuth": "",
"remoteConfigurationTimeout" : 0,
"frequency": 0,
"reloadTimeout" : 0,
"keys" : [
{
"id" : "",
"keyHex" : "",
"metadata" :
"purpose" : "",
"type" : ""
}
],
"licenseHost" : "",
"licensePoolId" : "",
"packaging" : {
"additionalSigners" : [],
"packageId" : "",
"packagerIdentities" : [],
"requiredAdditionalSignerCount" : 0,
"requiredSigners" : [
{
"id" : "",
"description" : ""
}
]
},
"errorHandling": {
"enableLocalLogging": true,
"metrics": {
"enabled": true,
"routingToken": "",
"outputUrl": "",
"outputAuthorization": ""
},
"logs": {
"enabled": true,
"routingToken": "",
"outputUrl": "",
"outputAuthorization": ""
},
"redactionPatterns": [
""
]
},
"workflow" : {
"metricOutput": {
"enabled": true,
"routingToken": "",
"outputUrl": "",
"outputAuthorization": ""
},
"outputs": [
{
"id": "",
"routingToken": "",
"type": "",
"outputUrl": "",
"typeProperties": {
"": {
"": ""
}
}
}
],
"errorHandling": {
"enableLocalLogging": true,
"metrics": {
"enabled": true,
"routingToken": "",
"outputUrl": "",
"outputAuthorization": ""
},
"logs": {
"enabled": true,
"routingToken": "",
"outputUrl": "",
"outputAuthorization": ""
}
}
},
"allowDeploymentAccess" : [
{
"id" : "",
"deploymentId" : "",
"access" : "",
"anyDeployment" : false
}
],
"allowExternalHostAccess": [
{
"authenticationHost" : true,
"id" : "",
"host": "",
"httpTimeout" : 0,
"transport": "",
"inProcServerId": "",
"inProcDeploymentId": "",
"headers": {
"": ""
},
"allowList" : [
{
"method" : "",
"uriPattern" : ""
}
],
"data" : {}
}
],
"allowFileAccess": [
{
"id" : "",
"directoryOrFile" : "",
"patterns" : [""],
"LIST" : true,
"READ" : true,
"WRITE" : true,
"DELETE" : true
}
],
"allowHttpServerAccess": [
{
"id" : "",
"port" : 0,
"tcp" : false,
"inProcOnly" : false,
"serveFromPackagedAsset" : {
"packagedAssetFileId": ""
}
}
],
"persistenceRoot" : "",
"data": {},
"agentControl" : {
"workflowCanShutdownAgent": true
}
}
]
The workflow schema overview
{
"workflows": [
{
"enabled": true,
"name": "",
"steps": [
{
"enabled": true,
"debug": true,
"type": "",
"stepId": "",
"trigger" : {
"deploymentAccess" : {
"ids" : [ "" ],
"noTrace" : false
},
"fileWatcher": {
"bootstrapFileId": "",
"eventSplitter": "",
"patterns": [ "" ],
"splitAtEnd": false
},
"tcp": {
"server" : "",
"delimiter" : "",
"stripDelimiter" : true
},
"http": {
"method": "",
"path": "",
"server" : ""
},
"timer" : {
"delay" : 0,
"period" : 0
},
"runOnce" : true
},
"authenticationProcessor": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"splitGenerator": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"urlGenerator": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"payloadGenerator": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"itemResultProcessor": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"resultsProcessor": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"httpStatusHandling": {
"" : {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
}
},
"httpConnectFailedProcessor": {
"script": "",
"resource": "",
"processors" : [
{
"script": "",
"resource": ""
"data": {}
}
],
"data": {}
},
"httpTimeout" : 0,
"singleThreaded" : "",
"persistenceFile" : "",
"data": {}
}
],
"data" : {},
"defaultStepProperties" : {
< ... any step properties ... >
}
}
],
"defaultStepProperties" : {
< ... any step properties ... >
}
}
Bootstrap schema
JSON Schema in the Bootstrap model:
AgentControl
Controls behaviour that allows workflows to influence the agent lifecycle.
JSON Properties
The following properties are available to set on the AgentControl JSON schema.
workflowCanShutdownAgent
Allow workflows to request that the agent shuts down.
Defaults to false
{
"workflowCanShutdownAgent": true
}
Bootstrap
A configuration that is loaded into the agent at startup and determines how the agent loads the main configuration is loaded.
Please note that the bootstap file that is authored is an ARRAY of these objects ie:
[
{
"agentPrivateKey": ...
"deploymentId": ...
}
]
It will be provided to the agent as an argument, either via a base64 encoded json text or a path to a json file
JSON Properties
The following properties are available to set on the Bootstrap JSON schema.
agentControl
Controls what workflows are permitted to do to the running agent.
{
"agentControl": {
"workflowCanShutdownAgent": true
}
}
agentPrivateKey
Required The private key for the agent to decrypt the remote configuration.
This should be a base64 encoded private key in pkcs8 format
This is how to create an appropriate key
1. Create key pair
openssl genrsa -out keypair.pem 2048
2. Extract public part
openssl rsa -in keypair.pem -pubout -out public.key
3. Extract private part
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out private.key
4. Base64 the contents of this file
cat private.key | base64 -w0
{
"agentPrivateKey": "LS0tLS1CRUdJTiBQUklWQV...."
}
allowDeploymentAccess
A list of Deployment Access Permitters that describe cross-deployment access within the same agent.
{
"allowDeploymentAccess": [
{
"id" : "appBridge",
"deploymentId" : "remote-deployment",
"access" : "call"
},
{
"id" : "receiveAny",
"access" : "receive",
"anyDeployment" : true
}
]
}
References:
- (Blog)
allowExternalHostAccess
A list of Host objects that describes access to external http(s) services that can be called from the workflow configuration.
{
"allowExternalHostAccess": [
{
"id" : "myHost",
"host": "https://www.example.com",
"headers": {
"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json, text/plain, *\/*"
},
"allowList" : [
{ "method" : "GET", "uriPattern" : "/this/is/allowed.*"},
{ "method" : "POST", "uriPattern" : "/this/.*\/allowed"}
],
"data" : {
}
}
}
]
References:
allowFileAccess
A list of File Permitters that describe access to files and directories.
When a directory is specified the permissions apply to all files in that directory.
Available permissions are:
- LIST
- READ
- WRITE
- DELETE
{
"allowFileAccess": [
{
"id" : "myTxtFiles",
"directoryOrFile" : "/path/to/a/directory",
"pattern" : ".*\\.txt",
"READ" : true
}
]
}
allowHttpServerAccess
data
A JSON Object for adding properties.
These properties will be merged with the WorkflowConfiguration.data configuration field and be available to all child elements in the main configuration tree.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3]
}
}
deferLoading
When set to true, step executors are initialized lazily to reduce startup time for large configurations.
At startup, only trigger wiring is performed. The rest of step setup is deferred until first execution.
Defaults to false
{
"deferLoading" : true
}
References:
- (Blog)
deploymentId
Required A Service Provider defined value that must be unique per deployed agent configuration.
This property is used by Service Provider downstream processor to enrich the transmitted data.
{
"deploymentId": "a7d2f8"
}
enabled
Disable is bootstrap by setting enabled : false
Defaults to true
{
"enabled": false
}
errorHandling
Determines the behavior of error handling while loading the main configuration
{
"errorHandling": {
...
}
}
frequency
Sets how often the agent checks for configuration updates in milliseconds.
For URL Bootstrap.remoteConfiguration, this is the HTTP polling period. For file Bootstrap.remoteConfiguration, this controls whether the file watch/update mechanism is enabled.
Setting frequency to 0 disables all configuration updating after startup.
In this mode the configuration is loaded once at startup and no HTTP polling or file watching is started.
Defaults to 60000 (60 seconds)
{
"remoteConfiguration": "http://www.example.com",
"remoteConfigurationAuth" : "xodsjfujrhdjfk",
"frequency" : 60000
}
References:
- (Blog)
keys
Optional List of keys made available to the agent.
The set of keys will be made available to the agent for cryptographic functions like encryption and signing.
The keys can be used by the packaging subsystem and can also be made available in workflows via the crypto context
{
"keys": [
{
"id" : "mySignKey",
"type" : "secret",
"purpose" : "sign",
"keyHex" : "DEADBEEF"
}
]
}
licensing
Define licensing options
{
"licenseHost" : "https://your.opscotch.license.app",
"licenseHostPoolId" : "anotherPool"
}
packaging
Used to declare the required packaging authenticity before deploying the package.
{
"packaging": {
"packageId" : "thePackage"
}
}
persistenceRoot
Defines the filesystem storage root for persistence
{
"persistenceRoot": "/storage"
}
reloadTimeout
Defines the maximum time in milliseconds to wait for a workflow to terminate running flows before loading a new version
Defaults to 10000 (10 seconds)
{
"reloadTimeout": 1000
}
remoteConfiguration
Required A URL or file path to the main configuration.
The main configuration does not exist, the agent will wait until it becomes available. When referencing a file, its important to remember that the path is relative to the opscotch working directory, NOT the bootstrap file
{
"remoteConfiguration": "http://www.example.com",
"remoteConfigurationAuth" : "xodsjfujrhdjfk",
"frequency" : 60000
}
remoteConfigurationAuth
When using a URL remoteConfiguration, setting this property will set the "Authorization" header
{
"remoteConfiguration": "http://www.example.com",
"remoteConfigurationAuth" : "xodsjfujrhdjfk",
"frequency" : 60000
}
remoteConfigurationTimeout
When using a URL remoteConfiguration, setting this property will set the http timeout period in milliseconds
When frequency > 0, remoteConfigurationTimeout must be less than frequency.
Defaults to 1000 (1 second)
{
"remoteConfiguration": "http://www.example.com",
"remoteConfigurationAuth" : "xodsjfujrhdjfk",
"frequency" : 60000,
"remoteConfigurationTimeout" : 1000
}
startupPriority
Controls startup activation ordering across deployments in the same bootstrap file. Lower numbers activate first.
Defaults to 100
{
"startupPriority" : 1
}
References:
- (Blog)
workflow
Determines metric and log outputs for the workflows
{
"workflow": {
...
}
}
DeploymentAccessPermitter
Defines cross-deployment access within the same agent.
Use access "call" on the caller deployment and "receive" on the receiver deployment.
JSON Properties
The following properties are available to set on the DeploymentAccessPermitter JSON schema.
access
Required Access mode: "call" or "receive".
{
"access": "call"
}
anyDeployment
When access is "receive", allow calls from any deployment.
{
"anyDeployment": true
}
Defaults to false
deploymentId
Required when access is "call". The deploymentId of the remote bootstrap. When access is "receive" and anyDeployment is true, this can be omitted.
{
"deploymentId": "remote-deployment"
}
id
Required A unique string that identifies this deployment access link.
{
"id": "appBridge"
}
startupWaitTimeoutMs
When access is "call", maximum time in milliseconds to wait for the target deployment to finish startup loading when it is still initializing.
Defaults to 1000
ErrorHandling
A configuration defining if and how to send error metrics or log to a remote system
JSON Properties
The following properties are available to set on the ErrorHandling JSON schema.
enableLocalLogging
Enable or disables logging of errors and information to the agent standard out
Defaults to true
{
"enableLocalLogging": true
}
logs
Defines how error logs are sent to a remote system.
Error logs are brief messages from a fault in the agent and are sent to a remote system for attention.
Error log configuration only apply to the process configuration they are defined for. For example the Bootstrap.errorHandling defines error handling while loading configurations, and the WorkflowOutputs.errorHandling defines error handling during the execution of configuration steps.
{
"logs": {
...
}
}
metrics
Defines how error metrics are sent to a remote system.
Error metrics represent a fault in the agent and are sent to a remote system for attention.
Error metric configuration only apply to the process configuration they are defined for. For example the Bootstrap.errorHandling defines error handling while loading configurations, and the WorkflowOutputs.errorHandling defines error handling during the execution of configuration steps.
{
"metrics": {
...
}
}
redactionPatterns
Defines regex patterns to apply redaction to log statements
Log statements from will have these redaction patterns applied before logging.
{
"redactionPatterns": [
"[0-9]+"
]
}
FilePermitter
Describes controlled access to files and directories.
NOTE: The permission constraints are additional to the OS filesystem permissions: setting a file as readable here does not imply that it is readable from the filesystem.
Regular Expressions can be used to further restrict access to specific files.
JSON Properties
The following properties are available to set on the FilePermitter JSON schema.
DELETE
When true files will be deletable.
Defaults to false
{
"DELETE": true
}
directoryOrFile
A path to a directory or file.
The directory or file does not need to exist. If a directory is specified it must end in a / (or the OS file separator)
Directory example:
{
"directoryOrFile": "/path/to/directory/"
}
File example:
{
"directoryOrFile": "/path/to/directory/or/file"
}
id
An id that must be unique to this bootstrap.
Use this id in the workflow step file trigger.
{
"id": "myTextFiles"
}
LIST
When true files will be listable.
Defaults to false
{
"LIST": true
}
patterns
A list of (Java) Regular Expressions that can be used to further restrict access to files in the directory
{
"patterns": [
".*\\.txt$",
".*\\.log$"
]
}
READ
When true files will be readable.
Defaults to false
{
"READ": true
}
required
When true the file or directory must exist otherwise an error is thrown.
Defaults to false
{
"required": true
}
WRITE
When true files will be writable.
Defaults to false
{
"WRITE": true
}
Host
A HTTP(S) host that the agent/app is expected to communicate with. Apps CAN NOT call any host not referenced by a Host record.
JSON Properties
The following properties are available to set on the Host JSON schema.
allowList
A list of allowed paths that may be called on this host.
A list of regex that will be matched to URL path. Matching results will be allowed, non-matching results will be blocked and logged.
{
"allowList": [
{ "method" : "GET", "uriPattern" : "/this/is/allowed"},
{ "method" : "POST", "uriPattern" : "/this/.*\/allowed"}
]
}
authenticationHost
When set to true the host can only be used by an authentication context,
when set to false (default) the host can only be used by a non-authentication context.
{
"authenticationHost": true
}
Defaults to false
data
A JSON Object with Additional properties that will accessible during authentication steps.
You can use environment variables in the form of ${NAME} anywhere in the data structure:
the environment variable will be substituted prior to parsing.
Strings in the data structure (after environment variable substitution) can be encrypted using the opscotch packager. Values will be decrypted at access time.
Encryption is done via the packaging tool and requires the agent public key.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3],
"someencryptedstring" : {
"abc" : "some encrypted value"
}
}
}
headers
A object of HTTP headers to be sent with every call.
{
"headers": {
"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json, text/plain, *\/*"
}
}
host
Required when transport = "http" A URL that is used as the base for constructing URLs to call.
{
"host": "https://www.example.com:8080"
}
httpTimeout
Default http timeout period in milliseconds for steps that call this host.
{
"httpTimeout": 10000
}
id
Required A unique string that identifies this host in other configurations.
{
"id": "myHost"
}
inProcDeploymentId
When transport is inProc, optionally route to a different deploymentId.
{
"inProcDeploymentId": "remote-deployment"
}
References:
- (Blog)
inProcServerId
When transport is inProc, identifies the bootstrap http server to route to internally.
{
"inProcServerId": "myAPI"
}
References:
- (Blog)
transport
HostAllow
Defines allowed http access patterns
JSON Properties
The following properties are available to set on the HostAllow JSON schema.
method
HTTP Method to match on. One of:
- GET
- HEAD
- POST
- PUT
- DELETE
- OPTIONS
- PATCH
{
"method": "GET"
}
uriPattern
Regex pattern to match on the URI.
{
"uriPattern": ".*"
}
HttpServerPermitter
Creates an server bound to the specified port.
Steps for this bootstrap using a http or tcp trigger can bind to this server.
A special feature is being able to serve static content from a zip file - see serveFromPackagedAsset
JSON Properties
The following properties are available to set on the HttpServerPermitter JSON schema.
bindAddress
Bind address for the server.
Defaults to "127.0.0.1", use "0.0.0.0" for all interfaces
{
"bindAddress": "127.0.0.1"
}
id
Required A unique string that identifies this server in other configurations.
{
"id": "myAPI"
}
inProcOnly
When true, this server will not bind to a network port and will only be available for in-process routing.
{
"inProcOnly": true
}
Defaults to false
References:
- (Blog)
port
Required when inProcOnly false. A port on the host that this server will bind to. Normal port binding rules apply.
{
"port": 1234
}
serveFromPackagedAsset
Describes how to serve content from a zip file.
{
"serveFromPackagedAsset": {
...
}
}
tcp
Enables raw TCP triggers on this port when set to true.
Defaults to false
{
"tcp": true
}
References:
- (Blog)
Key
Defines a cryptographic key made available to agent internal cryptographic functions (encryption and signing) and also to workflow/app cryptographic functions.
Keys must have a specified purpose and type that imply the required key length, which is verified before use.
Keys defined in the bootstrap are made available to the workflow context and also to internal agent operations like packaging and security.
Keys can be added to a workflow context, during a workflow context, via the crypto context.registerKey(...).
Once a key is added, it cannot be retrieved or removed, except for keys added during a workflow context are removed when that context ends.
When using keys, they can be selected by id or purpose/type. Keys are only ever used by reference and are never readable in the workflow context.
See the crypto context for more information.
JSON Properties
The following properties are available to set on the Key JSON schema.
id
Required A unique identifier used to reference a specific key
{
"id" : "thisIsMyKey"
}
keyHex
Required The hex encoded key
metadata
Additional metadata used solely for ease of key management in the bootstrap. This metadata is not loaded into the agent.
purpose
Required The intended purpose of the key.
The purpose is used to filter and verify the key properties for the intended usage.
Values can be one of:
sign: used for signing or signing verification- primitive: Ed25519
- secret key length: 64
- public key length: 32
authenticated: used for mutually authenticated encryption- primitive: X25519 (key exchange) + XSalsa20-Poly1305
- secret key length: 32
- public key length: 32
symmetric: used for symmetric encryption- primitive: XSalsa20-Poly1305
- secret key length: 32
anonymous: used for anonymous public key encryption- primitive: X25519 (key exchange) + XSalsa20-Poly1305
- secret key length: 32
- public key length: 32
{
"purpose" : "sign"
}
type
Required public or secret corresponding to the purpose
{
"type" : "secret"
}
Licensing
Define how to obtain a license for the workflow.
Licenses are issued to your organization by an opscotch license vendor.
Organization licenses are installed into an opscotch licensing app which might be separate service or might be running on the same agent as your workflows.
See the opscotch licensing app for more information.
References:
- (Blog)
JSON Properties
The following properties are available to set on the Licensing JSON schema.
basicAuth
Set the licensing basic auth header
{
"basicAuth" : "bm90IHNlY3JldA=="
}
licenseHost
An http(s) host running an opscotch licensing app where licenses can be obtained from.
Defaults to null. When null, remote licensing setup is not configured for the deployment.
{
"licenseHost" : "https://your.opscotch.license.app"
}
licenseHostPoolId
A licensing pool id configured on the opscotch licensing app.
Defaults to "default".
{
"licenseHostPoolId" : "anotherPool"
}
Output
Configuration for how to send data to a remote system.
JSON Properties
The following properties are available to set on the Output JSON schema.
enabled
Enables or disables the sending of data.
Defaults to false
{
"enabled": true
}
id
Optional A unique id used to reference this output from workflows.
{
"id": "my-output"
}
outputAuthorization
Set the "Authorization" header.
{
"outputAuthorization" : "xodsjfujrhdjfk"
}
outputUrl
Required The URL that data is transmitted to.
{
"outputUrl": "http://www.example.com"
}
persistenceRoot
If set, defines the location to store output queue files
{
"persistenceRoot" : "/tmp/output-queues"
}
routingToken
Required A Service Provider defined value that must be unique per deployed agent.
This property is used by Service Provider downstream processor to direct and enrich the transmitted data.
{
"routingToken": "dogurj"
}
type
Optional The output type. When set to otel, an OTEL sender is used.
{
"type": "otel"
}
typeProperties
Optional Type-specific properties. When a type is set, its properties should be stored under a key matching the type name.
{
"type": "otel",
"typeProperties": {
"otel": {
"aProperty": "aValue"
}
}
}
Packaging
Packaging applies required security constraints to package (app) loading.
Packages can be signed by the packaging entity and the signatures can be verified before loading. Signatures can be required or optional, and can have a required number of signatures.
Packages can be encrypted with mutually authenticated encryption meaning that the packager added keys specifically for this deployment, and this deployment has the matching key.
JSON Properties
The following properties are available to set on the Packaging JSON schema.
additionalSigners
Optional Used in conjunction of the requiredAdditionalSignerCount, define a list of additional signers by id that can also sign the package.
The id must match a single key id in keys.
This property is used to provide a pool of additional signers to sign the package.
{
"keys" : [
{
"id" : "trusted-party-1",
"purpose" : "sign",
"type" : "public",
"keyHex" : "..."
},
{
"id" : "trusted-party-1",
"purpose" : "sign",
"type" : "public",
"keyHex" : "..."
}
],
"packaging" : {
"additionalSigners": [
{
"id": "trusted-party-1",
"description" : "A trusted party"
},
{
"id": "trusted-party-2",
"description" : "Another trusted party"
}
]
}
}
packageId
Optional However, if using opscotch packaging app then its required. The packageId must match the packageId in the packaged file.
This property is used to ensure only the packageId specified is laoded.
{
"packageId": "a7d2f8"
}
packagerIdentities
Optional A list of public key ids of packaging identities that proves the authenticity of the package.
The key identified by the id, must be in the keys list.
Note that a package can be encrypted with multiple keys and each decryption key pair must be present in the keys list.
{
"packagerIdentities": [
"trusted-party-1", "trusted-party-2"
]
}
requiredAdditionalSignerCount
Optional Set the number of additional signers required from the additionalSigners list.
This property is used to ensure that the packageId is signed by a minimum number of specified keys.
Defaults to 0
{
requiredAdditionalSignerCount : 2
}
requiredSigners
Optional Define a list of required signers by id. The id must match a single key id in Bootstrap.keys
This property is used to ensure that the package is signed by specified keys
{
"keys" : [
{
"id" : "trusted-party-1",
"purpose" : "sign",
"type" : "public",
"keyHex" : "..."
},
{
"id" : "trusted-party-1",
"purpose" : "sign",
"type" : "public",
"keyHex" : "..."
}
],
"packaging" : {
"requiredSigners": [
{
"id": "trusted-party-1",
"description" : "A trusted party"
},
{
"id": "trusted-party-2",
"description" : "Another trusted party"
}
]
}
}
References:
- (Blog)
ServePackagedAsset
Defines how to serve static files from a packaged asset (zip file)
JSON Properties
The following properties are available to set on the ServePackagedAsset JSON schema.
packagedAssetFileId
Identifies a FilePermitter in the bootstrap to serve from.
THe FilePermitter should be a path to a zip file.
{
"packagedAssetFileId": "myZipFile"
}
WorkflowConfiguration
The configuration that describes the main activities of the agent
JSON Properties
The following properties are available to set on the WorkflowConfiguration JSON schema.
data
A JSON Object for adding properties.
These properties will be merged with the Bootstrap.data configuration field and be available to all child elements.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3]
}
}
defaultStepProperties
Default properties applied to all steps in all workflows.
These properties are merged into each step and can be overridden by the step.
{
"defaultStepProperties": {
"debug": true
}
}
workflows
Required A list of Workflow describing the agent tasks
{
"workflows" [
...
]
}
WorkflowOutputs
Determines the behaviour of error handling and metrics for the workflow
JSON Properties
The following properties are available to set on the WorkflowOutputs JSON schema.
errorHandling
Determines the behavior of error handling while running the main configuration
{
"errorHandling": {
...
}
}
metricOutput
Metrics represent a data point that is interesting, generated by the agent and are sent to a remote system for analysis.
{
"metricOutput": {
...
}
}
outputs
Additional outputs that can be referenced by id from workflows.
{
"outputs": [
{
"id": "my-otel",
"type": "otel",
"routingToken" : "anId",
"outputUrl": "https://collector:4317",
"typeProperties": {
"otel": {
"protocol": "grpc"
}
}
}
]
}
References:
- (Blog)
Workflow schema
JSON Schema in the Workflow model:
DeploymentAccessTrigger
Describes how to bind to a deployment access trigger.
References:
- (Blog)
JSON Properties
The following properties are available to set on the DeploymentAccessTrigger JSON schema.
ids
Identifies the bootstrap deployment access ids to listen to (local to this deployment).
{
"ids": ["appBridge"]
}
noTrace
When true these executions will be omitted from tracing (monitoring)
{
"noTrace" : true
}
FileWatchingTrigger
Defines a trigger that fires when new lines are added to a file.
Each event (split by the lineSplit property) will be sent to the step processor. A sample event:
{
"log": {
"file": {
"path": "/path/to/file.txt"
},
"offset": 4130
},
"message": "this is a line from a file",
"input": {
"type": "log"
},
"host": {
"name": "hostname",
"ip": "[fe80:0:0:0:a6d7:feea:f601:902%wlp1s0, 192.168.0.27]"
},
"agent": {
"type": "opscotch",
"version": "3.0.0"
},
"ecs": {
"version": "1.12"
}
}
JSON Properties
The following properties are available to set on the FileWatchingTrigger JSON schema.
bootstrapFileId
Defines the allowed file access from the bootstrap
This must match an id in a bootstrap.allowFileAccess.id
{
"bootstrapFileId": "myTestFiles"
}
eventSplitter
Defines the (Java) regular expressions used to split events.
The delimiter will be present on the event message. The events that are collected from this trigger will be passed into the step processor as a list. The event has select field from the ECS for base, log, host, agent.
{
"eventSplitter": "\\n"
}
noTrace
When true these executions will be omitted from tracing (monitoring)
{
"noTrace" : true
}
patterns
A list of (Java) regular expressions used for file selection
{
"patterns": [
".+\\.txt$",
".+\\.log$"
]
}
splitAtEnd
When true the delimiter is at the end of the line, when false the delimiter will be at the start of the line.
Defaults to true
{
"splitAtEnd": false
}
HttpRequestTrigger
Describes how to bind to a http request
A sample event:
{
"uri": "/api/users/123",
"method": "POST",
"path": "/api/users/123",
"query": "foo=bar",
"body": "{\"name\": \"test\"}",
"headers": {
"Content-Type": ["application/json"],
"Authorization": ["Bearer token123"]
}
}
JSON Properties
The following properties are available to set on the HttpRequestTrigger JSON schema.
method
The HTTP method to listen for.
Defaults to GET
{
"method": "POST"
}
multiPartUploadByteLimit
Limits multipart uploads to this number of bytes This must be set to enable multi-part uploads.
{
"multiPartUploadByteLimit" : 100000
}
NOTE: setting this enables multipart uploads for this endpoint
noTrace
When true these executions will be omitted from tracing (monitoring)
{
"noTrace" : true
}
path
A regular expression that matches against the URI path
{
"path": "/api/.*"
}
server
Identifies the bootstrap http server to listen to
{
"server": "myAPI"
}
JavaScriptSource
A JavaScript that is executed during the processing of a Step
JSON Properties
The following properties are available to set on the JavaScriptSource JSON schema.
data
A JSON Object for adding properties.
Used to pass parameters and data to the script.
These properties will be merged with all other data fields in the json path, available to the step script elements.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3],
}
}
resource
A file path to the script to execute.
Must be supplied if JavaScriptSource.script is not supplied
{
"resource": "scripts/myscript.js"
}
script
The script to execute.
A json-escaped script. Must be supplied if JavaScriptSource.resource is not supplied
{
"script": "console.log(\\"hello world\\");"
}
JavascriptProcessor
JSON Properties
The following properties are available to set on the JavascriptProcessor JSON schema.
processors
A list of JavaScriptSource that will be executed in order
{
"processors" : [
{
"resource" : "..."
},
{
"resource" : "..."
}
]
}
Persistence
Defines a cache/memory/key-value store that the Step has access to.
Required if using various functions. If required and not defined an error will be logged
This is currently a BETA feature and is unsupported.
JSON Properties
The following properties are available to set on the Persistence JSON schema.
hexSymmetricKey
obfuscate
persistenceFile
saveRatio
PersistentQueueParams
This is currently a BETA feature and is unsupported.
JSON Properties
The following properties are available to set on the PersistentQueueParams JSON schema.
maxFileBytes
HARD CODED TO 5MB
maxMemoryBytes
HARD CODED TO 1MB (1024 * 1024)
queuefilePrefix
HARD CODED TO persistenceFile + "-queue-" + deploymentId + "-" + stepId
Step
The Step is the primary configuration item for the agent configuration.
This configuration describes how to perform a single step or action in a Workflow.
There are different types of steps, however they all have the same execution structure:
- Prepare
- Execute
- Process
Steps take three forms of input:
- The response from a call to a Host (
context.getMessageBodyAsString()) - The message passed from another Step (
context.getPassedMessageAsString()) - Data from the configuration (
context.getData())
The different types of Steps allow for specialised behaviour:
-
"scripted" type: this is the default type with the following flow:
-
Optionally generate a URL (urlGenerator)
-
Optionally (requires a url to have been set) generate a payload (payloadGenerator)
-
Optionally perform authentication steps (authenticationProcessor, call other steps to perform authentication)
-
Optionally call out to a named Bootstrap Host with the generated URL and payload
-
Optionally handle specific HTTP status codes with httpStatusHandling
OR
-
Process the response or perform after-call processing (resultsProcessor)
Perhaps:
- Send a message to another Step
- Produce some metrics
-
-
"scripted-split-aggregate" type: this is a modified "scripted" type that has the following workflow of:
-
transforming the input into a list (splitGenerator)
-
calling a URL with each item in the list:
-
Optionally generate a URL (urlGenerator)
-
Optionally (requires a URL to have been set) generate a payload (payloadGenerator)
-
Optionally perform authentication steps (authenticationProcessor, call other steps to perform authentication)
-
Optionally call out to a named Bootstrap Host with the generated URL and payload
-
Optionally handle specific HTTP status codes with httpStatusHandling
OR
-
Optionally Process each item's response (itemResultProcessor)
-
Collect the result into a response list
-
-
The list of collected responses can then be processed and per normal (resultsProcessor)
Perhaps:
- Send a message to another Step
- Produce some metrics
Please note that in the case that one of the HTTP requests fail, it is your responsibility to handle this case by using the
httpStatusHandling,itemResultProcessor, andresultsProcessor
-
-
"scripted-auth" type: this is identical to "scripted" except that it has an alternative javascript context - it is not allowed to send metrics or call to non-authentication steps, but has access to the bootstrap data which may contain secrets.
-
"httpFile" type: this is a specialized step that serve static content from a zip file by mapping a url path into a zip file path. This type REQUIRES a
httptrigger to be defined, an only allowsGETrequests
At least one step in a Workflow will define a Step.trigger that will trigger the start of Workflow processing.
These forms of input and different type allows for the construction of flexible pipelines that should be sufficient to perform most tasks.
JSON Properties
The following properties are available to set on the Step JSON schema.
authenticationProcessor
This processor runs directly before an http call. It is not valid to have an authenticationProcessor without an urlGenerator.
This processor is expected to modify the context, generally by calling authentication steps and/or applying headers.
{
"authenticationProcessor": {
...
}
}
DEFAULT_HTTP_TIMEOUT
data
A JSON Object for adding properties.
Used to pass parameters and data to the JavaScriptSource elements.
These properties will be merged with all other data fields in the json path, available to the step JavaScriptSource elements.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3],
}
}
debug
Enables or disables the debug logs for this step. Defaults to false.
{
"debug": true
}
enabled
Enables or disables the execution of this step. Defaults to true.
{
"enabled": true
}
httpConnectFailedProcessor
Defines how to handle HTTP connection failures using a standard processor
{
"httpConnectFailedProcessor": {
...
}
}
httpStatusHandling
A set of JavascriptProcessor to process depending on the http status.
The key is the HTTP status either as a discrete number ie "401" or a range "400-499" and the value is a (standard processor)(#JavascriptProcessor).
When a status code matches a status handler and the handler is executed the resultProcessor or itemProcessor
will not be executed.
Note: When supplying ANY httpStatusHandling you will also need explicitly declare success codes ie 200 as the resultsProcessor will not be called
{
"httpStatusHandling": {
"301-302" : {
...
},
"401" : {
...
}
}
}
httpTimeout
Set the http timeout period in milliseconds
Set to 0 to disable the read timeout and wait indefinitely for response data.
Defaults to 10000 (10 seconds)
{
"httpTimeout" : 10000
}
itemResultProcessor
When using Step.type "scripted-split-aggregate", defines if and how to process items before they're added to the list.
{
"itemResultProcessor": {
...
}
}
payloadGenerator
Defines how to generate the call payload, including setting headers.
This requires the urlGenerator to be present and will throw a validation exception.
If this processor is not used, then the HTTP body will be removed.
{
"payloadGenerator": {
...
}
}
persistenceFile
Defines a cache/memory/key-value store that the Step has access to.
Required if using various functions. If required and not defined an error will be logged
{
"persistenceFile": "persistenceFile.data"
}
resultsProcessor
Required Defines how to process the result of the call to the host. Note: You might setup result processing via the httpStatusHandling property - you will still need to define a resultsProcessor though, even if it is an empty string.
{
"resultsProcessor": {
...
}
}
singleThreaded
Determines the behaviour when the step is called while it's still executing.
Options are:
- "none" - step is not single threaded and can be run simultaneously (default)
- "return" - step is single threaded: if the step is already running, any calls to start the step will return immediately without running
Future options are likely : queue - execution will wait for the running execution to complete
splitGenerator
When using Step.type "scripted-split-aggregate", defines how to generate the list to be operated on.
{
"splitGenerator": {
...
}
}
stepId
Required Sets the id of the step.
Must be unique.
{
"stepId": "the-first-step-in-my-route"
}
trigger
Defines how a workflow is started.
{
"trigger": {
...
}
}
type
Sets the type of the step.
Either "scripted", "scripted-split-aggregate", "scripted-auth" as "httpFile" as defined above.
Defaults to "scripted"
{
"type": "scripted-split-aggregate"
}
urlGenerator
Required Defines how to generate the URL
This processor should not attempt to set the payload (the current internal logic may result in unexpected results). To set the payload, use the payloadGenerator
{
"urlGenerator": {
...
}
}
TcpTrigger
Describes how to bind to a TCP socket
References:
- (Blog)
JSON Properties
The following properties are available to set on the TcpTrigger JSON schema.
batchSize
Configures the number of frames to batch before triggering the workflow. The payload passed to the workflow will be a JSON array string containing each frame as a UTF-8 string.
Defaults to 1
{
"batchSize": 10
}
delimiter
Configures delimiter based framing, emitting a message each time the delimiter is encountered.
{
"delimiter": "\\n"
}
fixedLength
Configures fixed length framing, emitting a message every time the configured number of bytes are read.
{
"fixedLength": 1024
}
maxBatchWindowMillis
Configures the maximum time to wait (in milliseconds) before flushing a batch. When set, the batch will be emitted at most after this window, even if batchSize is not reached.
Defaults to 0 (disabled)
{
"maxBatchWindowMillis": 250
}
noTrace
When true these executions will be omitted from tracing (monitoring)
server
Identifies the bootstrap http server to listen to
{
"server": "myTCP"
}
stripDelimiter
When true the configured delimiter will be removed from the emitted payload.
Defaults to true
{
"stripDelimiter": false
}
Timer
Defines a repeating, fixed-rate period trigger
JSON Properties
The following properties are available to set on the Timer JSON schema.
delay
Defines a delay in milliseconds before the first invocation.
Defaults to 0.
{
"delay": 60000
}
noTrace
When true these executions will be omitted from tracing (monitoring)
{
"noTrace" : true
}
period
Defines a delay in milliseconds between invocations.
Defaults to 1000.
{
"period": 60000
}
Trigger
Defines the starting condition for a workflow
JSON Properties
The following properties are available to set on the Trigger JSON schema.
deploymentAccess
Defines a trigger that fires when a deployment access request is received.
{
"deploymentAccess": {
...
}
}
fileWatcher
Defines a trigger that fires when new lines are added to a file.
{
"fileWatcher": {
...
}
}
http
Defines a trigger that fires when a matching http request is received.
{
"http": {
...
}
}
runOnce
Sets trigger to run only once.
Defaults to false
{
"runOnce": true
}
runOnceNoTrace
When true these executions will be omitted from tracing (monitoring)
{
"runOnceNoTrace" : true
}
tcp
Defines a trigger that fires when data is received on a TCP socket.
{
"tcp": {
...
}
}
timer
Defines a repeating period trigger
{
"timer": {
...
}
}
Workflow
Defines a set of Steps that the agent will perform in order to generate metrics
JSON Properties
The following properties are available to set on the Workflow JSON schema.
data
A JSON Object for adding properties.
Used to pass parameters and data to the JavaScriptSource elements.
These properties will be merged with all other data fields in the json path, available to the step JavaScriptSource elements.
{
"data": {
"somedata" : {
"abc: 123
},
"someotherdata" : [ 1, 2, 3],
}
}
defaultStepProperties
Default properties applied to all steps in this workflow.
These properties are merged into each step and can be overridden by the step.
{
"defaultStepProperties": {
"debug": true
}
}
enabled
Enable or disables the loading of the workflow.
Defaults to true
{
"enabled": false
}
name
Required The user friendly name of the workflow.
{
"name": "my workflow"
}
steps
Workflow scripting contexts
Scripting context objects in the Workflow modek:
- AgentControlContext
- AuthenticationJavascriptContext
- ByteBufferHandle
- ByteContext
- ByteReader
- CryptoContext
- DiagnosticsContext
- Doc
- FilesContext
- JavascriptContext
- JavascriptStateContext
- LicensingContext
- PersistentQueueContext
- TimestampManager
AgentControlContext
Allows workflows to request lifecycle actions on the running agent.
This is currently in beta and not supported
Methods
The following methods are available to call on the context.agentControl() object.
shutdownAgent
shutdownAgent()
Request that the agent begins shutting down.
Workflows must enable bootstrap.agentControl.workflowCanShutdownAgent or this will throw an error.
AuthenticationJavascriptContext
This is a specialised Javascript Context for authentication steps.
Most of the methods on Javascript Context are still available, the methods listed below are specialisations.
sendMetric and
Methods
- addSplitReturnItem
- addSystemError
- addUserError
- bytes
- counter
- crypto
- delta
- diagnosticLog
- end
- getAllErrors
- getAuthenticationPropertiesFromStep
- getBody
- getData
- getFirstError
- getHeader
- getMessageBodyAsString
- getPassedMessageAsString
- getPersistedItem
- getProperty
- getRestrictedDataFromHost
- getStepProperties
- getSystemErrors
- getTimestamp
- getTimestampManager
- getUserErrors
- hasSystemErrors
- hasUserErrors
- hash
- isErrored
- jsonPath
- licensing
- mergeJsonStrings
- queue
- regexMatch
- removeAllHeaders
- removeHeader
- sendToStep
- sendToStepAndForget
- setAuthenticationPropertiesOnStep
- setBody
- setCounter
- setData
- setHeader
- setHttpMethod
- setMessage
- setPersistedItem
- setProperty
- setUrl
- sleep
- xmlToJson
addSplitReturnItem
addSplitReturnItem(String item)
When the current step is a "scripted-split-aggregate" type (see Step) the processed item must be added to the returned aggregate using this method.
context.addSplitReturnItem("hello world");
addSystemError
addSystemError(String error)
Adds an error not intended for a user outside the agent. It will also mark the context as in an error state.
System errors would generally be thrown or handled.
addUserError
addUserError(String error)
Adds an error intended for a user outside the agent. It will also mark the context as in an error state.
User errors would generally make their way to a human.
bytes
bytes() : ByteContext
Obtain a Byte context for working with bytes
counter
counter(String name, Double add) : Double
Atomically add to (or subtract from) a thread safe atomic counter and return the updated value
To just get the value pass 0 for the add parameter add
var value = context.counter("myCounter", 0); // just get the value
var added = context.counter("myCounter", 10); // 10 is added and the final value returned
var subtracted = context.counter("myCounter", -10); // 10 is subtracted and the final value returned
crypto
crypto() : CryptoContext
Obtain a Cryptography context for working with cryptography
delta
delta(String key, Double currentValue) : Double
Returns the differences between the current value and the last value stored for given key
delta = context.delta("myTs", 12);
diagnosticLog
diagnosticLog(String message)
Write a diagnostic log. This will only be emitted in development mode, or in Production mode if the step is enabled via a "enableDiagnostics" message
context.diagnosticLog("Hello World");
end
end()
Terminates the running flow and returns immediately.
context.end();
getAllErrors
getAllErrors() : List of java.lang.String
Retrieves a list of all error messages associated with the current context.
getAuthenticationPropertiesFromStep
getAuthenticationPropertiesFromStep(String stepId, String key) : String
ACCESSES RESTRICTED DATA
Gets the authentication properties from another step. These properties can expire.
getBody
getBody() : String
A shorthand for: check getMessageBodyAsString()then check getPassedMessageAsString()
body = context.getBody();
@return the contents eiter passed into the step or set by the step.
getData
(2 variants)
getData() : String
data = JSON.parse(context.getData());
getData(String key) : String
data = context.getData(key);
getFirstError
getFirstError(List of java.lang.String errors) : String
Retrieves the first error message from a given list of errors, if available.
getHeader
getHeader(String name) : String
Get a header from the previous request/response - note: it always returns an array string
headerArray = context.getHeader("aHeader");
header = JSON.parse(headerArray)[0];
getMessageBodyAsString
getMessageBodyAsString() : String
Get the current message body, this could be the response from an http call for example
body = context.getMessageBodyAsString();
getPassedMessageAsString
getPassedMessageAsString() : String
Get the message body that was passed to this step.
passedMessage = context.getPassedMessageAsString();
getPersistedItem
getPersistedItem(String key) : String
Gets an item from the step persistence
item = context.getPersistedItem("myItem");
getProperty
getProperty(String key) : Object
Gets a property from this running context
property = context.getProperty("aKey");
getRestrictedDataFromHost
getRestrictedDataFromHost(String host) : String
ACCESSES RESTRICTED DATA
Gets the json string of restricted data for a host name
hostData = JSON.parse(context.getRestrictedDataFromHost("myhost"));
getStepProperties
getStepProperties() : Object of java.lang.Object
Returns the set properties for the Step. These properties will persist after requests but not over config reloads/restarts
property = context.getStepProperties().put("myProperty", "ok");
getSystemErrors
getSystemErrors() : List of java.lang.String
Retrieves a list of system-specific error messages associated with the current context.
getTimestamp
getTimestamp() : Integer
Get the current UTC timestamp (note that the timestamp might be set by a test or other mechanism) in milliseconds since 1970-01-01T00:00:00Z (UTC)
ts = context.getTimestamp();
date = new Date(context.getTimestamp())
getTimestampManager
getTimestampManager() : TimestampManager
The timestamp manager allows for persistence of timestamps
tm = context.getTimestampManager();
getUserErrors
getUserErrors() : List of java.lang.String
Retrieves a list of user-specific error messages associated with the current context.
hasSystemErrors
hasSystemErrors() : Boolean
Checks if there are any system-specific errors in the current context.
hasUserErrors
hasUserErrors() : Boolean
Checks if there are any user-specific errors in the current context.
hash
hash(String toHash) : String
Note: This is a non-cryptographic hash and is intended to be used for obfuscation.
When hashing a value, the original and the hash are emitted to the log to be referred to at a later date. The hash can be used in metrics etc so that the original value is not transmitted.
The intention is that the raw value can remain in the originating network and the hash value can be transmitted out of network.
hashedValue = context.hash("hello world");
isErrored
isErrored() : Boolean
Indicates whether the current context is in an errored state.
jsonPath
jsonPath(String json, String expression) : String
Returns the result from a JSONPath expression
licensing
licensing() : LicensingContext
Obtain licensing information.
This is currently a BETA feature and is unsupported.
mergeJsonStrings
mergeJsonStrings(String one, String two) : String
Returns a merged json string
queue
queue() : PersistentQueueContext
Returns the high performance persistent queue
regexMatch
regexMatch(String regex, String input) : List of java.lang.String
Returns the regex matches
removeAllHeaders
removeAllHeaders()
Remove all headers from the current state
context.removeAllHeaders();
removeHeader
removeHeader(String name)
Remove a header from the current state
context.removeHeader("aHeader");
sendToStep
(3 variants)
sendToStep(String stepName, String body) : JavascriptStateContext
Send a message to another step and return a completed context upon completion
var completedContext = context.sendToStep("myStep", "theBody");
sendToStep()
Send a message to another deployment step and return a completed context upon completion.
var completedContext = context.sendToStep("appBridge", "myStep", "theBody");
References:
-
(Blog)
sendToStep()
Send a message to another deployment step with headers (key pair available from context.getHeader(...)) and return a completed context upon completion.
var completedContext = context.sendToStep("appBridge", "myStep", "theBody", { "header1" : "abc"});
References:
-
(Blog)
sendToStepAndForget
(4 variants)
sendToStepAndForget(String stepName, String body)
Send a message to another step and returns immediately. The step called will be processed in another thread, and you will not be able to access to the result.
context.sendToStep("myStep", "theBody");
sendToStepAndForget()
Send a message to another deployment step and returns immediately.
context.sendToStepAndForget("appBridge", "myStep", "theBody");
References:
-
(Blog)
sendToStepAndForget(String stepName, String body, Object of java.lang.String headers)
Send a message to another step with headers (key pair available from context.getHeader(...) and returns immediately.
The step called will be processed in another thread, and you will not be able to access to the result.
context.sendToStep("myStep", "theBody", { "header1" : "abc"});
sendToStepAndForget()
Send a message to another deployment step with headers (key pair available from context.getHeader(...)) and returns immediately.
The step called will be processed in another thread, and you will not be able to access to the result.
context.sendToStepAndForget("appBridge", "myStep", "theBody", { "header1" : "abc"});
References:
-
(Blog)
setAuthenticationPropertiesOnStep
setAuthenticationPropertiesOnStep(String stepName, Long expiresInMs, String key, String authenticationProperties)
ACCESSES RESTRICTED DATA
Sets the authentication properties from another step. These properties can expire.
setBody
setBody(Object body)
An alias for setMessage(...)
context.setBody("hello");
setCounter
setCounter(String name, Double value)
Atomically set the counter to an absolute value
setData
setData(String data)
Set the JSON data for this step
context.setData(JSON.stringify(data));
setHeader
setHeader(String name, Object value)
Add a header to the next http request
context.setHeader("aHeader", "aValue");
setHttpMethod
setHttpMethod(String method)
Set the HTTP method for the next http action
This is generally used when a method other than the default is required.
The HTTP method will default to GET unless there is a payload body then it will default to POST
context.setHttpMethod("POST");
setMessage
setMessage(Object message)
Sets the message body for this running exchange
context.setMessage("hello world");
setPersistedItem
setPersistedItem(String key, String value)
Sets an item to the step persistence
context.setPersistedItem("myItem", "theValue");
setProperty
setProperty(String key, Object value)
Sets a property onto this running context to be available in downstream step execution
This differs from setPersistedItem in that setPersistedItem sets onto the STEP to be available on THIS STEP
in future runs, while setProperty makes an item available to OTHER steps
context.setProperty("aKey", "aValue");
setUrl
setUrl(String hostref, String path)
Set the url for the next http action with reference to a named host
The path can start with a / even if the named host ends in a / - the result will be a single '/'
context.setUrl("myHost", "/a/path");
sleep
sleep(Integer ms)
Force the currently running script to sleep for the given milliseconds
context.sleep(100);
xmlToJson
xmlToJson(String xml) : String
Returns a json string from an xml string
ByteBufferHandle
The ByteBufferHandle is a convenience "label" to make it clear that you're dealing with an internal byte buffer.
When you see a method taking or returning a ByteBufferHandle you know that you are dealing with a byte buffer.
See byte context
ByteContext
A low-level byte buffer manipulation interface providing minimal primitives for binary data operations.
Most operations either take or return a ByteBufferHandle. The byte buffer handle is a reference to a byte buffer in the agent - you will never interact with the buffer itself, rather you delegate the functionality to the agent.
The ByteContext offers the following categories of functionality:
- conversion to and from text encoded bytes (base64, hex)
- creating new byte arrays (create, createFromByteArray, createFromString)
- byte array manipulation (concat, copy, getSize, resize, slice, release)
- byte compression (gzip, gunzip, zip, unzip)
- writing to byte buffer (writeByte, writeBytes)
- reading from byte buffer (readByte, reader.available, reader.read, reader.readAll)
All high-level operations (multi-byte integers, strings, etc.) should be implemented in JavaScript using these primitives.
References:
Methods
The following methods are available to call on the context.bytes() object.
- base64ToBinary
- binaryToBase64
- binaryToHex
- concat
- copy
- create
- createFromByteArray
- createFromString
- getSize
- gunzip
- gzip
- hash
- hexToBinary
- readByte
- reader
- release
- resize
- sha256
- slice
- split
- toString
- unzip
- writeByte
- writeBytes
- zip
base64ToBinary
base64ToBinary(String base64) : ByteBufferHandle
Converts a Base64 encoded String into a binary buffer.
let buffer = byteContext.base64ToBinary("aGVsbG8="); // "Hello"
binaryToBase64
binaryToBase64(ByteBufferHandle buffer) : String
Converts buffer contents to a Base64 encoded string.
let buffer = byteContext.createFrom([72, 101, 108, 108, 111]); // "Hello"
let b64 = byteContext.binaryToBase64(buffer);
console.log(b64); // "aGVsbG8="
binaryToHex
binaryToHex(ByteBufferHandle buffer) : String
Converts buffer contents to a hexadecimal string representation.
let buffer = byteContext.createFrom([72, 101, 108, 108, 111]); // "Hello"
let hex = byteContext.binaryToHex(buffer);
console.log(hex); // "48656C6C6F"
concat
concat(ByteBufferHandle[] buffers) : ByteBufferHandle
Combines two buffers into a new buffer containing all bytes from both.
let header = byteContext.createFrom([0xFF, 0xFE]); // Magic bytes
let data = byteContext.createFrom([1, 2, 3, 4]); // Payload
let packet = byteContext.concat([header, data]);
// packet contains: [0xFF, 0xFE, 1, 2, 3, 4]
copy
copy(ByteBufferHandle sourceBuffer) : ByteBufferHandle
Creates a deep copy of an existing buffer.
let original = byteContext.create(10);
let copy = byteContext.copy(original);
// Modifying copy won't affect original
copy = byteContext.writeByte(copy, 0, 255);
console.log(byteContext.readByte(original, 0)); // 0 (unchanged)
create
create(Integer size) : ByteBufferHandle
Creates a new buffer of the specified size, initialized with zeros.
let buffer = byteContext.create(1024); // 1KB buffer of zeros
console.log(byteContext.getSize(buffer)); // 1024
createFromByteArray
createFromByteArray(byte[] bytes) : ByteBufferHandle
Creates a new buffer from a byte array.
// Create from existing data
let bytes = [0x48, 0x65, 0x6C, 0x6C, 0x6F]; // "Hello" in ASCII
let buffer = byteContext.createFrom(bytes);
console.log(byteContext.getSize(buffer)); // 5
createFromString
createFromString(String string) : ByteBufferHandle
Creates a new buffer from a string.
// Create buffer from UTF-8 string
let text = "Hello, 世界!"; // Unicode text
let buffer = byteContext.createFrom(text);
getSize
getSize(ByteBufferHandle buffer) : Integer
Returns the current size of a buffer in bytes.
let buffer = byteContext.create(42);
console.log(byteContext.getSize(buffer)); // 42
gunzip
gunzip(ByteBufferHandle buffer) : ByteBufferHandle
Decompresses GZIP-compressed buffer contents.
let compressed = byteContext.gzip(originalBuffer);
let decompressed = byteContext.gunzip(compressed);
gzip
gzip(ByteBufferHandle buffer) : ByteBufferHandle
Compresses buffer contents using GZIP compression.
let compressed = byteContext.gzip(originalBuffer);
let decompressed = byteContext.gunzip(compressed);
hash
hash(ByteBufferHandle buffer) : Integer
Computes a CRC32 hash of the buffer contents.
let buffer = byteContext.createFrom([1, 2, 3, 4]);
let hash = byteContext.hash(buffer);
console.log(hash); // Unsigned 32-bit CRC value as a number
hexToBinary
hexToBinary(String hex) : ByteBufferHandle
Converts a hexadecimal string to binary buffer data.
let buffer = byteContext.hexToBinary("48656C6C6F"); // "Hello" in hex
readByte
readByte(ByteBufferHandle fromBuffer, Integer offset) : Integer
Reads a single byte from the buffer at the specified offset.
let buffer = byteContext.create(5);
buffer = byteContext.writeByte(buffer, 2, 170); // 0xAA
let value = byteContext.readByte(buffer, 2);
console.log(value); // 170
reader
(2 variants)
reader(ByteBufferHandle buffer) : ByteReader
Creates a sequential reader for efficient forward-only reading of buffer data. This is more efficient than random access for sequential operations.
let reader = byteContext.reader(buffer);
// examples
let byte = reader.readByte();
let int32 = reader.readInt32BE();
let bytes = reader.readBytes(length);
reader() : ByteReader
Reads from the context stream
release
release(ByteBufferHandle[] buffers)
Securely releases (erase) buffers from memory.
resize
resize(ByteBufferHandle buffer, Integer newSize) : ByteBufferHandle
Changes the size of a buffer. If enlarged, new bytes are zero-filled. If shrunk, excess bytes are discarded.
let buffer = byteContext.create(10);
buffer = byteContext.resize(buffer, 20); // Grow to 20 bytes (zeros added)
buffer = byteContext.resize(buffer, 5); // Shrink to 5 bytes
sha256
sha256(ByteBufferHandle buffer) : ByteBufferHandle
Computes a SHA-256 digest of the buffer contents.
slice
slice(ByteBufferHandle sourceBuffer, Integer offset, Integer length) : ByteBufferHandle
Extracts a portion of a buffer without modifying the original.
let buffer = byteContext.create(100);
let middle = byteContext.slice(buffer, 25, 50); // Extract bytes 25-74
console.log(byteContext.getSize(middle)); // 50
// Extract from offset to end
let tail = byteContext.slice(buffer, 80, byteContext.getSize(buffer) - 80);
split
split(ByteBufferHandle buffer, ByteBufferHandle delimiter, Integer includeDelimiter) : ByteBufferHandle[]
Splits a buffer by a delimiter buffer.
let buffer = byteContext.createFrom([1, 2, 3, 2, 4]);
let delimiter = byteContext.createFrom([2]);
let parts = byteContext.split(buffer, delimiter, 0); // [[1], [3], [4]]
toString
toString(ByteBufferHandle buffer) : String
unzip
unzip(ByteBufferHandle buffer) : ByteBufferHandle
Decompresses ZIP-compressed buffer contents.
let compressed = byteContext.zip(originalBuffer);
let decompressed = byteContext.unzip(compressed);
writeByte
writeByte(ByteBufferHandle buffer, Integer offset, Integer value)
Writes a single byte to the buffer at the specified offset.
let buffer = byteContext.create(10);
buffer = byteContext.writeByte(buffer, 0, 0xFF); // Write 255
buffer = byteContext.writeByte(buffer, 1, 0x00); // Write 0
// Build a 32-bit big-endian integer
function writeInt32BE(buffer, offset, value) {
buffer = byteContext.writeByte(buffer, offset, (value >>> 24) & 0xFF);
buffer = byteContext.writeByte(buffer, offset + 1, (value >>> 16) & 0xFF);
buffer = byteContext.writeByte(buffer, offset + 2, (value >>> 8) & 0xFF);
buffer = byteContext.writeByte(buffer, offset + 3, value & 0xFF);
return buffer;
}
writeBytes
writeBytes(ByteBufferHandle toBuffer, Integer offset, ByteBufferHandle sourceBuffer, Integer sourceOffset, Integer length)
Copies bytes from one buffer to another. This is the most efficient way to move large amounts of data between buffers.
let source = byteContext.createFrom([1, 2, 3, 4, 5]);
let dest = byteContext.create(10);
// Copy bytes 1-3 from source to position 2 in dest
byteContext.writeBytes(dest, 2, source, 1, 3);
// dest now contains: [0, 0, 2, 3, 4, 0, 0, 0, 0, 0]
zip
zip(ByteBufferHandle buffer) : ByteBufferHandle
Compresses buffer contents using ZIP compression.
let compressed = byteContext.zip(originalBuffer);
let decompressed = byteContext.unzip(compressed);
ByteReader
A sequential reader for efficient forward-only reading of buffer data.
Methods
The following methods are available to call on the context.bytes().reader(...) object.
available
available() : Integer
Returns the number of bytes that can be read from the current position.
let available = reader.available();
read
read(Integer length) : ByteBufferHandle
Reads the specified number of bytes from the current position into a new buffer.
let buffer = reader.read(20);
console.log(context.bytes().getSize(buffer)); // 20
readAll
readAll() : ByteBufferHandle
Reads all the available bytes from the current position into a new buffer.
let buffer = reader.readAll();