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

Feature: Secret Syncs #2998

Merged
merged 14 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/src/services/secret-sync/github/github-sync-fns.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { Octokit } from "@octokit/rest";
import sodium from "libsodium-wrappers";

import { getGitHubClient } from "@app/services/app-connection/github";
import { GitHubSyncScope } from "@app/services/secret-sync/github/github-sync-enums";
import { GitHubSyncScope, GitHubSyncVisibility } from "@app/services/secret-sync/github/github-sync-enums";
import { SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";

@@ -149,7 +149,9 @@ const putSecret = async (client: Octokit, secretSync: TGitHubSyncWithCredentials
org: destinationConfig.org,
...payload,
visibility,
selected_repository_ids: selectedRepositoryIds
...(visibility === GitHubSyncVisibility.Selected && {
selected_repository_ids: selectedRepositoryIds
})
});
break;
}
14 changes: 12 additions & 2 deletions backend/src/services/secret-sync/github/github-sync-schemas.ts
Original file line number Diff line number Diff line change
@@ -34,10 +34,20 @@ const GitHubSyncDestinationConfigSchema = z
.superRefine((options, ctx) => {
if (options.scope !== GitHubSyncScope.Organization) return;

if (options.visibility === GitHubSyncVisibility.Selected && !options.selectedRepositoryIds?.length) {
if (options.visibility === GitHubSyncVisibility.Selected) {
if (!options.selectedRepositoryIds?.length)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Select at least 1 repository",
path: ["selectedRepositoryIds"]
});
return;
}

if (options.selectedRepositoryIds?.length) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Select at least 1 repository",
message: `Selected repositories is only supported for visibility "Selected"`,
path: ["selectedRepositoryIds"]
});
}
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ const Content = ({ secretSync, onComplete }: ContentProps) => {
}
errorText={error?.message}
isError={Boolean(error?.message)}
label="Initial Sync Behavior"
label="Import Behavior"
>
<Select
value={value}
Original file line number Diff line number Diff line change
@@ -20,18 +20,13 @@ import {
import { TSecretSyncForm } from "../schemas";

export const GitHubSyncFields = () => {
const {
control,
formState: { errors },
watch,
setValue
} = useFormContext<TSecretSyncForm & { destination: SecretSync.GitHub }>();

console.log("errors", errors, watch());
const { control, watch, setValue } = useFormContext<
TSecretSyncForm & { destination: SecretSync.GitHub }
>();

const connectionId = useWatch({ name: "connection.id", control });
const currentScope = watch("destinationConfig.scope");
const currentVisibility = watch("destinationConfig.visibility", GitHubSyncVisibility.All);
const currentVisibility = watch("destinationConfig.visibility");
const currentOrg = watch("destinationConfig.org");
const currentRepo = watch("destinationConfig.repo");
const currentOwner = watch("destinationConfig.owner");
@@ -70,7 +65,7 @@ export const GitHubSyncFields = () => {
setValue("destinationConfig.org", "");
setValue("destinationConfig.repo", "");
setValue("destinationConfig.owner", "");
setValue("destinationConfig.selectedRepositoryIds", []);
setValue("destinationConfig.selectedRepositoryIds", undefined);
}}
/>
<Controller
@@ -134,6 +129,7 @@ export const GitHubSyncFields = () => {
value={value}
onValueChange={(val) => {
onChange(val);
setValue("destinationConfig.selectedRepositoryIds", undefined);
}}
className="w-full border border-mineshaft-500 capitalize"
position="popper"
@@ -194,6 +190,7 @@ export const GitHubSyncFields = () => {

onChange(repo?.name);
setValue("destinationConfig.owner", repo?.owner.login ?? "");
setValue("destinationConfig.env", "");
}}
options={repositories}
placeholder="Select a repository..."
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ export const SecretSyncDetailsSection = ({ secretSync, onEditDetails }: Props) =
)}
{syncStatus === SecretSyncStatus.Failed && lastSyncMessage && (
<SecretSyncLabel labelClassName="text-red" label="Last Sync Error">
<p className="rounded bg-mineshaft-600 p-2 text-xs">{lastSyncMessage}</p>
<p className="break-words rounded bg-mineshaft-600 p-2 text-xs">{lastSyncMessage}</p>
</SecretSyncLabel>
)}
</div>