-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENG-3200: Centralize OAuth logic to a single repository (#7)
- Loading branch information
Showing
24 changed files
with
163 additions
and
167 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,11 @@ | ||
mod parameter; | ||
mod refresh; | ||
mod storage; | ||
mod token; | ||
mod trigger; | ||
|
||
pub use parameter::*; | ||
pub use refresh::*; | ||
pub use storage::*; | ||
pub use token::*; | ||
pub use trigger::*; | ||
|
||
use chrono::{DateTime, Utc}; | ||
use integrationos_domain::{ | ||
algebra::{MongoStore, StoreExt}, | ||
Connection, Id, IntegrationOSError, | ||
}; | ||
use mongodb::bson::doc; | ||
|
||
pub async fn get_connections_to_refresh( | ||
collection: &MongoStore<Connection>, | ||
refresh_before: &DateTime<Utc>, | ||
refresh_after: &DateTime<Utc>, | ||
) -> Result<Vec<Connection>, IntegrationOSError> { | ||
collection | ||
.get_many( | ||
Some(doc! { | ||
"oauth.enabled.expires_at": doc! { | ||
"$gt": refresh_before.timestamp(), | ||
"$lte": refresh_after.timestamp(), | ||
}, | ||
}), | ||
None, | ||
None, | ||
None, | ||
None, | ||
) | ||
.await | ||
} | ||
|
||
pub async fn get_connection_to_trigger( | ||
collection: &MongoStore<Connection>, | ||
id: Id, | ||
) -> Result<Option<Connection>, IntegrationOSError> { | ||
collection | ||
.get_one(doc! { | ||
"_id": id.to_string(), | ||
}) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use async_trait::async_trait; | ||
use chrono::{DateTime, Utc}; | ||
use integrationos_domain::{Connection, Id, IntegrationOSError, MongoStore, StoreExt}; | ||
use mongodb::bson::doc; | ||
|
||
#[async_trait] | ||
pub trait StorageExt { | ||
async fn get_by( | ||
&self, | ||
refresh_before: &DateTime<Utc>, | ||
refresh_after: &DateTime<Utc>, | ||
) -> Result<Vec<Connection>, IntegrationOSError>; | ||
|
||
async fn get(&self, id: Id) -> Result<Option<Connection>, IntegrationOSError>; | ||
} | ||
|
||
#[async_trait] | ||
impl StorageExt for MongoStore<Connection> { | ||
async fn get_by( | ||
&self, | ||
refresh_before: &DateTime<Utc>, | ||
refresh_after: &DateTime<Utc>, | ||
) -> Result<Vec<Connection>, IntegrationOSError> { | ||
self.get_many( | ||
Some(doc! { | ||
"oauth.enabled.expires_at": doc! { | ||
"$gt": refresh_before.timestamp(), | ||
"$lte": refresh_after.timestamp(), | ||
}, | ||
}), | ||
None, | ||
None, | ||
None, | ||
None, | ||
) | ||
.await | ||
} | ||
|
||
async fn get(&self, id: Id) -> Result<Option<Connection>, IntegrationOSError> { | ||
self.get_one(doc! { | ||
"_id": id.to_string(), | ||
}) | ||
.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
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
Oops, something went wrong.