Skip to content

Commit

Permalink
[api] OPSAPS-39252 API endpoint for External Account Configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Chaudhary committed Feb 17, 2017
1 parent d799c23 commit 1e3d56b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
29 changes: 26 additions & 3 deletions python/src/cm_api/endpoints/external_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

EXTERNAL_ACCOUNT_PATH = "/externalAccounts/%s"
EXTERNAL_ACCOUNT_FETCH_PATH = "/externalAccounts/%s/%s"
EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH = "/externalAccounts/account/%s"

def get_supported_categories(resource_root):
"""
Expand Down Expand Up @@ -125,7 +126,6 @@ def delete_external_account(resource_root, name):
EXTERNAL_ACCOUNT_FETCH_PATH % ("delete", name,),
ApiExternalAccount, False)


class ApiExternalAccountCategory(BaseApiObject):
_ATTRIBUTES = {
'name' : None,
Expand All @@ -151,7 +151,7 @@ def __str__(self):
return "<ApiExternalAccountType>: %s (categoryName: %s)" % (
self.name, self.typeName)

class ApiExternalAccount(BaseApiObject):
class ApiExternalAccount(BaseApiResource):
_ATTRIBUTES = {
'name' : None,
'displayName' : None,
Expand All @@ -163,9 +163,32 @@ class ApiExternalAccount(BaseApiObject):

def __init__(self, resource_root, name=None, displayName=None,
typeName=None, accountConfigs=None):
BaseApiObject.init(self, resource_root, locals())
BaseApiResource.init(self, resource_root, locals())

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

def _path(self):
return EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH % self.name

def get_config(self, view=None):
"""
Retrieve the external account's configuration.
The 'summary' view contains strings as the dictionary values. The full
view contains ApiConfig instances as the values.
@param view: View to materialize ('full' or 'summary')
@return: Dictionary with configuration data.
"""
return self._get_config("config", view)

def update_config(self, config):
"""
Update the external account's configuration.
@param config: Dictionary with configuration to update.
@return: Dictionary with updated configuration.
"""
return self._update_config("config", config)
30 changes: 30 additions & 0 deletions python/src/cm_api_tests/test_external_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,33 @@ def chkConfigsEqual(self, expectedConfigs, fetchedConfigs):
self.assertEqual(
fetchedConfigs[expectedConfigs[k].name].value,
expectedConfigs[k].value)

def test_get_acct_config(self):
test_config = self.account.accountConfigs.to_json_dict();
self.resource.expect("GET",
"/externalAccounts/account/%s/config" % self.account.name,
retdata=test_config)
ret = config_to_api_list(self.account.get_config())
for entry in ret['items']:
k = entry['name']
if k == 'aws_secret_key':
self.assertTrue(entry["value"] == 'bar')
elif k == "aws_access_key":
self.assertTrue(entry["value"] == 'foo')
else:
self.assertFailure()

def test_update_acct_config(self):
test_config = config_to_api_list({"aws_secret_key": "bar2", "aws_access_key": "foo"})
update_config = {"aws_secret_key": "bar2"}
self.resource.expect("PUT",
"/externalAccounts/account/%s/config" % self.account.name,
data=config_to_api_list(update_config), retdata=test_config)
ret = self.account.update_config(update_config)
for entry in ret.iteritems():
if entry[0] == 'aws_secret_key':
self.assertTrue(entry[1] == 'bar2')
elif entry[0] == "aws_access_key":
self.assertTrue(entry[1] == 'foo')
else:
self.assertFailure()

0 comments on commit 1e3d56b

Please sign in to comment.