Skip to content

Commit 1e3d56b

Browse files
author
Vivek Chaudhary
committed
[api] OPSAPS-39252 API endpoint for External Account Configs
1 parent d799c23 commit 1e3d56b

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

python/src/cm_api/endpoints/external_accounts.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
EXTERNAL_ACCOUNT_PATH = "/externalAccounts/%s"
2727
EXTERNAL_ACCOUNT_FETCH_PATH = "/externalAccounts/%s/%s"
28+
EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH = "/externalAccounts/account/%s"
2829

2930
def get_supported_categories(resource_root):
3031
"""
@@ -125,7 +126,6 @@ def delete_external_account(resource_root, name):
125126
EXTERNAL_ACCOUNT_FETCH_PATH % ("delete", name,),
126127
ApiExternalAccount, False)
127128

128-
129129
class ApiExternalAccountCategory(BaseApiObject):
130130
_ATTRIBUTES = {
131131
'name' : None,
@@ -151,7 +151,7 @@ def __str__(self):
151151
return "<ApiExternalAccountType>: %s (categoryName: %s)" % (
152152
self.name, self.typeName)
153153

154-
class ApiExternalAccount(BaseApiObject):
154+
class ApiExternalAccount(BaseApiResource):
155155
_ATTRIBUTES = {
156156
'name' : None,
157157
'displayName' : None,
@@ -163,9 +163,32 @@ class ApiExternalAccount(BaseApiObject):
163163

164164
def __init__(self, resource_root, name=None, displayName=None,
165165
typeName=None, accountConfigs=None):
166-
BaseApiObject.init(self, resource_root, locals())
166+
BaseApiResource.init(self, resource_root, locals())
167167

168168
def __str__(self):
169169
return "<ApiExternalAccount>: %s (typeName: %s)" % (
170170
self.name, self.typeName)
171171

172+
def _path(self):
173+
return EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH % self.name
174+
175+
def get_config(self, view=None):
176+
"""
177+
Retrieve the external account's configuration.
178+
179+
The 'summary' view contains strings as the dictionary values. The full
180+
view contains ApiConfig instances as the values.
181+
182+
@param view: View to materialize ('full' or 'summary')
183+
@return: Dictionary with configuration data.
184+
"""
185+
return self._get_config("config", view)
186+
187+
def update_config(self, config):
188+
"""
189+
Update the external account's configuration.
190+
191+
@param config: Dictionary with configuration to update.
192+
@return: Dictionary with updated configuration.
193+
"""
194+
return self._update_config("config", config)

python/src/cm_api_tests/test_external_accounts.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,33 @@ def chkConfigsEqual(self, expectedConfigs, fetchedConfigs):
158158
self.assertEqual(
159159
fetchedConfigs[expectedConfigs[k].name].value,
160160
expectedConfigs[k].value)
161+
162+
def test_get_acct_config(self):
163+
test_config = self.account.accountConfigs.to_json_dict();
164+
self.resource.expect("GET",
165+
"/externalAccounts/account/%s/config" % self.account.name,
166+
retdata=test_config)
167+
ret = config_to_api_list(self.account.get_config())
168+
for entry in ret['items']:
169+
k = entry['name']
170+
if k == 'aws_secret_key':
171+
self.assertTrue(entry["value"] == 'bar')
172+
elif k == "aws_access_key":
173+
self.assertTrue(entry["value"] == 'foo')
174+
else:
175+
self.assertFailure()
176+
177+
def test_update_acct_config(self):
178+
test_config = config_to_api_list({"aws_secret_key": "bar2", "aws_access_key": "foo"})
179+
update_config = {"aws_secret_key": "bar2"}
180+
self.resource.expect("PUT",
181+
"/externalAccounts/account/%s/config" % self.account.name,
182+
data=config_to_api_list(update_config), retdata=test_config)
183+
ret = self.account.update_config(update_config)
184+
for entry in ret.iteritems():
185+
if entry[0] == 'aws_secret_key':
186+
self.assertTrue(entry[1] == 'bar2')
187+
elif entry[0] == "aws_access_key":
188+
self.assertTrue(entry[1] == 'foo')
189+
else:
190+
self.assertFailure()

0 commit comments

Comments
 (0)