From 519553004e4444cada2f8f6873e142e70879967f Mon Sep 17 00:00:00 2001 From: Sergei Smolianinov Date: Mon, 7 Aug 2023 00:56:10 -0700 Subject: [PATCH] Gracefully handle invalid input --- README.md | 2 +- src/main.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9841457..c8b493a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # vector-aws-secrets-helper A helper tool for [Vector](https://vector.dev/) to securely retrieve secrets from AWS SSM Parameter Store and AWS -Secrets Manager using the [exec](https://vector.dev/docs/reference/configuration/global-options/#secret.exec) backend. +Secrets Manager using the [exec](https://vector.dev/highlights/2022-07-07-secrets-management/) backend. ## Installation diff --git a/src/main.rs b/src/main.rs index 76b5d56..ff85f87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,11 +32,14 @@ async fn main() { // Parse the CLI arguments. let cli = Cli::parse(); - // Parse the JSON from stdin into a SecretsToFetch struct. It assumes that Vector will always - // provide valid JSON, so we can simply unwrap the result. Probably should implement proper - // pattern matching for the result here at some point instead. - let secrets_to_fetch: vector::SecretsToFetch = - serde_json::from_reader(std::io::stdin()).unwrap(); + // Parse the JSON from stdin into a SecretsToFetch struct. + let secrets_to_fetch: vector::SecretsToFetch = match serde_json::from_reader(std::io::stdin()) { + Ok(secrets_to_fetch) => secrets_to_fetch, + Err(_) => { + eprintln!("failed to parse JSON from stdin"); + std::process::exit(1); + } + }; // Load the AWS SDK config using the default credential provider chain. let aws_sdk_config = aws_config::load_from_env().await;