Skip to content

Commit

Permalink
chore(cognito): upgrade dependency and code refactoring (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
burmecia authored Dec 11, 2024
1 parent 2ea964b commit 847b9a7
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 238 deletions.
58 changes: 34 additions & 24 deletions Cargo.lock

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

24 changes: 19 additions & 5 deletions docs/catalog/cognito.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,30 @@ The Cognito Wrapper supports data reads from Cognito's [User Records](https://do

| Cognito | Select | Insert | Update | Delete | Truncate |
| ------- | :----: | :----: | :----: | :----: | :------: |
| Records ||||||
| Users ||||||

For example:

```sql
create foreign table cognito (
email text,
username text
username text,
email text,
status text,
enabled boolean,
created_at timestamp,
updated_at timestamp,
attributes jsonb
)
server cognito_server
options (
object 'users'
object 'users'
);
```

!!! note

Only columns listed above are accepted in the foreign table.

### Foreign table options

The full list of foreign table options are below:
Expand All @@ -117,8 +126,13 @@ This will create a "foreign table" inside your Postgres database called `cognito

```sql
create foreign table cognito_table (
username text,
email text,
username text
status text,
enabled boolean,
created_at timestamp,
updated_at timestamp,
attributes jsonb
)
server cognito_server
options (
Expand Down
4 changes: 1 addition & 3 deletions wrappers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ cognito_fdw = [
"serde",
"url",
"thiserror",
"chrono",
]
logflare_fdw = [
"http",
Expand Down Expand Up @@ -198,8 +197,7 @@ aws-config = { version = "1.1.7", features = ["behavior-version-latest"], option
aws-sdk-s3 = { version = "1.45.0", optional = true }

# for cognito fdw
aws-sdk-cognitoidentityprovider = {version ="1.10.0", optional = true}

aws-sdk-cognitoidentityprovider = { version ="1.60.0", optional = true }

csv = { version = "1.2", optional = true }
tokio = { version = "1", features = ["full"], optional = true }
Expand Down
1 change: 1 addition & 0 deletions wrappers/src/fdw/cognito_fdw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ This is a demo foreign data wrapper which is developed using [Wrappers](https://

| Version | Date | Notes |
| ------- | ---------- | ---------------------------------------------------- |
| 0.1.3 | 2024-12-11 | Code quality improvment |
| 0.1.2 | 2024-09-30 | Support for pgrx 0.12.6 |
| 0.1.0 | 2024-01-25 | Initial version |
44 changes: 0 additions & 44 deletions wrappers/src/fdw/cognito_fdw/cognito_client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,2 @@
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::PgSqlErrorCode;
use supabase_wrappers::prelude::*;
use thiserror::Error;
use url::ParseError;

pub(crate) mod row;

pub(crate) mod rows_iterator;

#[allow(clippy::enum_variant_names)]
#[derive(Error, Debug)]
pub(crate) enum CognitoClientError {
#[error("{0}")]
CreateRuntimeError(#[from] CreateRuntimeError),

#[error("reqwest error: {0}")]
ReqwestError(#[from] reqwest::Error),

#[error("reqwest middleware error: {0}")]
ReqwestMiddlewareError(#[from] reqwest_middleware::Error),

#[error("invalid json response: {0}")]
SerdeError(#[from] serde_json::Error),

#[error("failed to parse url: {0}")]
UrlParseError(#[from] ParseError),

#[error("AWS Cognito error: {0}")]
AWSCognitoError(String),
}

impl From<CognitoClientError> for ErrorReport {
fn from(value: CognitoClientError) -> Self {
match value {
CognitoClientError::CreateRuntimeError(e) => e.into(),
CognitoClientError::UrlParseError(_)
| CognitoClientError::AWSCognitoError(_)
| CognitoClientError::ReqwestError(_)
| CognitoClientError::ReqwestMiddlewareError(_)
| CognitoClientError::SerdeError(_) => {
ErrorReport::new(PgSqlErrorCode::ERRCODE_FDW_ERROR, format!("{value}"), "")
}
}
}
}
Loading

0 comments on commit 847b9a7

Please sign in to comment.