from pyservice.layer import Layer

class ClientAuthLayer(Layer):

    def handle_request(self, context, next):
        client = context["client"]
        key = client._attr("authuser", None)
        pw = client._attr("authpw", None)
        if key is None or pw is None:
            raise ValueError("Must provide authuser and authpw")
        next.handle_request(context)

class ServiceAuthLayer(Layer):

    def handle_request(self, context, next):
        op_input = context["input"]
        key = op_input.get("authuser", None)
        pw = op_input.get("authpw", None)
        if key is None or pw is None:
            raise ValueError("Must provide authuser and authpw")
        next.handle_request(context)
Add sample basic auth layers
Add sample basic auth layers

Not very flexible, these are more meant to be a sample for others
creating Layers.  Given how similar the code is and how basic most
hande_request() methods will be, it might be worth creating something
similar to @contextmanager, so that it's trivial to create a layer from
a single method which only takes context:

@layer_decorator
def auth_layer(context):
# Auth here
yield # This is effectively next.handle_request(context)
# Post call
