Downloading JBoss Enterprise Application Platform (EAP) from the Red Hat Customer Portal programmatically via API involves a series of steps, primarily centered around authentication and accessing the correct endpoints. This comprehensive guide will walk you through the process, providing detailed instructions and code examples to facilitate the download.
Before you begin, ensure you have the following:
Active Red Hat Account: You must have a valid Red Hat account with an active subscription that includes JBoss EAP.
API Token or Credentials: Depending on the method, you will need either an API token or your Red Hat account credentials (username and password) for authentication.
Software Tools: You will need tools like curl
, wget
, or programming languages like Python with libraries such as requests
to interact with the API. Additionally, jq
is useful for processing JSON responses in shell scripts.
There are primarily two methods for authenticating with the Red Hat API:
Using an API Token (Bearer Token): This is the recommended method for programmatic access.
Using Basic Authentication: This involves using your Red Hat account username and password.
To use an API token, follow these steps:
Log in to the Red Hat Customer Portal: Go to access.redhat.com and log in with your credentials.
Navigate to API Tokens: Find the section for managing API tokens. This is usually under your account settings or a similar section.
Generate a New Token: Create a new API token. Make sure to copy and securely store this token, as you will need it for subsequent API requests.
If you prefer to use basic authentication, you will use your Red Hat account username and password directly in your API requests. However, this method is generally less secure than using API tokens.
Before you can download JBoss EAP, you need to identify the specific product and version you want. Red Hat provides API endpoints to help you list available products and versions.
Here are the key API endpoints you will be interacting with:
List Products: https://api.access.redhat.com/management/v1/products
List Versions for a Product: https://api.access.redhat.com/management/v1/products/{product_id}/versions
Get Download Links for a Version: https://api.access.redhat.com/management/v1/products/{product_id}/versions/{version_id}/download
Below is a detailed Python script that demonstrates how to download JBoss EAP using the Red Hat API. This script uses the API token method for authentication.
import requests
import json
# Replace with your actual API token
API_TOKEN = "your_api_token_here"
# Replace with the specific JBoss product and version you want to download
PRODUCT = "jboss-eap"
VERSION = "7.4.0"
# Set up the API endpoint and headers
api_url = "https://api.access.redhat.com/management/v1/products"
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Accept": "application/json"
}
# Step 1: Get the product details
response = requests.get(api_url, headers=headers)
if response.status_code != 200:
print(f"Failed to get product details: {response.text}")
exit(1)
products = response.json()
product_id = next((p['id'] for p in products if p['code'] == PRODUCT), None)
if not product_id:
print(f"Product {PRODUCT} not found.")
exit(1)
# Step 2: Get the versions for the product
versions_url = f"{api_url}/{product_id}/versions"
response = requests.get(versions_url, headers=headers)
if response.status_code != 200:
print(f"Failed to get versions: {response.text}")
exit(1)
versions = response.json()
version_id = next((v['id'] for v in versions if v['version'] == VERSION), None)
if not version_id:
print(f"Version {VERSION} not found.")
exit(1)
# Step 3: Get the download links for the version
downloads_url = f"{api_url}/{product_id}/versions/{version_id}/download"
response = requests.get(downloads_url, headers=headers)
if response.status_code != 200:
print(f"Failed to get download links: {response.text}")
exit(1)
downloads = response.json()
download_link = next((d['downloadLink'] for d in downloads if d['fileName'].endswith('.zip')), None)
if not download_link:
print("No suitable download link found.")
exit(1)
# Step 4: Download the file
print(f"Downloading from: {download_link}")
response = requests.get(download_link, headers=headers, stream=True)
if response.status_code != 200:
print(f"Failed to download file: {response.text}")
exit(1)
with open(f"{PRODUCT}-{VERSION}.zip", 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Download complete: {PRODUCT}-{VERSION}.zip")
Authentication: The script starts by setting up the API token and headers required for authentication.
Get Product Details: It makes a request to the /products
endpoint to find the ID of the JBoss EAP product.
Get Version Details: Using the product ID, it queries the /versions
endpoint to find the ID of the specified version.
Get Download Link: With both the product and version IDs, it requests the download link from the /download
endpoint.
Download the File: Finally, it downloads the file using the obtained link and saves it locally.
For those who prefer command-line tools, here's how to download JBoss EAP using curl
and jq
. This method uses an offline token to obtain an access token for authentication.
An offline token is a long-lived token that can be used to obtain access tokens. You can generate an offline token from the Red Hat Customer Portal under your account settings.
Use the offline token to obtain an access token. The access token is used for authenticating API requests.
# Set the offline token value
offline_token='your_offline_token_here'
# Get the access token
token=$(curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token \
-d grant_type=refresh_token \
-d client_id=rhsm-api \
-d refresh_token=$offline_token | jq --raw-output .access_token)
With the access token, you can now make authenticated requests to download JBoss EAP.
# Example API call to download JBoss EAP 7.4
curl -H "Authorization: Bearer $token" "https://api.access.redhat.com/management/v1/products/jboss-eap/versions/7.4.0/download" -o jboss-eap-7.4.0.zip
Set Offline Token: The offline token is set as a variable.
Obtain Access Token: A curl
command is used to request an access token from the Red Hat Single Sign-On (SSO) service using the offline token.
Download JBoss EAP: Another curl
command is used to make an authenticated request to the download endpoint, saving the file locally.
Alternatively, you can use wget
to download JBoss EAP. This method is similar to using curl
but with a different command-line tool.
# Set the offline token value
offline_token='your_offline_token_here'
# Get the access token
token=$(curl https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token \
-d grant_type=refresh_token \
-d client_id=rhsm-api \
-d refresh_token=$offline_token | jq --raw-output .access_token)
# Example API call to download JBoss EAP 7.4
wget --header="Authorization: Bearer $token" "https://api.access.redhat.com/management/v1/products/jboss-eap/versions/7.4.0/download" -O jboss-eap-7.4.0.zip
Set Offline Token: The offline token is set as a variable.
Obtain Access Token: Similar to the curl
method, an access token is obtained using the offline token.
Download JBoss EAP: The wget
command is used to make an authenticated request to the download endpoint, saving the file locally.
Be aware that Red Hat may impose rate limits on API requests. If you are making a large number of requests, ensure you handle rate limiting gracefully by implementing delays or retries in your script.
Always include error handling in your scripts to manage issues such as network problems, invalid tokens, or incorrect API endpoints. Proper error handling ensures that your script can recover from unexpected issues and provides useful feedback.
Ensure you comply with Red Hat's terms of service regarding API usage and automated downloads. Unauthorized use of the API may result in your access being revoked.
Regularly refer to the latest Red Hat API documentation for any updates or changes to the API endpoints, authentication methods, or response formats. API documentation is typically available on the Red Hat Customer Portal or developer portal.
Downloading JBoss EAP from the Red Hat Customer Portal using the API involves authenticating your requests and interacting with specific API endpoints to identify and download the desired product and version. This guide has provided detailed steps and examples using Python, curl
, and wget
to help you automate the download process. By following these instructions and adhering to best practices, you can efficiently manage your JBoss EAP downloads programmatically.
Remember to keep your API tokens and credentials secure, handle errors appropriately, and comply with Red Hat's terms of service. With these guidelines, you can confidently integrate JBoss EAP downloads into your automated workflows.