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

fix: Drop unknown FCM users #197

Merged
merged 7 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 62 additions & 0 deletions autoendpoint/src/db/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ pub trait DbClient: Send + Sync {
/// Save a message to the message table
async fn save_message(&self, uaid: Uuid, message: Notification) -> DbResult<()>;

/// Delete a notification
async fn remove_message(&self, uaid: Uuid, sort_key: String) -> DbResult<()>;

/// Check if the router table exists
async fn router_table_exists(&self) -> DbResult<bool>;

/// Check if the message table exists
async fn message_table_exists(&self) -> DbResult<bool>;

/// Get the message table name
fn message_table(&self) -> &str;

Expand Down Expand Up @@ -95,6 +104,32 @@ impl DbClientImpl {
message_table,
})
}

/// Check if a table exists
async fn table_exists(&self, table_name: String) -> DbResult<bool> {
let input = DescribeTableInput { table_name };

let output = match retry_policy()
.retry_if(
|| self.ddb.describe_table(input.clone()),
retryable_describe_table_error(self.metrics.clone()),
)
.await
{
Ok(output) => output,
Err(RusotoError::Service(DescribeTableError::ResourceNotFound(_))) => {
return Ok(false);
}
Err(e) => return Err(e.into()),
};

let status = output
.table
.and_then(|table| table.table_status)
.ok_or(DbError::TableStatusUnknown)?;

Ok(["CREATING", "UPDATING", "ACTIVE"].contains(&status.as_str()))
AzureMarker marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[async_trait]
Expand Down Expand Up @@ -256,6 +291,33 @@ impl DbClient for DbClientImpl {
Ok(())
}

async fn remove_message(&self, uaid: Uuid, sort_key: String) -> DbResult<()> {
let input = DeleteItemInput {
table_name: self.message_table.clone(),
key: ddb_item! {
uaid: s => uaid.to_simple().to_string(),
chidmessageid: s => sort_key
},
..Default::default()
};

retry_policy()
.retry_if(
|| self.ddb.delete_item(input.clone()),
retryable_delete_error(self.metrics.clone()),
)
.await?;
Ok(())
}

async fn router_table_exists(&self) -> DbResult<bool> {
self.table_exists(self.router_table.clone()).await
}

async fn message_table_exists(&self) -> DbResult<bool> {
self.table_exists(self.message_table.clone()).await
}

fn message_table(&self) -> &str {
&self.message_table
}
Expand Down
18 changes: 18 additions & 0 deletions autoendpoint/src/db/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ mockall::mock! {

fn save_message(&self, uaid: Uuid, message: Notification) -> DbResult<()>;

fn remove_message(&self, uaid: Uuid, sort_key: String) -> DbResult<()>;

fn router_table_exists(&self) -> DbResult<bool>;

fn message_table_exists(&self) -> DbResult<bool>;

fn message_table(&self) -> &str;

fn box_clone(&self) -> Box<dyn DbClient>;
Expand Down Expand Up @@ -65,6 +71,18 @@ impl DbClient for Arc<MockDbClient> {
Arc::as_ref(self).save_message(uaid, message)
}

async fn remove_message(&self, uaid: Uuid, sort_key: String) -> DbResult<()> {
Arc::as_ref(self).remove_message(uaid, sort_key)
}

async fn router_table_exists(&self) -> DbResult<bool> {
Arc::as_ref(self).router_table_exists()
}

async fn message_table_exists(&self) -> DbResult<bool> {
Arc::as_ref(self).message_table_exists()
}

fn message_table(&self) -> &str {
Arc::as_ref(self).message_table()
}
Expand Down
2 changes: 1 addition & 1 deletion autoendpoint/src/routes/webpush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn delete_notification_route(
trace!("message_id = {:?}", message_id);
state
.ddb
.delete_message(message_id.uaid(), sort_key)
.remove_message(message_id.uaid(), sort_key)
.await?;

Ok(HttpResponse::NoContent().finish())
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.