# 🧾 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**: ```bash 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 ```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() ``` --- ## πŸ”— Related Pages - πŸ” [Credentials input](/04_methods_development/05_input_types/05_input_credentials.md) - πŸ“¦ [Runtime architecture](/05_advanced_topics/01_architecture/02_runtime_architecture.md) - 🧱 [Method scripts and placeholders](/04_methods_development/06_scripts_and_placeholders.md)