Skip to content

Commit 212a942

Browse files
committed
Merge branch 'master' into issue1921
2 parents c3a4d31 + 5c08bac commit 212a942

File tree

12 files changed

+46
-10
lines changed

12 files changed

+46
-10
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ dist/*
1515
.cache
1616
.idea
1717
.pytest_cache/*
18-
slcli

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ is equivalent to
9898
9999
$ slcli -vvv --format=json vs list
100100
101+
101102
Getting Help
102103
------------
103104
Bugs and feature requests about this library should have a `GitHub issue <https://github.com/softlayer/softlayer-python/issues>`_ opened about them.
@@ -110,6 +111,12 @@ Examples
110111

111112
A curated list of examples on how to use this library can be found at `SLDN <https://softlayer.github.io/python/>`_
112113

114+
Development
115+
-----------
116+
To get started working with this project please read the `CONTRIBUTING <https://github.com/softlayer/softlayer-python/blob/master/CONTRIBUTING.md>`_ document.
117+
118+
You can quickly test local changes by running the './slcli' file, which will load the local softlayer-python code instead of the system's softlayer-python codebase.
119+
113120
Debugging
114121
---------
115122
To get the exact API call that this library makes, you can do the following.

SoftLayer/CLI/cdn/purge.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Purge cached files from all edge nodes."""
22
# :license: MIT, see LICENSE for more details.
3+
import datetime
34

45
import click
56

@@ -28,8 +29,9 @@ def cli(env, unique_id, path):
2829
table = formatting.Table(['Date', 'Path', 'Saved', 'Status'])
2930

3031
for data in result:
32+
date = datetime.datetime.fromtimestamp(int(data['date']))
3133
table.add_row([
32-
data['date'],
34+
date,
3335
data['path'],
3436
data['saved'],
3537
data['status']

SoftLayer/CLI/event_log/get.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import exceptions
8+
from SoftLayer import exceptions
99
from SoftLayer import utils
1010

1111

@@ -40,6 +40,7 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada
4040
request_filter = event_mgr.build_filter(date_min, date_max, obj_event, obj_id, obj_type, utc_offset)
4141
logs = event_mgr.get_event_logs(request_filter)
4242
log_time = "%Y-%m-%dT%H:%M:%S.%f%z"
43+
# A list of IDs that we have looked up user information about.
4344
user_data = {}
4445

4546
if metadata:
@@ -59,9 +60,11 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada
5960
if username is None:
6061
try:
6162
username = user_mgr.get_user(log['userId'], "mask[username]")['username']
62-
user_data[log['userId']] = username
63+
# Some users might not be able to access information about this specific userId
6364
except exceptions.SoftLayerAPIError:
6465
username = log['userId']
66+
# This keeps track of any users we asked the API about, so we can make fewer calls.
67+
user_data[log['userId']] = username
6568
user = username
6669

6770
if metadata:

SoftLayer/managers/cdn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def purge_content(self, unique_id, path):
140140
:param str path: A string of url or path that should be purged.
141141
:returns: A Container_Network_CdnMarketplace_Configuration_Cache_Purge array object
142142
"""
143-
143+
path = f"/{path}"
144144
return self.cdn_purge.createPurge(unique_id, path)
145145

146146
def get_usage_metrics(self, unique_id, history=30, frequency="aggregate"):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
'prompt_toolkit >= 2',
4141
'pygments >= 2.0.0',
4242
'urllib3 >= 1.24',
43-
'rich == 13.3.3'
43+
'rich == 13.3.4'
4444
],
4545
keywords=['softlayer', 'cloud', 'slcli'],
4646
classifiers=[

slcli

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!python
2+
# The above might need to be edited to your path to python3
3+
import re
4+
import sys
5+
6+
from SoftLayer.CLI.core import main
7+
8+
if __name__ == '__main__':
9+
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
10+
# print("arvs[0] = %s" % sys.argv[0])
11+
sys.exit(main())

tests/CLI/modules/event_log_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import json
88

9+
from SoftLayer import SoftLayerAPIError
910
from SoftLayer import testing
1011

1112

@@ -91,3 +92,16 @@ def test_get_unlimited_events(self):
9192
self.assert_no_fail(result)
9293
self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
9394
self.assertEqual(8, result.output.count("\n"))
95+
96+
def test_issues1905(self):
97+
"""https://github.com/softlayer/softlayer-python/issues/1905"""
98+
getUser = self.set_mock('SoftLayer_User_Customer', 'getObject')
99+
getUser.side_effect = SoftLayerAPIError(
100+
"SoftLayer_Exception_PermissionDenied",
101+
"You do not have permission to access this user")
102+
result = self.run_command(['event-log', 'get', '-l -1'])
103+
self.assert_no_fail(result)
104+
self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
105+
self.assert_called_with('SoftLayer_User_Customer', 'getObject', identifier=400)
106+
user_calls = self.calls('SoftLayer_User_Customer', 'getObject')
107+
self.assertEqual(1, len(user_calls))

tests/CLI/modules/sshkey_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_print_key(self):
118118
{'id': 1234, 'label': 'label', 'notes': 'notes'})
119119

120120
def test_print_key_file(self):
121-
if(sys.platform.startswith("win")):
121+
if (sys.platform.startswith("win")):
122122
self.skipTest("Test doesn't work in Windows")
123123
with tempfile.NamedTemporaryFile() as sshkey_file:
124124
service = self.client['Security_Ssh_Key']

tests/CLI/modules/vs/vs_create_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def test_create_vs_no_confirm(self, confirm_mock):
693693
self.assertEqual(result.exit_code, 2)
694694

695695
def test_create_vs_export(self):
696-
if(sys.platform.startswith("win")):
696+
if (sys.platform.startswith("win")):
697697
self.skipTest("Test doesn't work in Windows")
698698
with tempfile.NamedTemporaryFile() as config_file:
699699
result = self.run_command(['vs', 'create', '--hostname', 'TEST', '--export', config_file.name,

0 commit comments

Comments
 (0)