Skip to content

Commit

Permalink
SnowflakeCredentials Typeguard
Browse files Browse the repository at this point in the history
  • Loading branch information
albandum committed Dec 12, 2024
1 parent e45fa09 commit 168be4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 12 additions & 7 deletions connectors/src/connectors/snowflake/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { ConnectionCredentials, ModelId, Result } from "@dust-tt/types";
import { Err, getConnectionCredentials, Ok } from "@dust-tt/types";
import {
Err,
getConnectionCredentials,
isSnowflakeCredentials,
Ok,
} from "@dust-tt/types";

import { apiConfig } from "@connectors/lib/api/config";
import type { Logger } from "@connectors/logger/logger";
Expand Down Expand Up @@ -53,13 +58,13 @@ export const getCredentials = async ({
}
// Narrow the type of credentials to just the username/password variant
const credentials = credentialsRes.value.credential.content;
if ("apiKey" in credentials) {
if (!isSnowflakeCredentials(credentials)) {
logger.error(
{ credentialsId },
"Invalid credentials type - expected username/password credentials"
"Invalid credentials type - expected snowflake credentials"
);
return new Err(
Error("Invalid credentials type - expected username/password credentials")
Error("Invalid credentials type - expected snowflake credentials")
);
}
return new Ok({
Expand Down Expand Up @@ -99,13 +104,13 @@ export const getConnectorAndCredentials = async ({
}
// Narrow the type of credentials to just the username/password variant
const credentials = credentialsRes.value.credential.content;
if ("apiKey" in credentials) {
if (!isSnowflakeCredentials(credentials)) {
logger.error(
{ connectorId },
"Invalid credentials type - expected username/password credentials"
"Invalid credentials type - expected snowflake credentials"
);
return new Err(
Error("Invalid credentials type - expected username/password credentials")
Error("Invalid credentials type - expected snowflake credentials")
);
}
return new Ok({
Expand Down
6 changes: 6 additions & 0 deletions types/src/oauth/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export type ModjoCredentials = t.TypeOf<typeof ApiKeyCredentialsSchema>;

export type ConnectionCredentials = SnowflakeCredentials | ModjoCredentials;

export function isSnowflakeCredentials(
credentials: ConnectionCredentials
): credentials is SnowflakeCredentials {
return "username" in credentials && "password" in credentials;
}

// POST Credentials

export const PostSnowflakeCredentialsBodySchema = t.type({
Expand Down

0 comments on commit 168be4f

Please sign in to comment.