π§Ύ Environment Variables and ccptaskidο
This page documents special environment variables made available during method execution.
These allow your code to uniquely identify each replica, manage security tokens, and interact with D4Science services.
π ccptaskid: Execution Replica Identifierο
When a method is executed in parallel (e.g. multiple inputs or parallel containers), each instance is assigned a unique ccptaskid.
You can use this to generate replica-specific outputs:
mkdir -p /ccp_data/output
echo $RANDOM > /ccp_data/output/$(printenv ccptaskid).txt
This ensures files donβt overwrite each other across replicas.
π Auth Environment Variablesο
When your method runs, the container receives the following secure environment variables:
| Variable | Description |
|---|---|
ccpiamurl |
IAM server URL |
ccpclientid |
Client ID for token operations |
ccprefreshtoken |
Refresh token for authentication |
ccpcontext |
VRE/Context in which the method runs |
π Renewing Tokens from Inside the Methodο
You can use these variables to request a login token and an UMA access token
for accessing secured services like the Workspace or Catalogue.
π Example: Token Renewal in Pythonο
import os, requests
# Get auth info
refreshtoken = os.environ["ccprefreshtoken"]
context = os.environ["ccpcontext"]
clientid = os.environ["ccpclientid"]
iam = os.environ["ccpiamurl"]
# Login request
logindata = {
'grant_type': 'refresh_token',
'client_id': clientid,
'refresh_token': refreshtoken
}
loginheaders = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
}
# UMA token request
umadata = {
'grant_type': 'urn:ietf:params:oauth:grant-type:uma-ticket',
'audience': context
}
umaheaders = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
}
def getToken():
resp1 = requests.post(iam, data=logindata, headers=loginheaders)
jwt = resp1.json()
umaheaders["Authorization"] = "Bearer " + jwt["access_token"]
resp2 = requests.post(iam, data=umadata, headers=umaheaders)
return resp2.json()["access_token"]
# Use token
token = getToken()
headers = {"Authorization": f"Bearer {token}", "Accept": "application/json"}
vrefolder = requests.get("https://workspace.d4science.org/vrefolder", headers=headers).json()