#!/usr/bin/env python
# encoding: utf-8

from flask import Blueprint, Response, request

from ..helpers import get, error_response, successful_response, require_parameters
from ..core import Ec2stackError
from . import images, instances


DEFAULT = Blueprint('default', __name__)


@DEFAULT.route('/', methods=['POST'])
def index():
    try:
        response_content = _get_action(get('Action', request.form))()
        return successful_response(response_content)
    except Ec2stackError as err:
        return error_response(err.error, err.message)


def _get_action(action):
    actions = {
        'DescribeImages': images.describe,
        'DescribeInstances': instances.describe,
        'RegisterSecretKey': registerSecretKey,
        'RemoveSecretKey': removeSecretKey
    }

    if action in actions:
        return actions[action]
    else:
        raise Ec2stackError(
            'InvalidAction',
            'The action %s is not valid for this web service' % (action)
        )


def registerSecretKey():
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    return error_response(200, 'Not fully implemented yet....')

def removeSecretKey():
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    return error_response(200, 'Not fully implemented yet....')


@DEFAULT.app_errorhandler(404)
def not_found(err):
    return Response('Not Found', status=404, mimetype='text/html')


@DEFAULT.app_errorhandler(400)
def bad_request(err):
    return Response('Bad Request', status=404, mimetype='text/html')

@@ -198,16 +198,45 @@
 ckError%0A
+from ..services import USERS%0A
 from . i
@@ -1109,151 +1109,877 @@
     
-return error_response(200, 'Not fully implemented yet....')%0A%0Adef removeSecretKey():%0A    require_parameters(%7B'AWSAccessKeyId', 'AWSSecretKey'%7D)%0A
+found_user = USERS.get(get('AWSAccessKeyId', request.form))%0A    if found_user is None:%0A        USERS.create(%0A            apikey=get('AWSAccessKeyId', request.form),%0A            secretkey=get('AWSSecretKey', request.form)%0A        )%0A        return error_response(200, 'Not fully implemented yet....'%0A                                   'User might of been registered...')%0A    else:%0A        raise Ec2stackError(%0A            'DuplicateUser',%0A            'The given AWSAccessKeyId is already registered'%0A        )%0A%0A%0Adef removeSecretKey():%0A    require_parameters(%7B'AWSAccessKeyId', 'AWSSecretKey'%7D)%0A    found_user = USERS.get(get('AWSAccessKeyId', request.form))%0A    if found_user is not None:%0A        USERS.delete(found_user)%0A        return error_response(200, 'Not fully implemented yet....'%0A                                   'User might of been deleted...')%0A    else:%0A    
     

Add basic functions for the registering and deleting the secret key. Bit rough, needs reviewal