Skip to content

Commit

Permalink
Renames of internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 19, 2024
1 parent 2a874ef commit 37fd0f0
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 78 deletions.
13 changes: 4 additions & 9 deletions src/redacters/aws_comprehend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::args::RedacterType;
use crate::errors::AppError;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
RedactSupportedOptions, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
RedactSupport, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
};
use crate::reporter::AppReporter;
use crate::AppResult;
Expand Down Expand Up @@ -88,15 +88,10 @@ impl<'a> Redacter for AwsComprehendRedacter<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
Ok(match file_ref.media_type.as_ref() {
Some(media_type) if Redacters::is_mime_text(media_type) => {
RedactSupportedOptions::Supported
}
_ => RedactSupportedOptions::Unsupported,
Some(media_type) if Redacters::is_mime_text(media_type) => RedactSupport::Supported,
_ => RedactSupport::Unsupported,
})
}

Expand Down
19 changes: 6 additions & 13 deletions src/redacters/gcp_dlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::common_types::GcpProjectId;
use crate::errors::AppError;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
RedactSupportedOptions, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
RedactSupport, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
};
use crate::reporter::AppReporter;
use crate::AppResult;
Expand Down Expand Up @@ -267,21 +267,14 @@ impl<'a> Redacter for GcpDlpRedacter<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
Ok(match file_ref.media_type.as_ref() {
Some(media_type) if Redacters::is_mime_text(media_type) => {
RedactSupportedOptions::Supported
}
Some(media_type) if Redacters::is_mime_table(media_type) => {
RedactSupportedOptions::Supported
}
Some(media_type) if Redacters::is_mime_text(media_type) => RedactSupport::Supported,
Some(media_type) if Redacters::is_mime_table(media_type) => RedactSupport::Supported,
Some(media_type) if Self::check_supported_image_type(media_type) => {
RedactSupportedOptions::Supported
RedactSupport::Supported
}
_ => RedactSupportedOptions::Unsupported,
_ => RedactSupport::Unsupported,
})
}

Expand Down
19 changes: 6 additions & 13 deletions src/redacters/gemini_llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::common_types::{GcpProjectId, TextImageCoords};
use crate::errors::AppError;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
redact_image_at_coords, RedactSupportedOptions, Redacter, RedacterDataItem,
RedacterDataItemContent, Redacters,
redact_image_at_coords, RedactSupport, Redacter, RedacterDataItem, RedacterDataItemContent,
Redacters,
};
use crate::reporter::AppReporter;
use crate::AppResult;
Expand Down Expand Up @@ -346,18 +346,11 @@ impl<'a> Redacter for GeminiLlmRedacter<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
Ok(match file_ref.media_type.as_ref() {
Some(media_type) if Redacters::is_mime_text(media_type) => {
RedactSupportedOptions::Supported
}
Some(media_type) if Redacters::is_mime_image(media_type) => {
RedactSupportedOptions::Supported
}
_ => RedactSupportedOptions::Unsupported,
Some(media_type) if Redacters::is_mime_text(media_type) => RedactSupport::Supported,
Some(media_type) if Redacters::is_mime_image(media_type) => RedactSupport::Supported,
_ => RedactSupport::Unsupported,
})
}

Expand Down
22 changes: 8 additions & 14 deletions src/redacters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,15 @@ impl<'a> Redacters<'a> {
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RedactSupportedOptions {
pub enum RedactSupport {
Supported,
Unsupported,
}

pub trait Redacter {
async fn redact(&self, input: RedacterDataItem) -> AppResult<RedacterDataItem>;

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions>;
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport>;

fn redacter_type(&self) -> RedacterType;
}
Expand All @@ -182,16 +179,13 @@ impl<'a> Redacter for Redacters<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
match self {
Redacters::GcpDlp(redacter) => redacter.redact_supported_options(file_ref).await,
Redacters::AwsComprehend(redacter) => redacter.redact_supported_options(file_ref).await,
Redacters::MsPresidio(redacter) => redacter.redact_supported_options(file_ref).await,
Redacters::GeminiLlm(redacter) => redacter.redact_supported_options(file_ref).await,
Redacters::OpenAiLlm(redacter) => redacter.redact_supported_options(file_ref).await,
Redacters::GcpDlp(redacter) => redacter.redact_support(file_ref).await,
Redacters::AwsComprehend(redacter) => redacter.redact_support(file_ref).await,
Redacters::MsPresidio(redacter) => redacter.redact_support(file_ref).await,
Redacters::GeminiLlm(redacter) => redacter.redact_support(file_ref).await,
Redacters::OpenAiLlm(redacter) => redacter.redact_support(file_ref).await,
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/redacters/ms_presidio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::args::RedacterType;
use crate::errors::AppError;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
RedactSupportedOptions, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
RedactSupport, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
};
use crate::reporter::AppReporter;
use crate::AppResult;
Expand Down Expand Up @@ -183,24 +183,21 @@ impl<'a> Redacter for MsPresidioRedacter<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
Ok(match file_ref.media_type.as_ref() {
Some(media_type)
if Redacters::is_mime_text(media_type)
&& self.ms_presidio_options.text_analyze_url.is_some() =>
{
RedactSupportedOptions::Supported
RedactSupport::Supported
}
Some(media_type)
if Redacters::is_mime_image(media_type)
&& self.ms_presidio_options.image_redact_url.is_some() =>
{
RedactSupportedOptions::Supported
RedactSupport::Supported
}
_ => RedactSupportedOptions::Unsupported,
_ => RedactSupport::Unsupported,
})
}

Expand Down
13 changes: 4 additions & 9 deletions src/redacters/open_ai_llm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::args::RedacterType;
use crate::errors::AppError;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
RedactSupportedOptions, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
RedactSupport, Redacter, RedacterDataItem, RedacterDataItemContent, Redacters,
};
use crate::reporter::AppReporter;
use crate::AppResult;
Expand Down Expand Up @@ -154,15 +154,10 @@ impl<'a> Redacter for OpenAiLlmRedacter<'a> {
}
}

