Skip to content

Instantly share code, notes, and snippets.

@andreas-wilm
Last active August 30, 2019 02:28
Show Gist options
  • Save andreas-wilm/62e23ad3fd45c3aeeace6a83c510e191 to your computer and use it in GitHub Desktop.
Save andreas-wilm/62e23ad3fd45c3aeeace6a83c510e191 to your computer and use it in GitHub Desktop.
Convert Github JSON URL to directly usable "Deploy on Azure" link
import urllib.parse
TEMPLATEURL = "https://portal.azure.com/#create/Microsoft.Template/uri/"
def toraw(ghurl):
# convert github url to its raw equivalent, if needed
ghbase = "https://github.com"
ghrawbase = "https://raw.githubusercontent.com"
if ghbase in ghurl and "/blob/" in ghurl:
return ghurl.replace(ghbase, ghrawbase).replace("/blob/", "/")
else:
return ghurl
# example input json
json = "https://github.com/Azure/DataScienceVM/blob/master/Scripts/CreateDSVM/Ubuntu/dsvm-vmss-lowpri.json"
print(TEMPLATEURL.rstrip("/") + "/" + urllib.parse.quote(toraw(json), safe=''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment