def handleList(self, confInfo): import boto.sqs import boto.exception km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) aws_account = self.callerArgs['aws_account'][0] or "default" acct = km.get_accesskey(name=aws_account) if not acct: raise Exception("No AWS Account is configured. Setup App first.") sqs_conn = connect_sqs(self.callerArgs['aws_region'][0], acct.key_id, acct.secret_key, self.getSessionKey()) if sqs_conn is None: raise Exception("Invalid SQS Queue Region: {}".format(self.callerArgs['aws_region'][0])) q_names = [] try: q_list = sqs_conn.get_all_queues() if q_list: for q in q_list: q_names.append(q.name) except boto.exception.SQSError as e: if e.status == 403 and e.reason == 'Forbidden': if e.error_code == 'InvalidClientId': raise Exception("Authentication Key ID is invalid. Check App Setup.") elif e.error_code == 'SignatureDoesNotMatch': raise Exception("Authentication Secret Key is invalid. Check App Setup.") except Exception as e: raise Exception("Failed AWS Authentication: {}: {} {} ({}): {}".format( type(e).__name__, e.status, e.reason, e.error_code, e.error_message)) confInfo['SqsQueueNamesResult'].append('sqs_queue_names', q_names)
def handleEdit(self, confInfo): logger.info("get config info: " + str(self.callerArgs)) # name = self.callerArgs.name name = (self.callerArgs.data['fname'][0] or "").strip() key_id = (self.callerArgs.data['key_id'][0] or "").strip() secret_key = (self.callerArgs.data['secret_key'][0] or "").strip() logger.info("handle add name {}, key id {}, secret_key: {}".format( name, key_id, secret_key)) name = name.strip() if name == "": logger.info("the name field is empty, ignore the request.") return if key_id == "": logger.error("raise exceptions, because key id is empty") raise Exception("Invalid Data for fields: Key Id") # filter name's invalid character name2 = "".join( [c if c.isalnum() or c in "- _," else '' for c in name]).strip() if name != name2: logger.error("raise exceptions, because data is invalid: name=" + name) raise Exception("Invalid Data for fields: Account Name") # add or update from taaws.aws_accesskeys import AwsAccessKeyManager km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) km.set_accesskey(key_id=key_id, secret_key=secret_key, name=name)
def handleList(self, confInfo): km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) aws_account = self.callerArgs['aws_account'][0] if self.callerArgs[ 'aws_account'] is not None else "" if not aws_account: confInfo['S3BucketsResult'].append('buckets', []) return acct = km.get_accesskey(name=aws_account) if not acct: raise Exception(aws_account + " selected is incorrect, Setup App first.") connection = connect_s3(acct.key_id, acct.secret_key, self.getSessionKey()) rs = connection.get_all_buckets() rlist = [] for r in rs: rlist.append(r.name) confInfo['S3BucketsResult'].append('buckets', rlist)
def get_access_key_pwd_real(session_key="", aws_account_name="default"): if not AwsAccessKeyManager: raise Exception("Access Key Manager needed is not imported successfully") km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, session_key) logger.info("get account name: " + aws_account_name) acct = km.get_accesskey(name=aws_account_name) if not acct: # No recovering from this... logger.log(logging.FATAL, "No AWS Account is configured.") raise Exception("No AWS Account is configured.") return acct.key_id, acct.secret_key
def handleList(self, confInfo): km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) aws_account = self.callerArgs['aws_account'][0] or "default" acct = km.get_accesskey(name=aws_account) if not acct: raise Exception("No AWS Account is configured. Setup App first.") namespaces = taaws.s3util.list_cloudwatch_namespaces( self.callerArgs['aws_region'][0], acct.key_id, acct.secret_key, self.getSessionKey()) confInfo['NameSpacesResult'].append('metric_namespace', namespaces)
def handleList(self, confInfo): km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) aws_account = self.callerArgs['aws_account'][0] or "default" acct = km.get_accesskey(name=aws_account) if not acct: raise Exception("No AWS Account is configured. Setup App first.") connection = connect_s3(acct.key_id, acct.secret_key, self.getSessionKey()) bucket = connection.get_bucket(self.callerArgs['bucket_name'][0]) rlist = [] for key in taaws.s3util.get_keys(bucket,recursion_depth=1): rlist.append(key.name) confInfo['S3KeyNamesResult'].append('key_names', rlist)
def handleEdit(self, confInfo): # logger.info("get self info: " + str(self.__dict__)) logger.info("get config info: " + str(self.callerArgs)) # name = self.callerArgs.name name = self.callerArgs.data['fname'][0] key_id = self.callerArgs.data['key_id'][0] delete = self.callerArgs.data['delete'][0] logger.info("handle edit name {}, key id {}, delete: {}".format( name, key_id, delete)) if delete != "1": return # delete key_id from taaws.aws_accesskeys import AwsAccessKeyManager km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) km.delete_accesskey(name=name)
def handleEdit(self, confInfo): km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) key_id = self.callerArgs.data['key_id'][0] key_id = key_id and key_id.strip() or '' secret_key = self.callerArgs.data['secret_key'][0] secret_key = secret_key and secret_key.strip() or '' if not key_id and not secret_key: km.delete_accesskey() else: km.set_accesskey(key_id=key_id, secret_key=secret_key)
def handleList(self, confInfo): km = AwsAccessKeyManager(KEY_NAMESPACE, KEY_OWNER, self.getSessionKey()) acct = km.get_accesskey() confInfo['default_aws_key'].append('key_id', acct and acct.key_id or '') confInfo['default_aws_key'].append('secret_key', acct and acct.secret_key or '')