This repository was archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsecretkey_manager.py
More file actions
96 lines (76 loc) · 2.51 KB
/
secretkey_manager.py
File metadata and controls
96 lines (76 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# encoding: utf-8
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
"""This module provides functions to register AWSAccessKeyIds and AWSSecretKeys.
"""
import argparse
from xml.dom.minidom import parseString as xmlparse
import requests
def _generate_args(description):
"""
Generates the base application with required parameters.
@param description: Description of the command.
@return: The args associated with the command.
"""
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():
"""
Entry point for registering an api key and secret key.
"""
args = _generate_args(
'Command line utility for registering a secret key with ec2stack'
)
args['Action'] = 'RegisterSecretKey'
_execute_request(args)
def remove():
"""
Entry point for removing an api key and secret key.
"""
args = _generate_args(
'Command line utility for removing a secret key from ec2stack'
)
args['Action'] = 'RemoveSecretKey'
_execute_request(args)
def _execute_request(args):
"""
Executes the register/remove request.
@param args: Request payload.
"""
host = args.pop('ec2stack_server_address')
response = requests.post(host, args)
response = xmlparse(response.text)
message = response.getElementsByTagName('Message')[0].firstChild.nodeValue
print message