Skip to content

Commit 8bc29f6

Browse files
Merge pull request #1668 from caberos/issue1667
new feature block object-storage permissions command
2 parents 54ddf9c + 55821e0 commit 8bc29f6

File tree

7 files changed

+126
-1
lines changed

7 files changed

+126
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Display permission details for a cloud object storage."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('object_id')
12+
@environment.pass_env
13+
def cli(env, object_id):
14+
"""Display permission details for a cloud object storage."""
15+
16+
block_manager = SoftLayer.BlockStorageManager(env.client)
17+
18+
cloud = block_manager.get_network_message_delivery_accounts(object_id)
19+
end_points = block_manager.get_end_points(object_id)
20+
21+
table = formatting.Table(['Name', 'Value'])
22+
23+
table_credentials = formatting.Table(['Id', 'Access Key ID', 'Secret Access Key', 'Description'])
24+
25+
for credential in cloud.get('credentials'):
26+
table_credentials.add_row([credential.get('id'),
27+
credential.get('username'),
28+
credential.get('password'),
29+
credential['type']['description']])
30+
31+
table_url = formatting.Table(['Region',
32+
'Location',
33+
'Type',
34+
'URL'])
35+
for end_point in end_points:
36+
table_url.add_row([end_point.get('region') or '',
37+
end_point.get('location') or '',
38+
end_point.get('type'),
39+
end_point.get('url'), ])
40+
41+
table.add_row(['UUID', cloud.get('uuid')])
42+
table.add_row(['Credentials', table_credentials])
43+
table.add_row(['EndPoint URL´s', table_url])
44+
env.fout(table)

SoftLayer/CLI/routes.py

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129129
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
130130
('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),
131+
('block:object-storage-permission', 'SoftLayer.CLI.block.object_storage_permission:cli'),
131132

132133
('email', 'SoftLayer.CLI.email'),
133134
('email:list', 'SoftLayer.CLI.email.list:cli'),

SoftLayer/fixtures/SoftLayer_Network_Storage_Hub_Cleversafe_Account.py

+41
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,47 @@
4747
}
4848
]
4949

50+
getEndpoints = [
51+
{
52+
'legacy': False,
53+
'region': 'us-geo',
54+
'type': 'public',
55+
'url': 's3.us.cloud-object-storage.appdomain.cloud'
56+
},
57+
{
58+
'legacy': False,
59+
'region': 'us-geo',
60+
'type': 'private',
61+
'url': 's3.private.us.cloud-object-storage.appdomain.cloud'
62+
}
63+
]
5064
getCredentialLimit = 2
5165

5266
credentialDelete = True
67+
68+
getObject = {
69+
'id': 123456,
70+
'username': 'SLOSC307608-1',
71+
'credentials': [
72+
{
73+
'id': 1933496,
74+
'password': 'Um1Bp420FIFNvAg2QHjn5Sci2c2x4RNDXpVDDvnf',
75+
'username': 'Kv9aNIhtNa7ZRceCTgep',
76+
'type': {
77+
'description': 'A credential for generating S3 Compatible Signatures.',
78+
'keyName': 'S3_COMPATIBLE_SIGNATURE'
79+
}
80+
},
81+
{
82+
83+
'id': 1732820,
84+
'password': 'q6NtwqeuXDaRqGc0Jrugg2sDgbatyNsoN9sPEmjo',
85+
'username': '252r9BN8ibuDSQAXLOeL',
86+
'type': {
87+
'description': 'A credential for generating S3 Compatible Signatures.',
88+
'keyName': 'S3_COMPATIBLE_SIGNATURE',
89+
}
90+
}
91+
],
92+
'uuid': '01c449c484ae4a58a42d9b79d4c5e4ed'
93+
}

SoftLayer/managers/storage.py

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from SoftLayer.managers import storage_utils
1010
from SoftLayer import utils
1111

12+
1213
# pylint: disable=too-many-public-methods
1314

1415

@@ -586,3 +587,22 @@ def convert_dupe_status(self, volume_id):
586587
return self.client.call('Network_Storage',
587588
'getDuplicateConversionStatus',
588589
id=volume_id)
590+
591+
def get_network_message_delivery_accounts(self, object_id):
592+
"""Return object data of the cloud storage.
593+
594+
:param object_id cloud object storage identifier
595+
Returns: Get instances
596+
"""
597+
object_mask = 'mask[uuid,credentials]'
598+
return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account',
599+
'getObject', mask=object_mask, id=object_id)
600+
601+
def get_end_points(self, object_id):
602+
"""Returns a collection of endpoint URLs available to this IBM Cloud Object Storage account.
603+
604+
:param object_id cloud object storage identifier
605+
Returns: Returns a collection of endpoint URLs.
606+
"""
607+
return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account',
608+
'getEndpoints', id=object_id)

docs/cli/block.rst

+4
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ Block Commands
168168
:prog: block duplicate-convert-status
169169
:show-nested:
170170

171+
.. click:: SoftLayer.CLI.block.object_storage_permission:cli
172+
:prog: block object-storage-permission
173+
:show-nested:
174+

tests/CLI/modules/block_tests.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def test_snapshot_restore(self):
444444

445445
self.assert_no_fail(result)
446446
self.assertEqual(result.output, 'Block volume 12345678 is being'
447-
' restored using snapshot 87654321\n')
447+
' restored using snapshot 87654321\n')
448448

449449
@mock.patch('SoftLayer.BlockStorageManager.order_snapshot_space')
450450
def test_snapshot_order_order_not_placed(self, order_mock):
@@ -831,3 +831,10 @@ def test_object_details(self):
831831

832832
self.assert_no_fail(result)
833833
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')
834+
835+
def test_object_permissions(self):
836+
result = self.run_command(['block', 'object-storage-permission', '1234'])
837+
838+
self.assert_no_fail(result)
839+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getObject')
840+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getEndpoints')

tests/managers/block_tests.py

+8
Original file line numberDiff line numberDiff line change
@@ -1123,3 +1123,11 @@ def test_get_cloud_list(self):
11231123
def test_get_bucket(self):
11241124
self.block.get_buckets(1234)
11251125
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')
1126+
1127+
def test_get_cloud_endPoints(self):
1128+
self.block.get_end_points(123456)
1129+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getEndpoints')
1130+
1131+
def test_get_cloud_object(self):
1132+
self.block.get_network_message_delivery_accounts(123456)
1133+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getObject')

0 commit comments

Comments
 (0)