aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormurilo ijanc2025-11-21 19:09:42 -0300
committermurilo ijanc2025-11-21 19:09:42 -0300
commitfe7f63afe7addc351571882e205c5f73bf674cd5 (patch)
tree53c63e967e11458cf82dd8d476f3d5258a472ca4
parent8bbbe8ce175a9fee3bcb26d37595599353e3ed98 (diff)
downloadcogops-fe7f63afe7addc351571882e205c5f73bf674cd5.tar.gz
Fix clippy lint and change visibilities of functions
-rw-r--r--src/main.rs51
1 files changed, 20 insertions, 31 deletions
diff --git a/src/main.rs b/src/main.rs
index 8fdc1f7..b7270e4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-#![allow(unused)]
//
// Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
//
@@ -15,21 +14,22 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
-use std::collections::HashMap;
-use std::path::Path;
-use std::path::PathBuf;
-use std::sync::Arc;
-use std::time::Duration;
+use std::{
+ collections::HashMap, path::Path, path::PathBuf, sync::Arc, time::Duration,
+};
use anyhow::{Context, Result};
-use aws_sdk_cognitoidentityprovider::Client as CognitoClient;
-use aws_sdk_cognitoidentityprovider::types::UserType;
+use aws_sdk_cognitoidentityprovider::{
+ Client as CognitoClient, types::UserType,
+};
use clap::{ArgAction, Parser, Subcommand};
use indicatif::{ProgressBar, ProgressStyle};
-use tokio::fs::File;
-use tokio::io::{self, AsyncBufReadExt, AsyncWrite, AsyncWriteExt, BufReader};
-use tokio::sync::Semaphore;
-use tokio::task::JoinHandle;
+use tokio::{
+ fs::File,
+ io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
+ sync::Semaphore,
+ task::JoinHandle,
+};
use tracing::{debug, error, info};
use tracing_subscriber::EnvFilter;
@@ -345,7 +345,7 @@ async fn run_add_groups(
///
/// If `args.emails_file` is set, the CSV is written to that file.
/// Otherwise, the CSV is written to stdout.
-pub(crate) async fn sync_users_to_csv(
+async fn sync_users_to_csv(
client: &CognitoClient,
common_args: &CommonOperationArgs,
cmd_args: &SyncArgs,
@@ -357,17 +357,7 @@ pub(crate) async fn sync_users_to_csv(
&cmd_args.sync_file.display()
)
})?;
- // let mut writer: Box<dyn AsyncWrite + Unpin + Send> =
- // if let Some(path) = &cmd_args.sync_file {
- // let file = File::create(path).await.with_context(|| {
- // format!("failed to create output file at '{}'", path.display())
- // })?;
- // Box::new(file)
- // } else {
- // Box::new(io::stdout())
- // };
-
- // CSV header
+
writer
.write_all(b"username,email\n")
.await
@@ -450,7 +440,7 @@ fn extract_username_and_email(user: &UserType) -> (String, String) {
/// - The first line is treated as a header and skipped.
/// - Lines missing either username or email are ignored.
/// - Email is lowercased and trimmed to allow normalized lookups.
-pub async fn read_sync_file_to_map<P: AsRef<Path>>(
+async fn read_sync_file_to_map<P: AsRef<Path>>(
path: P,
) -> Result<HashMap<String, String>> {
let file = File::open(&path).await.with_context(|| {
@@ -494,7 +484,7 @@ pub async fn read_sync_file_to_map<P: AsRef<Path>>(
/// Load a plain-text file containing one e-mail per line.
///
/// Each line is trimmed and lowercased. Empty lines are skipped.
-pub async fn load_email_list<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
+async fn load_email_list<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
let file = File::open(&path).await.with_context(|| {
format!(
"failed to open e-mail list file '{}'",
@@ -520,7 +510,7 @@ pub async fn load_email_list<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
/// Add a Cognito user to one or more groups using the Admin API.
///
/// This function assumes AWS credentials and permissions allow admin operations.
-pub async fn admin_add_user_to_groups(
+async fn admin_add_user_to_groups(
client: &CognitoClient,
pool_id: &str,
username: &str,
@@ -558,7 +548,7 @@ pub async fn admin_add_user_to_groups(
///
/// `sync_csv_path`: CSV generated by `sync` (username,email).
/// `emails_list_path`: TXT file with one e-mail per line (users to be added).
-pub async fn add_users_to_groups_from_files(
+async fn add_users_to_groups_from_files(
client: &CognitoClient,
pool_id: &str,
sync_csv_path: &Path,
@@ -612,7 +602,8 @@ pub async fn add_users_to_groups_from_files(
let pb_clone = pb.clone();
let handle = tokio::spawn(async move {
- let _permit = permit; // keep permit alive for the duration of this task
+ // keep permit alive for the duration of this task
+ let _permit = permit;
if let Err(err) = admin_add_user_to_groups(
&client_clone,
@@ -643,9 +634,7 @@ pub async fn add_users_to_groups_from_files(
handles.push(handle);
}
- // Wait for all tasks to complete
for handle in handles {
- // Ignore panics here, just surface as error logs.
if let Err(join_err) = handle.await {
error!(error = ?join_err, "join error while processing a user");
}