async fn redact_supported_options(
&self,
file_ref: &FileSystemRef,
) -> AppResult<RedactSupportedOptions> {
async fn redact_support(&self, file_ref: &FileSystemRef) -> AppResult<RedactSupport> {
Ok(match file_ref.media_type.as_ref() {
Some(media_type) if Redacters::is_mime_text(media_type) => {
RedactSupportedOptions::Supported
}
_ => RedactSupportedOptions::Unsupported,
Some(media_type) if Redacters::is_mime_text(media_type) => RedactSupport::Supported,
_ => RedactSupport::Unsupported,
})
}

Expand Down
24 changes: 12 additions & 12 deletions src/redacters/stream_redacter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::file_converters::pdf::{PdfInfo, PdfPageInfo, PdfToImage};
use crate::file_converters::FileConverters;
use crate::file_systems::FileSystemRef;
use crate::redacters::{
redact_rgba_image_at_coords, RedactSupportedOptions, Redacter, RedacterBaseOptions,
RedacterDataItem, RedacterDataItemContent, Redacters,
redact_rgba_image_at_coords, RedactSupport, Redacter, RedacterBaseOptions, RedacterDataItem,
RedacterDataItemContent, Redacters,
};
use crate::AppResult;
use futures::{Stream, TryStreamExt};
Expand Down Expand Up @@ -56,8 +56,8 @@ impl<'a> StreamRedacter<'a> {
// Supports natively
let mut supported_redacters = Vec::new();
for redacter in redacters {
let supported_options = redacter.redact_supported_options(file_ref).await?;
if supported_options == RedactSupportedOptions::Supported {
let supported_options = redacter.redact_support(file_ref).await?;
if supported_options == RedactSupport::Supported {
supported_redacters.push(redacter);
}
}
Expand All @@ -69,12 +69,12 @@ impl<'a> StreamRedacter<'a> {
if Redacters::is_mime_table(file_ref_media) {
for redacter in redacters {
let supported_options = redacter
.redact_supported_options(&FileSystemRef {
.redact_support(&FileSystemRef {
media_type: Some(mime::TEXT_PLAIN),
..file_ref.clone()
})
.await?;
if supported_options == RedactSupportedOptions::Supported {
if supported_options == RedactSupport::Supported {
supported_redacters.push(redacter);
}
}
Expand All @@ -86,12 +86,12 @@ impl<'a> StreamRedacter<'a> {
{
for redacter in redacters {
let supported_options = redacter
.redact_supported_options(&FileSystemRef {
.redact_support(&FileSystemRef {
media_type: Some(mime::IMAGE_PNG),
..file_ref.clone()
})
.await?;
if supported_options == RedactSupportedOptions::Supported {
if supported_options == RedactSupport::Supported {
supported_redacters.push(redacter);
}
}
Expand All @@ -103,12 +103,12 @@ impl<'a> StreamRedacter<'a> {
if supported_redacters.is_empty() && self.file_converters.ocr.is_some() {
for redacter in redacters {
let supported_options = redacter
.redact_supported_options(&FileSystemRef {
.redact_support(&FileSystemRef {
media_type: Some(mime::TEXT_PLAIN),
..file_ref.clone()
})
.await?;
if supported_options == RedactSupportedOptions::Supported {
if supported_options == RedactSupport::Supported {
supported_redacters.push(redacter);
}
}
Expand All @@ -122,12 +122,12 @@ impl<'a> StreamRedacter<'a> {
{
for redacter in redacters {
let supported_options = redacter
.redact_supported_options(&FileSystemRef {
.redact_support(&FileSystemRef {
media_type: Some(mime::TEXT_PLAIN),
..file_ref.clone()
})
.await?;
if supported_options == RedactSupportedOptions::Supported {
if supported_options == RedactSupport::Supported {
supported_redacters.push(redacter);
}
}
Expand Down

0 comments on commit 37fd0f0

Please sign in to comment.