Coder Social home page Coder Social logo

gotham-middleware-aws-sig-verify's Introduction

Gotham middleware for AWS SigV4 verification

The gotham_middleware_aws_sig_verify crate integrates AWS SigV4 verification (from aws_sig_verify) into the Gotham web framework.

Assuming you have a function get_signing_key that can return signing keys given AWS access keys (and optionally tokens), integration would be done similarly to:

use gotham;
use gotham::pipeline::new_pipeline;
use gotham::pipeline::single::single_pipeline;
use gotham::router::builder::{build_router, DefineSingleRoute, DrawRoutes};
use gotham::router::Router;
use gotham::state::State;
use gotham_middleware_aws_sig_verify::{AWSSigV4Verifier, SigningKeyKind, SignatureError};
use http::status::StatusCode;
use hyper::{Body, Response};

const SERVICE: &str = "myservice";
const REGION: &str = "local";

fn router() -> Router {
    let verifier = AWSSigV4Verifier::new(get_signing_key, SERVICE, REGION);
    let (chain, pipelines) = single_pipeline(new_pipeline().add(verifier).build());
    build_router(chain, pipelines, |route| {
        route.get("/").to(my_handler);
    })
}

fn my_handler(state: State) -> (State, Response<Body>) {
    let response: Response<Body> = Response::builder()
        .header("Content-Type", "text/plain; charset=utf-8")
        .status(StatusCode::OK)
        .body(Body::from("OK"))
        .unwrap();

    (state, response)
}

fn get_signing_key(
    kind: SigningKeyKind,
    access_key_id: &str,
    session_token: Option<&str>,
    req_date_opt: Option<&str>,
    region_opt: Option<&str>,
    service_opt: Option<&str>
) -> Result<Vec<u8>, SignatureError> {
    ...
}

pub fn main() {
    gotham::start("127.0.0.1:8080", router())
}

gotham-middleware-aws-sig-verify's People

Contributors

dacut avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.