2. CAWBS library
The CaWBS library provides a Python-based utility to interact with CoreAuto's REST APIs for workload automation and real-time event handling. It is designed to integrate seamlessly with CoreAuto's backend services, offering methods to authenticate, retrieve event data, manage step payloads, and interact with keystore services.
Installation
Ensure that Python 3.6+ is installed on your system. To use the library, copy the provided Python code into your project and configure the required environment variables.
Environment Variables
Before using the library, the following environment variables must be defined:
ENV Specifies the environment (e.g., "production").
ACTIONID Unique action identifier for the event.
CA_ACCESS_CODE API access code for authentication.
CA_WBS_URL Base URL of the CoreAuto API.
STEPNAME Name of the workflow step to interact with.
Initialization
Init()
Initializes the library by authenticating with the API and setting up necessary headers.
- Returns:
status_code
: HTTP response code.
error
: Error message (if any).
- Possible Error Codes:
601
: Missing environment variables.
602
: Initialization already completed.
result = Init()
if result['status_code'] == 200:
print("Initialization successful!")
else:
print(f"Error: {result['error']}")
Core Functions
GetEventPayload()
Fetches the payload of the event specified by ACTIONID
.
- Returns:
status_code
: HTTP response code.
payload
: Event payload data.
- Possible Error Codes:
603
: Initialization required.
result = GetEventPayload()
if result['status_code'] == 200:
print("Payload:", result['payload'])
else:
print(f"Error: {result['error']}")
PutStepPayload(payload)
PutStepPayload(payload)
Saves a payload for the specified step.
- Parameters:
payload
: JSON object containing the data to be saved.
- Returns:
status_code
: HTTP response code.
error
: Error message (if any).
- Possible Error Codes:
603
: Initialization required.
payload_data = {"key": "value"}
result = PutStepPayload(payload_data)
if result['status_code'] == 200:
print("Payload saved successfully!")
else:
print(f"Error: {result['error']}")
GetStepPayload(stepname)
GetStepPayload(stepname)
Retrieves the payload of a specific step.
- Parameters:
stepname
: Name of the step to retrieve the payload from.
- Returns:
status_code
: HTTP response code.payload
: Payload data.
- Possible Error Codes:
603
: Initialization required.
result = GetStepPayload("Step1")
if result['status_code'] == 200:
print("Step Payload:", result['payload'])
else:
print(f"Error: {result['error']}")
GetKeystore(keylist)
GetKeystore(keylist)
Fetches values from the keystore based on a comma-separated list of keys.
- Parameters:
keylist
: Comma-separated string of key names.
- Returns:
status_code
: HTTP response code.
answer
: Dictionary containing key-value pairs.
- Possible Error Codes:
603
: Initialization required.
605
: Specific key not found.
result = GetKeystore("key1,key2")
if result['status_code'] == 200:
print("Keystore Data:", result['answer'])
else:
print(f"Error: {result['error']}")
Error Handling
The library provides consistent error handling through structured responses containing status_code
and error
fields. Ensure that error codes are handled appropriately in your application.
Authentication Workflow
Init()
to authenticate and generate a token.
Version
Library Version: 1.0.0
Last Updated: January 22, 2025