def update_aws_auth_params(): """ Updates the AWS authentication parameters according to config :return: True if new params allow successful authentication. False otherwise """ access_key_id = ConfigService.get_config_value( ['cnc', 'aws_config', 'aws_access_key_id'], False, True) secret_access_key = ConfigService.get_config_value( ['cnc', 'aws_config', 'aws_secret_access_key'], False, True) if (access_key_id != AwsService.access_key_id) or ( secret_access_key != AwsService.secret_access_key): AwsService.set_auth_params(access_key_id, secret_access_key) RemoteRunAwsService.is_auth = AwsService.test_client() AwsService.set_region(RemoteRunAwsService.aws_instance.region) return RemoteRunAwsService.is_auth
def get(self): action = request.args.get('action') if action == 'list_aws': is_aws = RemoteRunAwsService.is_running_on_aws() resp = {'is_aws': is_aws} if is_aws: is_auth = RemoteRunAwsService.update_aws_auth_params() resp['auth'] = is_auth if is_auth: resp['instances'] = AwsService.get_instances() return jsonify(resp) return {}
def get(self): action = request.args.get('action') if action == 'list_aws': is_aws = RemoteRunAwsService.is_running_on_aws() resp = {'is_aws': is_aws} if is_aws: try: resp['instances'] = AwsService.get_instances() except NoCredentialsError as e: resp['error'] = NO_CREDS_ERROR_FORMAT.format(e.message) return jsonify(resp) except ClientError as e: resp['error'] = CLIENT_ERROR_FORMAT.format(e.message) return jsonify(resp) return jsonify(resp) return {}
def __init__(self, is_linux, instance_id, region=None): super(AwsCmdRunner, self).__init__(is_linux) self.instance_id = instance_id self.region = region self.ssm = AwsService.get_client('ssm', region)
def update_aws_region_authless(): """ Updates the AWS region without auth params (via IAM role) """ AwsService.set_region(RemoteRunAwsService.aws_instance.region)