Skip to content

Instantly share code, notes, and snippets.

@Resousse
Created September 26, 2022 10:16
Show Gist options
  • Save Resousse/94b347bd83201357c1f06c8121059b86 to your computer and use it in GitHub Desktop.
Save Resousse/94b347bd83201357c1f06c8121059b86 to your computer and use it in GitHub Desktop.
Retrieve the list of LoadBalancer (LB) defined in Mulesoft Anypoint platform
import requests
'''
pip install requests
orgId can be retrieved in any url of the api manager, within the URL after the /organizations/
token can be retrieved if you run the developper console (F12 on Chrome), in network tab, and then go in RuntimeManager then Load Balancers, this could be found in Authorization header, take the part after Bearer
'''
orgId = "insert yours"
token = "insert yours"
auth = {"Authorization" : "Bearer {}".format(token)}
r = requests.get("https://anypoint.mulesoft.com/cloudhub/api/organizations/{}/loadbalancers?shortFormat=true".format(orgId), headers=auth)
f = open("LBMulesoft.csv", "w")
assert r, "Please check parameters or Auth Token"
assert r.json(), "No JSON returned"
f.write("LB Name;Public BaseName;Base Url;Target App Name;Target URI\n")
for vpc in r.json()["data"]:
print (vpc["name"])
s = requests.get("https://anypoint.mulesoft.com/cloudhub/api/organizations/{}/vpcs/{}/loadbalancers/{}".format(orgId, vpc["vpcId"], vpc["id"]) , headers=auth)
assert s, "Unable to retrieve LB configuration"
assert s.json(), "No JSON returned by LB"
js = s.json()
for ssl in js["sslEndpoints"]:
for map in ssl["mappings"]:
f.write("{};{};{};{};{}\n".format(vpc["name"], ssl["publicKeyCN"], map["inputUri"], map["appName"], map["appUri"]))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment