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

Support environment variable substitution #433

Merged
merged 1 commit into from Dec 8, 2023
Merged

Support environment variable substitution #433

merged 1 commit into from Dec 8, 2023

Conversation

jbeisen
Copy link
Collaborator

@jbeisen jbeisen commented Nov 30, 2023

In the Kafka, Polling HTTP, WebSocket, and SSE sources, support environment variables in the passwords, secrets, and headers fields.

This is done by setting the format of the field in the JSON schema to var-str, which tells typify to replace the type with the VarStr struct, which has a function for substituting environment variables. The VarStr struct serializes/deserializes from a JSON string.


Screenshot 2023-11-30 at 1 21 44 PM

If the variable is needed for testing the connection and it's missing, it'll look like this:

Screenshot 2023-11-30 at 1 22 06 PM

And in SQL it looks like this:

image

@jbeisen jbeisen force-pushed the env-var-sub branch 10 times, most recently from 20efd7e to cab3d45 Compare December 6, 2023 01:03
@jbeisen jbeisen marked this pull request as ready for review December 6, 2023 01:04
@jbeisen jbeisen force-pushed the env-var-sub branch 3 times, most recently from 3f9a97a to 638987c Compare December 6, 2023 01:35
"description": "Comma separated list of headers to send with the request",
"pattern": "([a-zA-Z0-9-]+: ?.+,)*([a-zA-Z0-9-]+: ?.+)",
"examples": ["Authentication: digest 1234,Content-Type: application/json"]
"description": "Comma separated list of headers to send with the request. May contain [variables](https://doc.arroyo.dev/connectors/variables).",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this link to be something like "https://doc.arroyo.dev/connectors/overview#connection-formats" since we probably wouldn't want an entire doc page just to explain variable substitution

type Value = VarStr;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a string")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this forms the error message if deserialization fails. More details here.

@@ -8,3 +8,5 @@ bincode = "2.0.0-rc.3"
serde = { version = "1.0", features = ["derive"] }
arrow = { workspace = true }
arrow-array = { workspace = true }
regex = "1.10.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we try to avoid adding dependencies to arroyo-types since it's the base for everything — can this be moved elsewhere? For example, things that are needed by both api and the worker generally live in arroyo-rpc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

@@ -103,15 +104,15 @@ pub struct ConfluentSchemaRegistry {
topic: String,
client: Client,
api_key: Option<String>,
api_secret: Option<String>,
api_secret: Option<VarStr>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure ConfluentSchemaRegistry should be aware of VarStr — maybe it makes more sense to have the resolution happen earlier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that we should try to delay variable substitution as long as possible, and do it just in time when it's needed. I think that pattern minimizes the risk that we accidentally log sensitive data.

@@ -72,12 +72,28 @@ where
.map(|m| m.to_string()),
);

let headers = string_to_map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we abstract this code out into a method so we don't have to repeat it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

In the Kafka, Polling HTTP, WebSocket, and SSE sources, support
environment variables in the passwords, secrets, and headers fields.

This is done by setting the format of the field in the JSON schema to
'var-str', which tells typify to replace the type with the VarStr
struct, which has a function for substituting environment variables.
The VarStr struct serializes/deserializes from a JSON string.
@jbeisen jbeisen merged commit 38079a2 into master Dec 8, 2023
8 checks passed
@jbeisen jbeisen deleted the env-var-sub branch December 8, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants