diff --git a/aws/sdk/examples/secretsmanager-create-secret/Cargo.toml b/aws/sdk/examples/secretsmanager-create-secret/Cargo.toml new file mode 100644 index 0000000000..7aa282e29c --- /dev/null +++ b/aws/sdk/examples/secretsmanager-create-secret/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "secretsmanager-create-secret" +version = "0.1.0" +authors = ["AWS Rust SDK Team ", "Doug Schwartz "] +edition = "2018" +description = "Example usage of the SecretManager service" + +[dependencies] +secretsmanager = { package = "aws-sdk-secretsmanager", path = "../../build/aws-sdk/secretsmanager" } +tokio = { version = "1", features = ["full"]} +structopt = { version = "0.3", default-features = false } +tracing-subscriber = { version = "0.2.16", features = ["fmt"] } +aws-types = { path = "../../build/aws-sdk/aws-types" } \ No newline at end of file diff --git a/aws/sdk/examples/secretsmanager-create-secret/src/main.rs b/aws/sdk/examples/secretsmanager-create-secret/src/main.rs new file mode 100644 index 0000000000..7c2ffad3e2 --- /dev/null +++ b/aws/sdk/examples/secretsmanager-create-secret/src/main.rs @@ -0,0 +1,76 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +use secretsmanager::{Client, Config, Region}; + +use aws_types::region::{EnvironmentProvider, ProvideRegion}; + +use structopt::StructOpt; + +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::fmt::SubscriberBuilder; + +#[derive(Debug, StructOpt)] +struct Opt { + /// The region + #[structopt(short, long)] + region: Option, + + /// The name of the secret + #[structopt(short, long)] + name: String, + + /// The value of the secret + #[structopt(short, long)] + value: String, + /// Whether to display additonal runtime information + #[structopt(short, long)] + info: bool, +} + +#[tokio::main] +async fn main() { + let Opt { + info, + name, + region, + value, + } = Opt::from_args(); + + let region = EnvironmentProvider::new() + .region() + .or_else(|| region.as_ref().map(|region| Region::new(region.clone()))) + .unwrap_or_else(|| Region::new("us-west-2")); + + if info { + println!( + "SecretsManager client version: {}\n", + secretsmanager::PKG_VERSION + ); + println!("Region: {:?}", ®ion); + println!("Secret name: {}", name); + println!("Secret value: {}", value); + + SubscriberBuilder::default() + .with_env_filter("info") + .with_span_events(FmtSpan::CLOSE) + .init(); + } + + let config = Config::builder().region(region).build(); + + let client = Client::from_conf(config); + + match client + .create_secret() + .name(name) + .secret_string(value) + .send() + .await + { + Ok(_) => println!("Created secret"), + Err(e) => panic!("Failed to create secret: {}", e), + }; +} diff --git a/aws/sdk/examples/secretsmanager-get-secret-value/Cargo.toml b/aws/sdk/examples/secretsmanager-get-secret-value/Cargo.toml new file mode 100644 index 0000000000..13f000c35d --- /dev/null +++ b/aws/sdk/examples/secretsmanager-get-secret-value/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "secretsmanager-get-secret-value" +version = "0.1.0" +authors = ["AWS Rust SDK Team ", "Doug Schwartz "] +edition = "2018" +description = "Example usage of the SecretManager service" + +[dependencies] +secretsmanager = { package = "aws-sdk-secretsmanager", path = "../../build/aws-sdk/secretsmanager" } +tokio = { version = "1", features = ["full"]} +structopt = { version = "0.3", default-features = false } +tracing-subscriber = { version = "0.2.16", features = ["fmt"] } +aws-types = { path = "../../build/aws-sdk/aws-types" } \ No newline at end of file diff --git a/aws/sdk/examples/secretsmanager-get-secret-value/src/main.rs b/aws/sdk/examples/secretsmanager-get-secret-value/src/main.rs new file mode 100644 index 0000000000..e633d92f13 --- /dev/null +++ b/aws/sdk/examples/secretsmanager-get-secret-value/src/main.rs @@ -0,0 +1,73 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ +use std::process; + +use secretsmanager::{Client, Config, Region}; + +use aws_types::region::{EnvironmentProvider, ProvideRegion}; + +use structopt::StructOpt; + +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::fmt::SubscriberBuilder; + +#[derive(Debug, StructOpt)] +struct Opt { + /// The region + #[structopt(short, long)] + region: Option, + + /// The name of the secret + #[structopt(short, long)] + name: String, + /// Whether to display additonal runtime information + #[structopt(short, long)] + verbose: bool, +} + +#[tokio::main] +async fn main() { + let Opt { + name, + region, + verbose, + } = Opt::from_args(); + + let region = EnvironmentProvider::new() + .region() + .or_else(|| region.as_ref().map(|region| Region::new(region.clone()))) + .unwrap_or_else(|| Region::new("us-west-2")); + + if verbose { + println!( + "SecretsManager client version: {}\n", + secretsmanager::PKG_VERSION + ); + println!("Region: {:?}", ®ion); + println!("Secret name: {}", name); + + SubscriberBuilder::default() + .with_env_filter("info") + .with_span_events(FmtSpan::CLOSE) + .init(); + } + + let config = Config::builder().region(region).build(); + let client = Client::from_conf(config); + + match client.get_secret_value().secret_id(name).send().await { + Ok(resp) => { + println!( + "Value: {}", + resp.secret_string.as_deref().unwrap_or("No value!") + ); + } + Err(e) => { + println!("Got an error listing secrets:"); + println!("{}", e); + process::exit(1); + } + }; +} diff --git a/aws/sdk/examples/secretsmanager-list-secrets/Cargo.toml b/aws/sdk/examples/secretsmanager-list-secrets/Cargo.toml new file mode 100644 index 0000000000..c035e056aa --- /dev/null +++ b/aws/sdk/examples/secretsmanager-list-secrets/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "secretsmanager-list-secrets" +version = "0.1.0" +authors = ["AWS Rust SDK Team ", "Doug Schwartz "] +edition = "2018" +description = "Example usage of the SecretManager service" + +[dependencies] +secretsmanager = { package = "aws-sdk-secretsmanager", path = "../../build/aws-sdk/secretsmanager" } +tokio = { version = "1", features = ["full"]} +structopt = { version = "0.3", default-features = false } +tracing-subscriber = { version = "0.2.16", features = ["fmt"] } +aws-types = { path = "../../build/aws-sdk/aws-types" } \ No newline at end of file diff --git a/aws/sdk/examples/secretsmanager-list-secrets/src/main.rs b/aws/sdk/examples/secretsmanager-list-secrets/src/main.rs new file mode 100644 index 0000000000..80e0babc14 --- /dev/null +++ b/aws/sdk/examples/secretsmanager-list-secrets/src/main.rs @@ -0,0 +1,69 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ +use std::process; + +use secretsmanager::{Client, Config, Region}; + +use aws_types::region::{EnvironmentProvider, ProvideRegion}; + +use structopt::StructOpt; + +use tracing_subscriber::fmt::format::FmtSpan; +use tracing_subscriber::fmt::SubscriberBuilder; + +#[derive(Debug, StructOpt)] +struct Opt { + /// The region + #[structopt(short, long)] + region: Option, + + /// Whether to display additonal runtime information + #[structopt(short, long)] + verbose: bool, +} + +#[tokio::main] +async fn main() { + let Opt { region, verbose } = Opt::from_args(); + + let region = EnvironmentProvider::new() + .region() + .or_else(|| region.as_ref().map(|region| Region::new(region.clone()))) + .unwrap_or_else(|| Region::new("us-west-2")); + + if verbose { + println!( + "SecretsManager client version: {}", + secretsmanager::PKG_VERSION + ); + println!("Region: {:?}", ®ion); + + SubscriberBuilder::default() + .with_env_filter("info") + .with_span_events(FmtSpan::CLOSE) + .init(); + } + + let config = Config::builder().region(region).build(); + let client = Client::from_conf(config); + + match client.list_secrets().send().await { + Ok(resp) => { + println!("Secret names:"); + + let secrets = resp.secret_list.unwrap_or_default(); + for secret in &secrets { + println!(" {}", secret.name.as_deref().unwrap_or("No name!")); + } + + println!("Found {} secrets", secrets.len()); + } + Err(e) => { + println!("Got an error listing secrets:"); + println!("{}", e); + process::exit(1); + } + }; +}