Prerequisites:
Semver is the only external dependency. pip install semver
Usage:
python get_enterprise_url.py -h
will display all flags and options.
########## | |
# Consul # | |
########## | |
## Download latest | |
curl -L $(python get_enterprise_url.py -p consul) > consul.zip | |
## Download a specific version | |
curl -L $(python get_enterprise_url.py -p consul -v 1.4.0) > consul.zip | |
######### | |
# Vault # | |
######### | |
## Download latest | |
curl -L $(python get_enterprise_url.py -p vault) > vault.zip | |
## Download a specific version | |
curl -L $(python get_enterprise_url.py -p vault -v 1.0.0) > vault.zip |
################################################################################ | |
# get_enterprise_url.py # | |
# gets the URL to download Vault Enterprise or Consul Enterprise # | |
################################################################################ | |
import sys | |
import json | |
import urllib | |
import urllib2 | |
import semver | |
def get_latest_version(product): | |
# use semver's cmp function as the sort function to get the latest version | |
jsondata = json.loads(urllib2.urlopen("https://releases.hashicorp.com/%s/index.json" % product).read()) | |
return sorted(jsondata['versions'].keys(), cmp=lambda a, b: semver.cmp(a, b))[-1] | |
def get_version_url(product, platform, os, version, edition): | |
# hacky encoding stuff to insert a URL entity so the Python string formatter does not misinterpret the token | |
if edition == 'ent': | |
return "https://s3-us-west-2.amazonaws.com/hc-enterprise-binaries/%s/ent/%s/%s-enterprise_%s%sent_%s_%s.zip" % (product, version, product, version, urllib.quote_plus('+'), os, platform) | |
elif edition == 'prem': | |
return "s3://hc-enterprise-binaries/%s/prem/%s/%s-enterprise_%s+prem_%s_%s.zip" % (product, version, product, version, os, platform) | |
elif edition == 'pro': | |
return "s3://hc-enterprise-binaries/%s/pro/%s/%s-enterprise_%s+pro_%s_%s.zip" % (product, version, product, version, os, platform) | |
if __name__ == '__main__': | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-p", "--product", help="Name of the product ('vault' or 'consul')") | |
parser.add_argument("-l", "--platform", default="amd64", help="Defaults to amd64. Replace with desired architecture") | |
parser.add_argument("-o", "--os", default="linux", help="Defaults to linux. Replace with desired operating system") | |
parser.add_argument("-v", "--version", default="latest", help="Defaults to latest. Replace with desired version") | |
parser.add_argument("-e", "--edition", default="ent", help="Defaults to ent. Replace with desired edition") | |
args = parser.parse_args() | |
product, platform, os, edition = args.product, args.platform, args.os, args.edition | |
version = get_latest_version(product).replace('+ent', '') if args.version == 'latest' else args.version | |
print get_version_url(product, platform, os, version, edition) |