Skip to content

Commit 4c7da9b

Browse files
authored
Merge pull request #62 from romeech/implement-hub-token-cmd
Implement 'hub-token' command in apsconnect-cli
2 parents 675b22a + 9effbcf commit 4c7da9b

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ matrix:
1313
sudo: required
1414
python: 3.6
1515
env: BUILD=LINUX
16-
- os: osx
17-
language: generic
18-
env: BUILD=OSX
1916

2017
before_install:
2118
- ./.travis/before_install.sh

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,9 @@ Disable mode with `--disable`.
162162
⇒ apsconnect aps-devel-mode --disable
163163
APS Development mode DISABLED.
164164
```
165+
166+
#### Get Hub token
167+
```
168+
⇒ apsconnect hub-token
169+
ab8719ff-d818-4b6f-8023-0229f768e086
170+
```

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.0
1+
1.11.1

apsconnectcli/apsconnect.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import yaml
1919

2020
from requests import get
21-
from requests.exceptions import Timeout, ConnectionError, SSLError
21+
from requests.exceptions import ConnectionError, SSLError, Timeout
2222

2323
from kubernetes import client, config
2424
from kubernetes.client.rest import ApiException
2525

2626
from apsconnectcli.action_logger import Logger
27-
from apsconnectcli.cluster import read_cluster_certificate, poll_deployment
27+
from apsconnectcli.cluster import poll_deployment, read_cluster_certificate
2828
from apsconnectcli.config import CFG_FILE_PATH, NULL_CFG_INFO
2929
from apsconnectcli.hub import Hub
3030
from apsconnectcli.package import Package
@@ -319,6 +319,10 @@ def info(self):
319319
print(item_name)
320320
print(_check_binding(check_config, get_info))
321321

322+
def hub_token(self):
323+
hub = Hub()
324+
print(hub.hub_id)
325+
322326

323327
def _get_k8s_api_client(config_file=None):
324328
if not config_file:

tests/test_hub.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import sys
12
from unittest import TestCase
23

34
from mock import MagicMock, patch
45

5-
from apsconnectcli.hub import osaapi_raise_for_status, Hub, APS
6+
from apsconnectcli.apsconnect import APSConnectUtil
7+
from apsconnectcli.hub import APS, Hub, osaapi_raise_for_status
8+
9+
if sys.version_info >= (3,):
10+
_BUILTINS_OPEN = 'builtins.open'
11+
_BUILTINS_PRINT = 'builtins.print'
12+
else:
13+
_BUILTINS_OPEN = 'apsconnectcli.apsconnect.open'
14+
_BUILTINS_PRINT = 'apsconnectcli.apsconnect.print'
615

716

817
class OsaApiRaiseForStatusTest(TestCase):
@@ -79,7 +88,7 @@ def test_get_resclass_name_without_unit(self):
7988

8089
def test_hub_init(self):
8190
with patch('apsconnectcli.hub.osaapi'), \
82-
patch('apsconnectcli.hub.APS') as aps_mock, \
91+
patch('apsconnectcli.hub.APS') as aps_mock, \
8392
patch('apsconnectcli.hub.get_config'), \
8493
patch('apsconnectcli.hub.osaapi_raise_for_status'):
8594
resp_mock = MagicMock()
@@ -104,7 +113,7 @@ def test_get_hub_version(self):
104113

105114
def test_hub_incorrect_id(self):
106115
with patch('apsconnectcli.hub.osaapi'), \
107-
patch('apsconnectcli.hub.APS') as aps_mock, \
116+
patch('apsconnectcli.hub.APS') as aps_mock, \
108117
patch('apsconnectcli.hub.get_config'), \
109118
patch('apsconnectcli.hub.osaapi_raise_for_status'), \
110119
patch('apsconnectcli.hub.sys') as sys_mock:
@@ -244,3 +253,17 @@ def test_delete(self):
244253
self.assertEqual(requests_mock.delete.call_args[1].get('headers'), 'token')
245254
self.assertEqual(requests_mock.delete.call_args[1].get('verify'), False)
246255
self.assertEqual(requests_mock.delete.call_args[0][0], 'https://aps_host:aps_port/test')
256+
257+
258+
class TestApsConnectUtilHubCommands(TestCase):
259+
@patch('apsconnectcli.apsconnect.Hub')
260+
def test_hub_token(self, hub_cls):
261+
with patch(_BUILTINS_PRINT) as mock_print:
262+
expected_hub_token = '359b67d3-fdd7-4e90-a891-b909734fb64a'
263+
hub_mock = MagicMock()
264+
hub_mock.hub_id = expected_hub_token
265+
hub_cls.return_value = hub_mock
266+
267+
util = APSConnectUtil()
268+
util.hub_token()
269+
mock_print.assert_called_with(expected_hub_token)

0 commit comments

Comments
 (0)