-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error tracking): verify tokens (#25258)
- Loading branch information
1 parent
0470d65
commit 9fca67a
Showing
18 changed files
with
301 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Common types | ||
|
||
For types used across our projects, like events, persons, etc. Each time you go to copy a type from somewhere, put it here instead. | ||
For types used across our projects, like events, persons, etc. Each time you go to copy a type from somewhere, put it here instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
mod event; | ||
mod team; | ||
|
||
// Events | ||
pub use event::CapturedEvent; | ||
|
||
// Teams | ||
pub use team::Team; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, sqlx::FromRow)] | ||
pub struct Team { | ||
pub id: i32, | ||
pub name: String, | ||
pub api_token: String, | ||
} | ||
|
||
// We use query_as functions here rather than macros to avoid having to wrangle sqlx... TODO, be better | ||
// about that. | ||
impl Team { | ||
pub async fn by_token<'c, E>(executor: E, token: &str) -> Result<Option<Self>, sqlx::Error> | ||
where | ||
E: sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
sqlx::query_as::<_, Self>( | ||
r#" | ||
SELECT id, name, api_token | ||
FROM teams | ||
WHERE api_token = $1 | ||
"#, | ||
) | ||
.bind(token) | ||
.fetch_optional(executor) | ||
.await | ||
} | ||
|
||
pub async fn by_id<'c, E>(executor: E, id: i32) -> Result<Option<Self>, sqlx::Error> | ||
where | ||
E: sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
sqlx::query_as::<_, Self>( | ||
r#" | ||
SELECT id, name, api_token | ||
FROM teams | ||
WHERE id = $1 | ||
"#, | ||
) | ||
.bind(id) | ||
.fetch_optional(executor) | ||
.await | ||
} | ||
|
||
pub async fn bulk_by_tokens<'c, E>( | ||
executor: E, | ||
tokens: &[&str], | ||
) -> Result<Vec<Self>, sqlx::Error> | ||
where | ||
E: sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
sqlx::query_as::<_, Self>( | ||
r#" | ||
SELECT id, name, api_token | ||
FROM teams | ||
WHERE api_token = ANY($1) | ||
"#, | ||
) | ||
.bind(tokens) | ||
.fetch_all(executor) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod app_context; | ||
pub mod config; | ||
pub mod error; | ||
pub mod team_cache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.