Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

[WIP] API Gateway Data Model #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ license = "MIT/Apache-2.0"
exclude = [".gitignore", "builder/**", "examples/**", "test/**"]

[dependencies]
serde = "1.0"
serde_json = "1.0"
chrono = { version = "0.4", features = ["serde"] }
cpython = { version = "0.1", default-features = false }
cpython-json = { version = "0.2", default-features = false }
error-chain = { version = "0.11.0", optional = true }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_qs = "0.4"
serde-aux = "0.5"

[features]
default = ["cpython/python3-sys"]

53 changes: 53 additions & 0 deletions src/data/apigateway/auth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// API Gateway Custom Authorizer Events
use super::*;

use data::apigateway::HttpEventRequestContext;

use std::fmt;

/// The type of an `AuthEvent`.
#[serde(rename_all="SCREAMING_SNAKE_CASE")]
#[derive(Debug,Eq,PartialEq,Serialize,Deserialize)]
pub enum AuthEventType {
Request,
Token
}

/// An API Gateway authorization event for a custom Lambda authorizer.
#[serde(rename_all="camelCase")]
#[derive(Serialize,Deserialize)]
pub struct AuthEvent {
#[serde(default)]
pub headers: BTreeMap<String, String>,
pub http_method: String,
pub method_arn: String,
pub path: String,
#[serde(default)]
pub path_parameters: BTreeMap<String, String>,
#[serde(default)]
pub query_string_parameters: BTreeMap<String, String>,
pub resource: String,
pub request_context: HttpEventRequestContext,
#[serde(default)]
pub stage_variables: BTreeMap<String, String>,
#[serde(rename="type")]
pub event_type: AuthEventType,
}

/// The response effect for a given `AuthEvent`.
#[derive(Serialize,Deserialize)]
pub enum AuthEffect {
/// Allow access to the underlying resource.
Allow,
/// Reject access to the underlying resource.
Deny
}

impl fmt::Display for AuthEffect {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
AuthEffect::Allow => write!(f, "Allow"),
AuthEffect::Deny => write!(f, "Deny")
}
}
}
26 changes: 26 additions & 0 deletions src/data/apigateway/fixtures/authorize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"headers": null,
"httpMethod": "GET",
"methodArn": "arn:aws:execute-api:us-east-1:111111111111:rest-api-id/null/GET/",
"path": "/",
"pathParameters": {},
"queryStringParameters": {},
"requestContext": {
"accountId": "111111111111",
"apiId": "rest-api-id",
"httpMethod": "GET",
"identity": {
"apiKey": "test-invoke-api-key",
"apiKeyId": "test-invoke-api-key-id",
"sourceIp": "test-invoke-source-ip"
},
"path": "/",
"requestId": "test-invoke-request",
"resourceId": "test-invoke-resource-id",
"resourcePath": "/",
"stage": "test-invoke-stage"
},
"resource": "/",
"stageVariables": {},
"type": "REQUEST"
}
53 changes: 53 additions & 0 deletions src/data/apigateway/fixtures/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"body": null,
"headers": {
"Accept": "*/*",
"CloudFront-Forwarded-Proto": "https",
"CloudFront-Is-Desktop-Viewer": "true",
"CloudFront-Is-Mobile-Viewer": "false",
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Host": "example.com",
"User-Agent": "curl/7.47.0",
"Via": "1.1 deadbeefcafebabebeefbeefdeaddead.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "J0YMU-brgNv9hzadv_rjnICwfLCd4-IYjVz55KdZS6fuGB6xkU65WA==",
"X-Amzn-Trace-Id": "Root=1-5a9095d0-2459dc8c2eead5b445840ca0",
"X-Forwarded-For": "127.0.0.1, 127.0.0.1",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"httpMethod": "GET",
"isBase64Encoded": false,
"path": "/echo.json",
"pathParameters": null,
"queryStringParameters": null,
"requestContext": {
"accountId": "123456789012",
"apiId": "smddwihyy9",
"httpMethod": "GET",
"identity": {
"accessKey": null,
"accountId": null,
"caller": null,
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityId": null,
"cognitoIdentityPoolId": null,
"sourceIp": "127.0.0.1",
"user": null,
"userAgent": "curl/7.47.0",
"userArn": null
},
"path": "/echo.json",
"protocol": "HTTP/1.1",
"requestId": "30e9177b-7253-43c4-95b4-b7c275ad037f",
"requestTime": "23/Feb/2018:22:29:36 +0000",
"requestTimeEpoch": 1519424976415,
"resourceId": "abcdef",
"resourcePath": "/echo.json",
"stage": "production"
},
"resource": "/echo.json",
"stageVariables": null
}
36 changes: 36 additions & 0 deletions src/data/apigateway/fixtures/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"body": null,
"headers": null,
"httpMethod": "DELETE",
"isBase64Encoded": false,
"path": "/user/session.json",
"pathParameters": null,
"queryStringParameters": null,
"requestContext": {
"accountId": "123456789012",
"apiId": "rest-api-id",
"httpMethod": "DELETE",
"identity": {
"accessKey": "AWS_ACCESS_KEY_ID",
"accountId": "123456789012",
"apiKey": "test-invoke-api-key",
"apiKeyId": "test-invoke-api-key-id",
"caller": "AWS_CALLER_ID",
"cognitoAuthenticationProvider": null,
"cognitoAuthenticationType": null,
"cognitoIdentityId": null,
"cognitoIdentityPoolId": null,
"sourceIp": "test-invoke-source-ip",
"user": "AIDAJDXSYAWOHYRSW7IPO",
"userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_144)",
"userArn": "arn:aws:iam::123456789012:user/example"
},
"path": "/user/session.json",
"requestId": "test-invoke-request",
"resourceId": "abcdef",
"resourcePath": "/user/session.json",
"stage": "test-invoke-stage"
},
"resource": "/user/session.json",
"stageVariables": null
}
Loading