Skip to content
Permalink
Browse files
closes #43 Create wrapper for registerSecretKey
  • Loading branch information
imduffy15 committed Mar 5, 2014
1 parent 14d2f8e commit b1f50cf2b9225d8dee4060521731362275a3081e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
@@ -17,7 +17,7 @@ def _create_config_folder():
config_folder = os.path.join(os.path.expanduser('~'), '.ec2stack')
if not os.path.exists(config_folder):
os.makedirs(config_folder)
os.chmod(config_folder, 0700)
os.chmod(config_folder, 0o700)
return config_folder


@@ -81,8 +81,9 @@ def register_secret_key():
return {
'template_name_or_list': 'secretkey.xml',
'response_type': 'RegisterSecretKeyResponse',
'apikey': get('AWSAccessKeyId'),
'secretkey': get('AWSSecretKey'),
'AWSAccessKeyId': get('AWSAccessKeyId'),
'AWSSecretKey': get('AWSSecretKey'),
'Message': 'Successfully Registered!'
}
else:
raise Ec2stackError(
@@ -103,8 +104,9 @@ def remove_secret_key():
return {
'template_name_or_list': 'secretkey.xml',
'response_type': 'RemoveSecretKeyResponse',
'apikey': get('AWSAccessKeyId'),
'secretkey': get('AWSSecretKey'),
'AWSAccessKeyId': get('AWSAccessKeyId'),
'AWSSecretKey': get('AWSSecretKey'),
'Message': 'Successfully removed!'
}
else:
raise Ec2stackError(
@@ -0,0 +1,56 @@
#!/usr/bin/env python
# encoding: utf-8

import argparse
import requests

from xml.dom.minidom import parseString as xmlparse


def _generate_args(description):
parser = argparse.ArgumentParser(
description=description
)

parser.add_argument(
'ec2stack_server_address',
help='The address of the ec2stack server http://localhost:5000'
)

parser.add_argument(
'AWSAccessKeyId',
help='Your Cloudstack API Key'
)

parser.add_argument(
'AWSSecretKey',
help='Your Cloudstack Secret Key'
)

args = parser.parse_args()

return vars(args)


def register():
args = _generate_args(
'Command line utility for registering a secret key with ec2stack'
)
args['Action'] = 'RegisterSecretKey'
_execute_request(args)


def remove():
args = _generate_args(
'Command line utility for removing a secret key from ec2stack'
)
args['Action'] = 'RemoveSecretKey'
_execute_request(args)


def _execute_request(args):
host = args.pop('ec2stack_server_address')
response = requests.post(host, args)
response = xmlparse(response.text)
message = response.getElementsByTagName('Message')[0].firstChild.nodeValue
print message
@@ -1,5 +1,6 @@
{% extends "response.xml" %}
{% block response_content %}
<apiKey>{{apikey}}</apiKey>
<secretKey>{{secretkey}}</secretKey>
{% endblock %}
<AWSAccessKeyId>{{AWSAccessKeyId}}</AWSAccessKeyId>
<AWSSecretKey>{{AWSSecretKey}}</AWSSecretKey>
<Message>{{Message}}</Message>
{% endblock %}
@@ -70,5 +70,7 @@ def read_file(name):
[console_scripts]
ec2stack = ec2stack.__main__:main
ec2stack-configure = ec2stack.configure:main
ec2stack-register = ec2stack.secretkey_manager:register
ec2stack-remove = ec2stack.secretkey_manager:remove
""",
)

0 comments on commit b1f50cf

Please sign in to comment.