Who among us hasn’t ever needed to download a larger file like an ISO or tarball onto their laptop via a browser, just to upload it via scp or WinSCP to a server somewhere far, far away– all because of the source website’s authentication requirements? Even in our modern world of multi-gigabit home Internet download speeds, considering the total number of network hops your file(s) might have to take, all while traversing corporate VPN and IDPS services as well, this inconvenience can cost you precious time during tight maintenance windows especially.

Direct downloads onto a target or bastion server (in your cloud tenant or datacenter) can be a great way to go in these situations… if you can make them work for you. In the case of Red Hat®, there are a few steps involved to download their software content via curl, but they may add up to real time savings.

1) Generate an offline token

You can generate an offline token for your Red Hat user account here (this token will eventually expire unless you refresh it periodically):

https://access.redhat.com/management/api

2) Save your offline token somewhere (optional)

Optionally, save your new offline token in your favorite password manager if and as needed (especially if you plan on reusing it in the future for automations, etc. As you probably already know, Level Up loves automating!).

3) Grab your download’s checksum and go

Copy the SHA256 checksum for the product content file (e.g., the latest Red Hat AAP setup bundle) from the Downloads section of https://access.redhat.com:

4) curl your way to victory

Run the following (as a script or individual steps) from the terminal of an instance in your cloud tenant or datacenter (adapted from https://access.redhat.com/articles/3626371):

# rh-direct-download.sh:

#!/bin/bash
# set the offline token and checksum parameters
offline_token="<YOUR_OFFLINE_TOKEN>"

# get an access token
access_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 -r '.access_token')

# get the filename and download url
checksum="d8587a2835877d6f6323eba49fb9486ce6b83cb7782c47951215a6f9de463de6"
image=$(curl -H "Authorization: Bearer $access_token" "https://api.access.redhat.com/management/v1/images/$checksum/download")
filename=$(echo $image | jq -r .body.filename)
url=$(echo $image | jq -r .body.href)

# download the file
curl $url -o $filename

Upon a successful curl, you’ll see output like this:

# results of curl:

$ curl $url -o $filename
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2193M  100 2193M    0     0  12.4M      0  0:02:56  0:02:56 --:--:-- 8832k
$ ls -lh | grep ansible-automation-platform-setup-bundle-2.4-7-x86_64.tar.gz
-rw-r--r--     1 ec2-user  ec2-user   2.1G Jul 15 11:40 ansible-automation-platform-setup-bundle-2.4-7-x86_64.tar.gz
$

And that’s it!

Get the latest from Level Up delivered to your inbox– DevOps Automation and Cloud news, tips & tricks.

Select list(s) to subscribe to


By submitting this form, you are consenting to receive marketing emails from: Level Up, 20929 Ventura Blvd Ste 47 #265, Woodland Hills, CA, 91364. You can revoke your consent to receive emails at any time by using the SafeUnsubscribe® link, found at the bottom of every email. Emails are serviced by Constant Contact

Spread the word. Share this post!