Skip to content

Commit

Permalink
Merge branch 'main' into chore/improve-rotate-keys-address-mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiloc committed Nov 13, 2024
2 parents 35bc3a3 + a93ab6d commit 940d0cf
Show file tree
Hide file tree
Showing 70 changed files with 5,109 additions and 184 deletions.
4 changes: 2 additions & 2 deletions .generated-sources/emily/client/rust/docs/ChainstateApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Name | Type | Description | Required | Notes

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down Expand Up @@ -110,7 +110,7 @@ Name | Type | Description | Required | Notes

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down
2 changes: 1 addition & 1 deletion .generated-sources/emily/client/rust/docs/DepositApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Name | Type | Description | Required | Notes

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down
2 changes: 1 addition & 1 deletion .generated-sources/emily/client/rust/docs/HealthApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This endpoint does not need any parameter.

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down
2 changes: 1 addition & 1 deletion .generated-sources/emily/client/rust/docs/TestingApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This endpoint does not need any parameter.

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down
4 changes: 2 additions & 2 deletions .generated-sources/emily/client/rust/docs/WithdrawalApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Name | Type | Description | Required | Notes

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down Expand Up @@ -115,7 +115,7 @@ Name | Type | Description | Required | Notes

### Authorization

No authorization required
[ApiGatewayKey](../README.md#ApiGatewayKey)

### HTTP request headers

Expand Down
16 changes: 16 additions & 0 deletions .generated-sources/emily/client/rust/src/apis/chainstate_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ pub async fn set_chainstate(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&chainstate);

let local_var_req = local_var_req_builder.build()?;
Expand Down Expand Up @@ -187,6 +195,14 @@ pub async fn update_chainstate(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&chainstate);

let local_var_req = local_var_req_builder.build()?;
Expand Down
8 changes: 8 additions & 0 deletions .generated-sources/emily/client/rust/src/apis/deposit_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ pub async fn update_deposits(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&update_deposits_request_body);

let local_var_req = local_var_req_builder.build()?;
Expand Down
8 changes: 8 additions & 0 deletions .generated-sources/emily/client/rust/src/apis/health_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ pub async fn check_health(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
Expand Down
8 changes: 8 additions & 0 deletions .generated-sources/emily/client/rust/src/apis/testing_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ pub async fn wipe_databases(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
Expand Down
16 changes: 16 additions & 0 deletions .generated-sources/emily/client/rust/src/apis/withdrawal_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ pub async fn create_withdrawal(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&create_withdrawal_request_body);

let local_var_req = local_var_req_builder.build()?;
Expand Down Expand Up @@ -200,6 +208,14 @@ pub async fn update_withdrawals(
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&update_withdrawals_request_body);

let local_var_req = local_var_req_builder.build()?;
Expand Down
105 changes: 67 additions & 38 deletions .generated-sources/emily/openapi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use serde_json::json;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use utoipa::openapi::security::ApiKey;
use utoipa::openapi::security::ApiKeyValue;
use utoipa::openapi::security::SecurityScheme;
use utoipa::Modify;
use utoipa::OpenApi;

fn main() {
Expand All @@ -12,6 +16,9 @@ fn main() {

#[derive(utoipa::OpenApi)]
#[openapi(
// Add API key security scheme.
modifiers(&AwsApiKey, &AwsLambdaIntegration),
// Paths to be included in the OpenAPI specification.
paths(
// Health check endpoints.
api::handlers::health::get_health,
Expand All @@ -34,6 +41,7 @@ fn main() {
// Testing endpoints.
api::handlers::testing::wipe_databases,
),
// Components to be included in the OpenAPI specification.
components(schemas(
// Chainstate models.
api::models::chainstate::Chainstate,
Expand Down Expand Up @@ -77,50 +85,71 @@ pub fn build_emily() {
println!("cargo:rerun-if-changed=../../../emily/handler/api");
println!("cargo:rerun-if-changed=build.rs");

let mut api_doc = ApiDoc::openapi();
let new_extensions: HashMap<String, serde_json::Value> = new_operation_extensions();

// TODO(269): Change Emily API Lambda Integrations to use cdk constructs if possible instead of specification
// alteration.
//
// Add AWS extension to openapi specification so AWS CDK can attach the appropriate lambda endpoint.
api_doc
.paths
.paths
.iter_mut()
.flat_map(|(_, path_item)| path_item.operations.iter_mut())
.for_each(|(_, operation)| {
operation
.extensions
.get_or_insert(Default::default())
.extend(new_extensions.clone())
});

// Generate string for api doc.
let spec_json = api_doc
let spec_json = ApiDoc::openapi()
// Make the spec pretty just because it's easier to read.
.to_pretty_json()
.expect("Failed to serialize OpenAPI spec");

// Open and write to file.
let mut file =
File::create("emily-openapi-spec.json").expect("Failed to create OpenAPI spec file");
file.write_all(spec_json.as_bytes())
File::create("emily-openapi-spec.json")
.expect("Failed to create OpenAPI spec file")
.write_all(spec_json.as_bytes())
.expect("Failed to write OpenAPI spec file");
}

/// Creates the map of the extensions to be included in each operation.
fn new_operation_extensions() -> HashMap<String, serde_json::Value> {
let mut extensions: HashMap<String, serde_json::Value> = HashMap::new();
extensions.insert(
"x-amazon-apigateway-integration".to_string(),
json!({
"type": "aws_proxy",
// Note that it's always meant to be POST regardless of the verb in the api spec.
"httpMethod": "POST",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OperationLambda}/invocations"
}
})
);
extensions
/// Openapi spec modifier that adds the API Gateway API key to the OpenAPI specification.
/// This adds the key as a schema type but is referenced by name in the paths need to
/// require authentication.
struct AwsApiKey;
impl Modify for AwsApiKey {
/// Modify the OpenAPI specification to include the AWS API Gateway key.
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
if let Some(schema) = openapi.components.as_mut() {
schema.add_security_scheme(
"ApiGatewayKey",
SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::with_description(
"x-api-key",
"AWS Apigateway key",
))),
);
}
}
}

/// Attaches the AWS Lambda integration to the OpenAPI specification. This is necessary
/// for the AWS CDK to attach the lambda to the API Gateway.
///
/// TODO(269): Change Emily API Lambda Integrations to use cdk constructs if possible
/// instead of specification alteration.
struct AwsLambdaIntegration;
impl Modify for AwsLambdaIntegration {
/// Add AWS extension to openapi specification so AWS CDK can attach the appropriate lambda endpoint.
fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
// Gather the extensions to be added to each operation.
let mut lambda_integration: HashMap<String, serde_json::Value> = HashMap::new();
lambda_integration.insert(
"x-amazon-apigateway-integration".to_string(),
json!({
"type": "aws_proxy",
// Note that it's always meant to be POST regardless of the verb in the api spec.
"httpMethod": "POST",
"uri": {
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OperationLambda}/invocations"
}
})
);
// Add extensions to each operation.
openapi
.paths
.paths
.iter_mut()
.flat_map(|(_, path_item)| path_item.operations.iter_mut())
.for_each(|(_, operation)| {
operation
.extensions
.get_or_insert(Default::default())
.extend(lambda_integration.clone())
});
}
}
Loading

0 comments on commit 940d0cf

Please sign in to comment.