Veracode API Signing Library

26.4.0 · active · verified Tue Apr 14

The `veracode-api-signing` library provides an easy way to sign HTTP requests destined for the Veracode API Gateway using Hash-based Message Authentication Code (HMAC). This is a crucial security measure for authenticating with Veracode's REST and XML APIs. The current version is 26.4.0, and new releases are typically published every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to make an authenticated GET request to the Veracode REST API's `/applications` endpoint using the `veracode-api-signing` library with the popular `requests` library. API credentials are expected to be available as environment variables `VERACODE_API_KEY_ID` and `VERACODE_API_KEY_SECRET`, or alternatively, loaded from a `~/.veracode/credentials` file. The `RequestsAuthPluginVeracodeHMAC` automatically signs the request with the provided or discovered credentials.

import requests
import os
from veracode_api_signing.plugin_requests import RequestsAuthPluginVeracodeHMAC

# Veracode API credentials can be loaded from ~/.veracode/credentials or environment variables.
# For quickstart, using environment variables for demonstration. In production, prefer file.
api_id = os.environ.get('VERACODE_API_KEY_ID', '')
api_key_secret = os.environ.get('VERACODE_API_KEY_SECRET', '')

if not api_id or not api_key_secret:
    print("WARNING: VERACODE_API_KEY_ID and VERACODE_API_KEY_SECRET environment variables are not set.")
    print("Please set them or configure ~/.veracode/credentials file for successful authentication.")
    # Exit or provide mock values for a non-failing example
    api_id = 'YOUR_MOCK_API_ID'
    api_key_secret = 'YOUR_MOCK_API_SECRET'

# The base URL for Veracode REST APIs. For US Commercial Region.
# Adjust for other regions if necessary (e.g., https://api.veracode.eu/appsec/v1)
api_base = "https://api.veracode.com/appsec/v1"

try:
    # Make a GET request to an API endpoint, e.g., /applications
    # The RequestsAuthPluginVeracodeHMAC automatically handles signing the request.
    response = requests.get(api_base + "/applications", auth=RequestsAuthPluginVeracodeHMAC(api_key_id=api_id, api_key_secret=api_key_secret))
    response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
    print("Successfully fetched applications:")
    print(response.json())
except requests.exceptions.HTTPError as e:
    print(f"HTTP Error: {e.response.status_code} - {e.response.text}")
except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")

view raw JSON →