Skip to content

Commit

Permalink
Rust: Checks use -D warnings (#5460)
Browse files Browse the repository at this point in the history
* Consistently use -D warnings, and add Lambdas to checks.
  • Loading branch information
DavidSouther authored and ford-at-aws committed Dec 15, 2023
1 parent ccc9f6d commit 6a3e704
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 50 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ jobs:
toolchain: "1.70.0"
components: clippy, rustfmt
- uses: actions/checkout@v3
- name: Set Environment
run: >
export RUSTFLAGS="-D warnings" ;
export APP_ENVIRONMENT="test"
- name: Rust format
run: >
"$HOME/.cargo/bin/cargo" fmt --manifest-path rust_dev_preview/cross_service/Cargo.toml --all --check &&
"$HOME/.cargo/bin/cargo" fmt --manifest-path rust_dev_preview/examples/Cargo.toml --all --check &&
"$HOME/.cargo/bin/cargo" fmt --manifest-path rust_dev_preview/lambda/Cargo.toml --all --check &&
"$HOME/.cargo/bin/cargo" fmt --manifest-path rust_dev_preview/webassembly/Cargo.toml --all --check
- name: Rust lint
if: success() || failure()
run: >
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/cross_service/Cargo.toml -- -D warnings &&
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/examples/Cargo.toml -- -D warnings &&
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/webassembly/Cargo.toml -- -D warnings
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/cross_service/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/examples/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/lambda/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" clippy --manifest-path rust_dev_preview/webassembly/Cargo.toml --all
- name: Rust test
run: >
"$HOME/.cargo/bin/cargo" test --manifest-path rust_dev_preview/cross_service/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" test --manifest-path rust_dev_preview/examples/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" test --manifest-path rust_dev_preview/lambda/Cargo.toml --all &&
"$HOME/.cargo/bin/cargo" test --manifest-path rust_dev_preview/webassembly/Cargo.toml --all
env:
APP_ENVIRONMENT: test
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use aws_sdk_dynamodb::primitives::DateTime;
use aws_sdk_s3::{operation::get_object::GetObjectOutput, types::CompletedPart};
use aws_smithy_types_convert::date_time::DateTimeExt;
use chrono::NaiveDateTime;
use futures::TryStreamExt;
use pipe::{pipe, PipeReader, PipeWriter};
use streaming_zip::{Archive, CompressionMode};
use uuid::Uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,5 @@ mod test {
assert!(update_inner_debug.contains("\":image\": L([S(\"object\")])"));
assert!(update_inner_debug.contains("\":one\": N(\"1\")"));
assert!(update_inner_debug.contains("\":zero\": N(\"0\")"));

()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use aws_smithy_types_convert::date_time::DateTimeExt;
use std::io::prelude::*;
use std::io::Write;
use tempfile::tempfile;
use tokio_stream::StreamExt;
use zip_next::{write::FileOptions, ZipWriter};

use crate::common::Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn prep_app(config: aws_config::ConfigLoader) -> (String, RdsClient) {
let port = listener.local_addr().unwrap().port();
let server =
rest_ses::startup::run(listener, rds.clone(), ses).expect("Failed to initalize server!");
let _ = tokio::spawn(server);
tokio::spawn(server);
let address = format!("http://127.0.0.1:{port}");
(address, rds)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async fn show_pools(client: &Client) -> Result<(), Error> {
for pool in pools {
println!(" ID: {}", pool.id().unwrap_or_default());
println!(" Name: {}", pool.name().unwrap_or_default());
println!(" Status: {:?}", pool.status());
println!(" Lambda Config: {:?}", pool.lambda_config().unwrap());
println!(
" Last modified: {}",
Expand Down
1 change: 0 additions & 1 deletion rust_dev_preview/examples/s3/src/bin/get-object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use aws_config::meta::region::RegionProviderChain;
use std::{fs::File, io::Write, path::PathBuf, process::exit};
use tokio_stream::StreamExt;

use aws_sdk_s3::Client;
use clap::Parser;
Expand Down
60 changes: 22 additions & 38 deletions rust_dev_preview/examples/sts/src/bin/assume-role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,28 @@ struct Opt {

// Displays the STS AssumeRole Arn.
// snippet-start:[sts.rust.assume_role]
async fn assume_role(
config: &SdkConfig,
region: Region,
role_name: String,
session_name: Option<String>,
) -> Result<(), Error> {
match config.credentials_provider() {
Some(credential) => {
let provider = aws_config::sts::AssumeRoleProvider::builder(role_name)
.region(region)
.session_name(session_name.unwrap_or_else(|| String::from("rust-assume-role")))
.build(credential.clone());
let local_config = aws_config::from_env()
.credentials_provider(provider)
.load()
.await;
let client = Client::new(&local_config);
let req = client.get_caller_identity();
let resp = req.send().await;
match resp {
Ok(e) => {
println!("UserID : {}", e.user_id().unwrap_or_default());
println!("Account: {}", e.account().unwrap_or_default());
println!("Arn : {}", e.arn().unwrap_or_default());
}
Err(e) => println!("{:?}", e),
}
}
None => {
println!("No config provided");
async fn assume_role(config: &SdkConfig, role_name: String, session_name: Option<String>) {
let provider = aws_config::sts::AssumeRoleProvider::builder(role_name)
.session_name(session_name.unwrap_or("rust_sdk_example_session".into()))
.configure(config)
.build()
.await;

let local_config = aws_config::from_env()
.credentials_provider(provider)
.load()
.await;
let client = Client::new(&local_config);
let req = client.get_caller_identity();
let resp = req.send().await;
match resp {
Ok(e) => {
println!("UserID : {}", e.user_id().unwrap_or_default());
println!("Account: {}", e.account().unwrap_or_default());
println!("Arn : {}", e.arn().unwrap_or_default());
}
Err(e) => println!("{:?}", e),
}
Ok(())
}
// snippet-end:[sts.rust.assume_role]

Expand Down Expand Up @@ -104,11 +93,6 @@ async fn main() -> Result<(), Error> {
}

let shared_config = aws_config::from_env().region(region_provider).load().await;
assume_role(
&shared_config,
shared_config.region().unwrap().clone(),
role_arn,
role_session_name,
)
.await
assume_role(&shared_config, role_arn, role_session_name).await;
Ok(())
}
1 change: 1 addition & 0 deletions rust_dev_preview/examples/tls/tests/test-tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#[ignore]
#[tokio::test]
#[allow(clippy::assertions_on_constants)]
async fn test_it_runs() {
match tls::connect_via_tls_13().await {
Err(_e) => assert!(false),
Expand Down
6 changes: 6 additions & 0 deletions rust_dev_preview/lambda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
resolver = "2"

members = [
"calculator"
]

0 comments on commit 6a3e704

Please sign in to comment.