Skip to content

Commit

Permalink
Update to latest NDC SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-chambers committed Oct 10, 2024
1 parent b373cbc commit 8ac7a4a
Show file tree
Hide file tree
Showing 16 changed files with 1,481 additions and 1,072 deletions.
1,747 changes: 1,008 additions & 739 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.1.0"
version = "0.6.0"

[workspace]
resolver = "2"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.76-slim-buster AS build
FROM rust:1.81-slim-bookworm AS build

WORKDIR /app

Expand All @@ -16,7 +16,7 @@ COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --release --all-targets


FROM debian:buster-slim as ndc-sendgrid
FROM debian:bookworm-slim AS ndc-sendgrid

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
Expand Down
42 changes: 30 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# SendGrid Connector

> [!WARNING]
> This connector has been updated to support the Hasura DDN Beta, and will not work with the Alpha.
The SendGrid Native Data Connector allows for connecting to the SendGrid v3 API and exposing its functionality from your Hasura API.
While this is a functional implementation of the SendGrid API, it also serves as a minimal example of an "Action" style connector using the [Rust Data Connector SDK](https://github.com/hasura/ndc-hub#rusk-sdk).

* [SendGrid Connector information in the Hasura Connectors directory](https://hasura.io/connectors/sendgrid)
* [Hasura V3 Documentation](https://hasura.io/docs/3.0)
* [Hasura DDN Documentation](https://hasura.io/docs/3.0)

In order to use this connector you will need to:

* Create a [SendGrid API account](https://signup.sendgrid.com/)
* Create an [API key](https://app.sendgrid.com/settings/api_keys)
* Log in to A Hasura CLI Session
* Create a Pre-Shared Token for service authentication between the Hasura V3 Engine and your connector
* A Hasura DDN project (see the [Getting Started guide](https://hasura.io/docs/3.0/getting-started/overview/))

## Features

Expand All @@ -26,7 +21,33 @@ This connector is a minimal implementation of the SendGrid v3 API functions:
It also serves as an example of how an `Action` style connector can be implemented in Hasura V3.

## For Hasura Users
TBD
Add the SendGrid connector to your DDN project by running

```
> ddn connector init -i
```

Select the SendGrid connector from the list and provide a name for the connector and your SendGrid API key.

Then you need to introspect the connector to get its schema:

```
> ddn connector introspect <connector name>
```

And then you can add all the SendGrid commands to your supergraph:

```
> ddn command add <connector name> "*"
```

You can now build your supergraph, run it locally, and open the Hasura Console to try it out:

```
> ddn supergraph build local
> ddn run docker-start
> ddn console --local
```

## For Developers

Expand All @@ -46,10 +67,7 @@ SENDGRID_API_KEY="YOUR-API-KEY-HERE" cargo run -- serve --configuration .
```

### Docker

The `Dockerfile` is used by the `connector create` command and can be tested as follows:

```
docker build . --tag ndc-sendgrid
docker run -it -e SENDGRID_API_KEY="YOUR-API-KEY-HERE" ndc-sendgrid
docker run --rm -it -e SENDGRID_API_KEY="YOUR-API-KEY-HERE" -p 8080:8080 ndc-sendgrid
```
2 changes: 2 additions & 0 deletions connector-definition/connector-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ packagingDefinition:
supportedEnvironmentVariables:
- name: SENDGRID_API_KEY
description: The SendGrid API key to use
required: true
commands: {}
dockerComposeWatch:
- path: ./
target: /etc/connector
action: sync+restart
documentationPage: https://hasura.info/sendgrid-getting-started
7 changes: 0 additions & 7 deletions connector-definition/docker-compose.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions crates/ndc-sendgrid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "ndc-sendgrid"
version = "0.1.0"
version = { workspace = true }
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# ndc-client = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.0-rc.4" }
ndc-sdk = { git = "https://github.com/hasura/ndc-hub.git", rev = "660750a", package = "ndc-sdk" }
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.4.0" }

async-trait = "0.1"
prometheus = { version = "0.13" }
schemars = { version = "0.8.16", features = ["smol_str"] }
schemars = { version = "0.8", features = ["smol_str"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.11.19" }
http = { version = "0.2" }
reqwest = { version = "0.12", features = ["json"] }
indexmap = "^2"
thiserror = { version = "*" } # Use the version from ndc-sdk
33 changes: 11 additions & 22 deletions crates/ndc-sendgrid/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{env, path::Path};
use ndc_sdk::connector::{self, InvalidRange, KeyOrIndex};
use ndc_sdk::connector;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::{env, path::Path};

use super::sendgrid_api::{ApiKeyError, SendGridApiKey};

Expand All @@ -11,34 +11,23 @@ pub struct SendGridConfiguration {
}

pub fn parse_configuration(
_configuration_dir: impl AsRef<Path> + Send
) -> Result<SendGridConfiguration, connector::ValidateError> {

_configuration_dir: impl AsRef<Path> + Send,
) -> connector::Result<SendGridConfiguration> {
match env::var("SENDGRID_API_KEY") {
Ok(key) => SendGridApiKey::new(key.as_str())
.map(|api_key| SendGridConfiguration {
sendgrid_api_key: api_key,
})
.map_err(|err| match err {
ApiKeyError::CannotBeBlank => {
mk_single_error("sendgrid_api_key", "sendgrid_api_key cannot be blank")
}
ApiKeyError::CannotBeBlank => connector::ErrorResponse::from(
"The SENDGRID_API_KEY environment variable cannot be blank".to_owned(),
),
}),
Err(env::VarError::NotPresent) => Err(mk_single_error(
"SENDGRID_API_KEY",
"The SENDGRID_API_KEY environment variable is required",
Err(env::VarError::NotPresent) => Err(connector::ErrorResponse::from(
"The SENDGRID_API_KEY environment variable is required".to_owned(),
)),
Err(env::VarError::NotUnicode(_)) => Err(mk_single_error(
"SENDGRID_API_KEY",
"The SENDGRID_API_KEY environment variable value is not valid unicode",
Err(env::VarError::NotUnicode(_)) => Err(connector::ErrorResponse::from(
"The SENDGRID_API_KEY environment variable value is not valid unicode".to_owned(),
)),
}
}

fn mk_single_error(key: &str, message: &str) -> connector::ValidateError {
let errs = vec![InvalidRange {
path: vec![KeyOrIndex::Key(String::from(key))],
message: String::from(message),
}];
connector::ValidateError::ValidateError(errs)
}
Loading

0 comments on commit 8ac7a4a

Please sign in to comment.