Created
July 30, 2020 05:42
-
-
Save jc1518/ad9dac41f81fc70f83daaee314b8a3f5 to your computer and use it in GitHub Desktop.
Automate Atlassian Addons POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a3 = Automate Atlassian Addons | |
def get_server_info(server, auth): | |
''' Check application version on the server ''' | |
print("\n>>> Checking server information") | |
server_application = server.split('.')[0].split('-')[0] | |
url = "https://{}/rest/applinks/1.0/manifest".format(server) | |
headers = {'content-type': 'application/xml'} | |
response = requests.get(url, auth=auth, headers=headers) | |
response.raise_for_status() | |
manifest = etree.fromstring(response.text.encode('utf-8')) | |
server_version = manifest.xpath('/manifest/version').pop().text | |
print("{} is on {} {}".format(server, server_application, server_version)) | |
return {"application": server_application, "version": server_version} | |
def parse_plugins_details(file): | |
''' Get plugin details from the var file ''' | |
try: | |
with open(file) as f: | |
plugins_details = yaml.load(f, Loader=yaml.FullLoader)["plugin_details"] | |
return plugins_details | |
except: | |
print("Error:", sys.exc_info()[0]) | |
raise | |
def get_plugin_info_by_version_from_marketplace(plugin): | |
''' Get plugin info by version from Atlassian Marketplace ''' | |
print("\n>>> Checking {} {}".format(plugin["desc"], plugin["version"])) | |
url = "{}/addons/{}/versions/name/{}?hosting=datacenter"\ | |
.format(market_place_path_url, plugin["key"], plugin["version"]) | |
headers = {'Accept': 'application/json'} | |
response = requests.get(url, headers=headers) | |
if response.status_code==404: | |
print(u'\u274c', "{} seems not compatible with datacenter version, please double check the version number.".format(plugin["version"])) | |
return False | |
else: | |
response.raise_for_status() | |
plugin_info = json.loads(response.text) | |
return plugin_info | |
def get_latest_plugin_info_from_marketplace(server_application, plugin): | |
''' Get latest plugin info from Atlassian Marketplace ''' | |
url = "{}/addons/{}/versions/latest?application={}&afterVersion={}&hosting=datacenter"\ | |
.format(market_place_path_url, plugin["key"], server_application, plugin["version"]) | |
headers = {'Accept': 'application/json'} | |
response = requests.get(url, headers=headers) | |
if response.status_code==404: | |
print("This plugin is already on the latest version.") | |
return False | |
else: | |
response.raise_for_status() | |
plugin_info = json.loads(response.text) | |
print("Latest version {} is available".format(plugin_info["name"])) | |
return plugin_info | |
def check_plugin_compatibility(server_application, server_version, plugin_info): | |
''' Check plugin compatibility against server version ''' | |
if plugin_info: | |
for supported_platform in plugin_info["compatibilities"]: | |
if supported_platform["application"]==server_application: | |
support_min_version = supported_platform["hosting"]["dataCenter"]["min"]["version"] | |
support_max_version = supported_platform["hosting"]["dataCenter"]["max"]["version"] | |
if (version.parse(support_min_version) <= version.parse(server_version)) and ( | |
version.parse(server_version) <= version.parse(support_max_version)): | |
print(u'\u2713', "{} is compatible with {} {}".format(plugin_info["name"], server_application, server_version)) | |
return True | |
else: | |
print(u'\u274c', "{} is not compatible with {} {}, the supported version is between {} and {}"\ | |
.format(plugin_info["name"], server_application, server_version, support_min_version, support_max_version)) | |
return False | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment