Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cds-1565 Refactor Shipper code base in preparation for Metrics workflow #116

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/clients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use aws_sdk_s3::Client as S3Client;
use aws_sdk_sqs::Client as SqsClient;
use aws_sdk_ecr::Client as EcrClient;
use aws_config::SdkConfig;


/// A type used to hold the AWS clients required to interact with AWS services
/// used by the lambda function.
#[derive(Clone)]
pub struct AwsClients {
pub s3: S3Client,
pub ecr: EcrClient,
pub sqs: SqsClient,
}

impl AwsClients {
pub fn new(sdk_config: &SdkConfig) -> Self {
AwsClients {
s3: S3Client::new(&sdk_config),
ecr: EcrClient::new(&sdk_config),
sqs: SqsClient::new(&sdk_config),
}
}
}
18 changes: 9 additions & 9 deletions src/combined_event.rs → src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_json::Value;
use tracing::debug;

#[derive(Debug)]
pub enum CombinedEvent {
pub enum Combined {
S3(S3Event),
Sns(SnsEvent),
CloudWatchLogs(LogsEvent),
Expand All @@ -20,7 +20,7 @@ pub enum CombinedEvent {
EcrScan(EcrScanEvent),
}

impl<'de> Deserialize<'de> for CombinedEvent {
impl<'de> Deserialize<'de> for Combined {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -29,31 +29,31 @@ impl<'de> Deserialize<'de> for CombinedEvent {
debug!("raw_value: {:?}", raw_value);
if let Ok(event) = S3Event::deserialize(&raw_value) {
tracing::info!("s3 event detected");
return Ok(CombinedEvent::S3(event));
return Ok(Combined::S3(event));
}

if let Ok(event) = SnsEvent::deserialize(&raw_value) {
tracing::info!("sns event detected");
return Ok(CombinedEvent::Sns(event));
return Ok(Combined::Sns(event));
}
if let Ok(event) = EcrScanEvent::deserialize(&raw_value) {
tracing::info!("ecr scan event detected");
return Ok(CombinedEvent::EcrScan(event));
return Ok(Combined::EcrScan(event));
}

if let Ok(event) = LogsEvent::deserialize(&raw_value) {
tracing::info!("cloudwatch event detected");
return Ok(CombinedEvent::CloudWatchLogs(event));
return Ok(Combined::CloudWatchLogs(event));
}

if let Ok(event) = KinesisEvent::deserialize(&raw_value) {
tracing::info!("kinesis event detected");
return Ok(CombinedEvent::Kinesis(event));
return Ok(Combined::Kinesis(event));
}

if let Ok(event) = SqsEvent::deserialize(&raw_value) {
tracing::info!("sqs event detected");
return Ok(CombinedEvent::Sqs(event));
return Ok(Combined::Sqs(event));
}

// IMPORTANT: kafka must be evaluated last as it uses an arbitrary map to evaluate records.
Expand All @@ -69,7 +69,7 @@ impl<'de> Deserialize<'de> for CombinedEvent {
"unsupported or bad event type: {raw_value}"
)));
}
return Ok(CombinedEvent::Kafka(event));
return Ok(Combined::Kafka(event));
}

Err(de::Error::custom(format!(
Expand Down
Loading
Loading