Skip to content

Commit

Permalink
revert: attempt to make secrets allow empty
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw committed Jul 22, 2024
1 parent 06bb377 commit 74b8043
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/router/integration/integration-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const integrationRouter = createTRPCRouter({
name: input.name,
url: input.url,
kind: input.kind,
secrets: !input.secrets ? null : input.secrets,
secrets: input.secrets,
});

const integrationId = createId();
Expand All @@ -88,7 +88,7 @@ export const integrationRouter = createTRPCRouter({
kind: input.kind,
});

if (input.secrets && input.secrets.length >= 1) {
if (input.secrets.length >= 1) {
await ctx.db.insert(integrationSecrets).values(
input.secrets.map((secret) => ({
kind: secret.kind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export const testConnectionAsync = async (
value: `${string}.${string}`;
}[] = [],
) => {
const formSecrets = integration.secrets !== null ? integration.secrets
const formSecrets = integration.secrets
.filter((secret) => secret.value !== null)
.map((secret) => ({
...secret,
// We ensured above that the value is not null
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
value: secret.value!,
source: "form" as const,
})) : [];
}));

const decryptedDbSecrets = dbSecrets.map((secret) => ({
...secret,
Expand All @@ -35,9 +35,7 @@ export const testConnectionAsync = async (
}));

const sourcedSecrets = [...formSecrets, ...decryptedDbSecrets];
console.log('sourcedSecrets' + JSON.stringify(sourcedSecrets));
const secretKinds = getSecretKindOption(integration.kind, sourcedSecrets);
console.log('secretKinds' + JSON.stringify(secretKinds));

const filteredSecrets = secretKinds.map((kind) => {
const secrets = sourcedSecrets.filter((secret) => secret.kind === kind);
Expand Down
8 changes: 4 additions & 4 deletions packages/definitions/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const integrationDefs = {
},
getDashDot: {
name: "Dash.",
secretKinds: [],
secretKinds: [[]],
category: [],
iconUrl: "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/png/dashdot.png",
}
Expand All @@ -116,7 +116,7 @@ export const integrationDefs = {
{
name: string;
iconUrl: string;
secretKinds: [...IntegrationSecretKind[][]];
secretKinds: [IntegrationSecretKind[], ...IntegrationSecretKind[][]]; // at least one secret kind set is required
category: IntegrationCategory[];
}
>;
Expand All @@ -125,12 +125,12 @@ export const getIconUrl = (integration: IntegrationKind) => integrationDefs[inte

export const getIntegrationName = (integration: IntegrationKind) => integrationDefs[integration].name;

export const getDefaultSecretKinds = (integration: IntegrationKind): IntegrationSecretKind[] | undefined =>
export const getDefaultSecretKinds = (integration: IntegrationKind): IntegrationSecretKind[] =>
integrationDefs[integration].secretKinds[0];

export const getAllSecretKindOptions = (
integration: IntegrationKind,
): [...IntegrationSecretKind[][]] => integrationDefs[integration].secretKinds;
): [IntegrationSecretKind[], ...IntegrationSecretKind[][]] => integrationDefs[integration].secretKinds;

export const integrationKinds = objectKeys(integrationDefs);

Expand Down
2 changes: 1 addition & 1 deletion packages/validation/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const integrationCreateSchema = z.object({
kind: zodEnumFromArray(integrationSecretKinds),
value: z.string().nonempty(),
}),
).optional(),
),
});

const integrationUpdateSchema = z.object({
Expand Down

0 comments on commit 74b8043

Please sign in to comment.