Variables are dynamic values that have a key associated to them and can be retrieved during the execution of a Script or Flow.

All Variables (not just secrets) are encrypted with a workspace specific symmetric key to avoid leakage.

There are two types of Variables in getOperate: user-defined and contextual.

User-defined Variables

User-defined Variables is essentially a key-value store where every user can read, set and share values at given keys as long as they have the privilege to do so.

They are editable in the UI and also readable if they are not Secret Variables.

Inside the Scripts, one would use the getOperate client to interact with the user-defined Variables.

import getOperate

getOperate.get_variable("u/user/foo")
getOperate.set_variable("u/user/foo", value)

Note that there is a similar API for getting and setting Resources which are simply Variables that can contain any JSON values, not just a string and that are labeled with a Resource Type to be automatically discriminated in the auto-generated form to be of the proper type (e.g. a parameter in TypeScript of type pg: Postgresql is only going to offer a selection over the resources of type postgresql in the auto-generated UI).

There is also a concept of state to share values across script executions.

Contextual variables

Contextual Variables are environment variables automatically set by getOperate. This is how the Deno and Python clients get their implicit credentials to interact with the platform.

See the Contextual tab on the Variable page for the list of reserved variables and what they are used for.

You can use them in a Script by clicking on “+Context Var”:

NameValue
GOPRT_WORKSPACEWorkspace id of the current script
GOPRT_TOKENToken ephemeral to the current script with equal permission to the permission of the run (Usable as a bearer token)
GOPRT_EMAILEmail of the user that executed the current script
GOPRT_USERNAMEUsername of the user that executed the current script
GOPRT_BASE_URLBase URL of this instance
GOPRT_JOB_IDJob id of the current script
GOPRT_JOB_PATHPath of the script or flow being run if any
GOPRT_FLOW_JOB_IDJob id of the encapsulating flow if the job is a flow step
GOPRT_FLOW_PATHPath of the encapsulating flow if the job is a flow step
GOPRT_SCHEDULE_PATHPath of the schedule if the job of the step or encapsulating step has been triggered by a schedule
GOPRT_PERMISSIONED_ASFully Qualified (u/g) owner name of executor of the job
GOPRT_STATE_PATHState resource path unique to a script and its trigger

Secrets

Secrets are encrypted when stored on getOperate. From a usage standpoint, secrets are kept safe in three different ways:

  • Secrets can only be accessed by users with the right permissions, as defined by their path. In addition, secrets can be explicitly shared with users or groups. A secret in u/alice/secret will only be accessible by alice, unless explicitly shared. A secret in f/devops/secret will be accessible by anyone with read access to f/devops.
  • Secrets cannot be viewed outside of scripts. Note that a user could still print a secret if they have access to it from a script.
  • Accessing secrets generates variables.decrypt_secret event that ends up in the Audit Logs. It means that you can audit who accesses secrets. Additionally you can audit results, logs and script code for every script run.

Add a Variable or Secret

You can define variables from the Variables page. Like all objects in getOperate, variable ownership is defined by the path - see ownership path prefix.

Variables also have a name, generated from the path, and names are used to access variables from scripts.

A variable can be made secret. In this case, its value will not be visible outside of a script.

Accessing a variable from a script

Add Resources and Variables to Code Editor

You can directly access Variables and Resources from the Code Editor.

Accessing Contextual Variables from a script

See the Contextual tab on the Variable page for the list of reserved variables and what they are used for.

You can use them in a Script by clicking on “+Context Var”:

Reserved variables are passed to the job as environment variables. For example, the ephemeral token is passed as GOPRT_TOKEN.

Accessing User-defined Variables from a script

There are 2 main ways variables are used within scripts:

Passing variables as parameters to scripts

Variables can be passed as parameters of the script, using the UI based variable picker. Underneath, the variable is passed as a string of the form: $var:<variable_path> and replaced by the worker at time of execution of the script by fetching the value with the job’s permissions. So the job will fail if the job’s permissions inherited from the caller do not allow access to the variable. This is the same mechanism used for resource, but they use $res: instead of $var:.

Fetching them from within a script by using the getOperate client in the respective language

By clicking on + Variable, you’ll get to pick a variable from your workspace and be able to fetch it from within the script.

Typescript:

getOperate.getVariable('u/user/foo');

Python:

getOperate.get_variable("u/user/foo")

Go:

getOperate.GetVariable("u/user/foo")

Bash:

curl -s -H "Authorization: Bearer $GOPRT_TOKEN" \
  "$BASE_INTERNAL_URL/api/w/$GOPRT_WORKSPACE/variables/get/u/user/foo" \
    | jq -r .value

PowerShell:

$Headers = @{
  "Authorization" = "Bearer $Env:GOPRT_TOKEN"
}
Invoke-RestMethod -Headers $Headers -Uri "$Env:BASE_INTERNAL_URL/api/w/$Env:GOPRT_WORKSPACE/variables/get/u/user/foo"

The last examples in bash and PowerShell showcase well how it works under the hood: It fetches the secret from the API using the job’s permissions through the ephemeral token passed as an environment variable to the job.