gigantum
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: gigantum | ||
| Version: 1.2.0 | ||
| Version: 1.2.1 | ||
| Summary: CLI for the Gigantum Platform | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/gigantum/gigantum-cli |
| # Gigantum CLI Version | ||
| __version__ = "1.2.0" | ||
| __version__ = "1.2.1" |
@@ -95,5 +95,8 @@ import sys | ||
| print("\nDownloading and installing the Gigantum Client Docker Image. Please wait...\n") | ||
| image = docker.client.images.pull(image_name, 'latest') | ||
| cl = ChangeLog() | ||
| tag = cl.latest_tag() | ||
| image = docker.client.images.pull(image_name, tag) | ||
| docker.client.api.tag('{}:{}'.format(image_name, tag), image_name, 'latest') | ||
| except APIError: | ||
| except APIError as err: | ||
| msg = "ERROR: failed to pull image! Verify your internet connection and try again." | ||
@@ -129,3 +132,3 @@ raise ExitCLI(msg) | ||
| # Trying to update to the latest version | ||
| tag = 'latest' | ||
| tag = cl.latest_tag() | ||
@@ -153,3 +156,3 @@ # Get id of current labmanager install | ||
| # Trying to update to the latest version | ||
| tag = 'latest' | ||
| tag = "latest" | ||
@@ -162,6 +165,4 @@ # Make sure user wants to pull | ||
| # If pulling not truly latest, force to latest | ||
| if tag != 'latest': | ||
| print("Tagging explicit version {} with latest".format(tag)) | ||
| docker.client.api.tag('{}:{}'.format(tag, image_name), image_name, 'latest') | ||
| # Tag to latest locally | ||
| docker.client.api.tag('{}:{}'.format(image_name, tag), image_name, 'latest') | ||
| else: | ||
@@ -168,0 +169,0 @@ raise ExitCLI("Update cancelled") |
@@ -55,5 +55,26 @@ # Copyright (c) 2017 FlashX, LLC | ||
| """ | ||
| latest_hash = self.data['latest']['id'] | ||
| return latest_hash != tag | ||
| latest_image_id = self.data['latest']['id'] | ||
| return latest_image_id != tag | ||
| def latest_tag(self): | ||
| """Method to get the latest tag from the changelog data | ||
| Returns: | ||
| str | ||
| """ | ||
| latest_image_id = self.data['latest']['id'] | ||
| tag = None | ||
| for t in self.data: | ||
| if t == "latest": | ||
| continue | ||
| if self.data[t]['id'] == latest_image_id: | ||
| tag = t | ||
| break | ||
| if not tag: | ||
| raise ValueError("Failed to look up latest image tag.") | ||
| return tag | ||
| def get_changelog(self, tag="latest"): | ||
@@ -60,0 +81,0 @@ """Method to print the changelog data |
+52
-30
@@ -6,3 +6,4 @@ from urllib.parse import urljoin, urlparse | ||
| import requests | ||
| from gigantumcli.utilities import ExitCLI | ||
| from gigantumcli.utilities import ExitCLI, ask_question | ||
| import urllib3 | ||
@@ -16,3 +17,44 @@ | ||
| @staticmethod | ||
| def _discover_server(url: str): | ||
| def _fetch_wellknown_data(url): | ||
| succeed = False | ||
| data = None | ||
| verify = True | ||
| try: | ||
| response = requests.get(url, verify=verify) | ||
| if response.status_code == 200: | ||
| try: | ||
| # If a 200, make sure you get valid JSON back in case you were routed to some other 200 response. | ||
| data = response.json() | ||
| succeed = True | ||
| except json.JSONDecodeError: | ||
| pass | ||
| except requests.exceptions.SSLError: | ||
| print("WARNING: SSL verification failed while trying to configure from server located at {}.\nIf this" | ||
| " is expected, it may be safe to proceed (e.g. a server created with a self-signed TLS " | ||
| "certificate).".format(url)) | ||
| if ask_question("Do you want to continue?"): | ||
| # Try again with SSL verification disabled | ||
| try: | ||
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
| verify = False | ||
| response = requests.get(url, verify=verify) | ||
| if response.status_code == 200: | ||
| try: | ||
| # If a 200, make sure you get valid JSON back in case you were routed to some | ||
| # other 200 response. | ||
| data = response.json() | ||
| succeed = True | ||
| except json.JSONDecodeError: | ||
| pass | ||
| except requests.exceptions.ConnectionError: | ||
| pass | ||
| else: | ||
| # User decided not to proceed. | ||
| raise ExitCLI("SSL Verification failed on server located at {}.".format(url)) | ||
| except requests.exceptions.ConnectionError: | ||
| pass | ||
| return succeed, data, verify | ||
| def _discover_server(self, url: str): | ||
| """Method to load the server's discovery data | ||
@@ -33,31 +75,11 @@ | ||
| try: | ||
| response = requests.get(team_url) | ||
| except requests.exceptions.ConnectionError: | ||
| succeed, data, verify = self._fetch_wellknown_data(team_url) | ||
| if not succeed: | ||
| succeed, data, verify = self._fetch_wellknown_data(enterprise_url) | ||
| if not succeed: | ||
| raise ExitCLI("Failed to discover configuration for server located at" | ||
| " {}. Check server URL and try again.".format(url)) | ||
| return data, verify | ||
| data = None | ||
| if response.status_code == 200: | ||
| try: | ||
| # If a 200, make sure you get valid JSON back in case you were routed to some other 200 response. | ||
| data = response.json() | ||
| except json.JSONDecodeError: | ||
| pass | ||
| if not data: | ||
| response = requests.get(enterprise_url) | ||
| if response.status_code == 200: | ||
| try: | ||
| # If a 200, make sure you get valid JSON back in case you were routed to some other 200 response. | ||
| data = response.json() | ||
| except json.JSONDecodeError: | ||
| pass | ||
| if not data: | ||
| raise ExitCLI("Failed to discover configuration for server located at" | ||
| " {} ({}). Check server URL and try again.".format(url, response.status_code)) | ||
| return data | ||
| def add_server(self, url): | ||
@@ -72,3 +94,3 @@ """Method to discover a server's configuration and add it to the local configured servers | ||
| """ | ||
| server_data = self._discover_server(url) | ||
| server_data, verify = self._discover_server(url) | ||
@@ -90,3 +112,3 @@ # Ensure core URLS have trailing slashes to standardize within codebase | ||
| # Fetch Auth configuration | ||
| response = requests.get(server_data['auth_config_url']) | ||
| response = requests.get(server_data['auth_config_url'], verify=verify) | ||
| if response.status_code != 200: | ||
@@ -93,0 +115,0 @@ raise ExitCLI("Failed to load auth configuration " |
@@ -10,12 +10,12 @@ import pytest | ||
| from gigantumcli.dockerinterface import DockerInterface | ||
| from gigantumcli.actions import start, install | ||
| from gigantumcli.actions import start, install, update | ||
| @pytest.fixture() | ||
| def fixture_remove_busybox(): | ||
| """Fixture start fake project and client containerss""" | ||
| def fixture_remove_client(): | ||
| """Fixture start fake project and client containers""" | ||
| docker = DockerInterface() | ||
| try: | ||
| # Check to see if the image has already been pulled | ||
| img = docker.client.images.get('busybox') | ||
| img = docker.client.images.get('gigantum/labmanager:latest') | ||
| docker.client.images.remove(img.id, force=True) | ||
@@ -58,3 +58,3 @@ except ImageNotFound: | ||
| def test_install(self, fixture_remove_busybox): | ||
| def test_update(self, fixture_remove_client): | ||
| docker = DockerInterface() | ||
@@ -65,3 +65,3 @@ | ||
| # Check to see if the image has already been pulled | ||
| docker.client.images.get('busybox') | ||
| docker.client.images.get('gigantum/labmanager:latest') | ||
| assert "Image should not exist" | ||
@@ -71,11 +71,35 @@ except ImageNotFound: | ||
| install('busybox') | ||
| # Pull old image | ||
| old_tag = "55f05c26" | ||
| docker.client.images.pull("gigantum/labmanager", old_tag) | ||
| docker.client.api.tag('{}:{}'.format("gigantum/labmanager", old_tag), "gigantum/labmanager", 'latest') | ||
| update("gigantum/labmanager", accept_confirmation=True) | ||
| # Latest should be a new image | ||
| current_image = docker.client.images.get("{}:latest".format("gigantum/labmanager")) | ||
| short_id = current_image.short_id.split(':')[1] | ||
| print(short_id) | ||
| assert old_tag != short_id | ||
| def test_install(self, fixture_remove_client): | ||
| docker = DockerInterface() | ||
| # image should exist not exist before install | ||
| try: | ||
| # Check to see if the image has already been pulled | ||
| docker.client.images.get('gigantum/labmanager:latest') | ||
| assert "Image should not exist" | ||
| except ImageNotFound: | ||
| pass | ||
| install('gigantum/labmanager') | ||
| # image should exist after install | ||
| docker = DockerInterface() | ||
| docker.client.images.get('busybox') | ||
| docker.client.images.get('gigantum/labmanager') | ||
| # Calling again should exit with a message since already installed | ||
| with pytest.raises(ExitCLI): | ||
| install('busybox') | ||
| install('gigantum/labmanager') | ||
@@ -82,0 +106,0 @@ @pytest.mark.skipif(getpass.getuser() == 'circleci', reason="Cannot run this test in CircleCI, needs access " |
@@ -45,2 +45,7 @@ import pytest | ||
| def test_get_latest_tag(self, fixture_changelog_data): | ||
| """Test checking if an update is available""" | ||
| cl = ChangeLog() | ||
| assert cl.latest_tag() == "abcdef" | ||
| def test_get_changelog(self, fixture_changelog_data): | ||
@@ -47,0 +52,0 @@ """Test getting a changelog string""" |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: gigantum | ||
| Version: 1.2.0 | ||
| Version: 1.2.1 | ||
| Summary: CLI for the Gigantum Platform | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/gigantum/gigantum-cli |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
103371
2.89%1314
5.04%