-
Notifications
You must be signed in to change notification settings - Fork 394
integrations gcs and s3 #403
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
Open
lindesvard
wants to merge
8
commits into
main
Choose a base branch
from
feature/integrations-s3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c290d06
feat: S3/GCS data export integration
lindesvard 2c6815f
feat: scope integrations to projects (dual-scope)
lindesvard 20e32fc
refactor: integration plugin registry (generic dispatch)
lindesvard a4cbe85
fix: make isKind lenient for empty/unknown integration config
lindesvard e3ccf88
refactor: one encryption key for all at-rest secrets
lindesvard 8c1de48
chore: remove dead integration-registry exports
lindesvard 80c00a7
fix: slack OAuth callback no longer redirects to a deleted route
lindesvard f8ea00d
fix: SSRF guards + cross-project integration update authz
lindesvard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
apps/start/src/components/integrations/forms/gcs-export-integration.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| import { InputWithLabel } from '@/components/forms/input-with-label'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from '@/components/ui/select'; | ||
| import { useAppParams } from '@/hooks/use-app-params'; | ||
| import { useTRPC } from '@/integrations/trpc/react'; | ||
| import type { RouterOutputs } from '@/trpc/client'; | ||
| import { zodResolver } from '@hookform/resolvers/zod'; | ||
| import { zCreateGCSExportIntegration } from '@openpanel/validation'; | ||
| import { useMutation } from '@tanstack/react-query'; | ||
| import { path, mergeDeepRight } from 'ramda'; | ||
| import { Controller, useForm } from 'react-hook-form'; | ||
| import { toast } from 'sonner'; | ||
| import type { z } from 'zod'; | ||
|
|
||
| type IForm = z.infer<typeof zCreateGCSExportIntegration>; | ||
|
|
||
| export function GCSExportIntegrationForm({ | ||
| defaultValues, | ||
| onSuccess, | ||
| }: { | ||
| defaultValues?: RouterOutputs['integration']['get']; | ||
| onSuccess: () => void; | ||
| }) { | ||
| const { projectId } = useAppParams(); | ||
| const form = useForm<IForm>({ | ||
| defaultValues: mergeDeepRight( | ||
| { | ||
| id: defaultValues?.id, | ||
| projectId, | ||
| name: '', | ||
| config: { | ||
| type: 'gcs_export' as const, | ||
| bucket: '', | ||
| prefix: 'openpanel-exports', | ||
| format: 'jsonl_gzip' as const, | ||
| serviceAccountKey: '', | ||
| }, | ||
| }, | ||
| defaultValues ?? {}, | ||
| ), | ||
| resolver: zodResolver(zCreateGCSExportIntegration), | ||
| }); | ||
| const trpc = useTRPC(); | ||
| const mutation = useMutation( | ||
| trpc.integration.createOrUpdateExport.mutationOptions({ | ||
| onSuccess, | ||
| onError(error) { | ||
| toast.error(error.message || 'Failed to create integration'); | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const testMutation = useMutation( | ||
| trpc.integration.testExportConnection.mutationOptions({ | ||
| onSuccess(data) { | ||
| if (data.success) { | ||
| toast.success('Connection successful! Bucket is accessible.'); | ||
| } else { | ||
| toast.error(`Connection failed: ${data.error}`); | ||
| } | ||
| }, | ||
| onError(error) { | ||
| toast.error(error.message || 'Failed to test connection'); | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const handleSubmit = (values: IForm) => { | ||
| mutation.mutate(values); | ||
| }; | ||
|
|
||
| const handleError = () => { | ||
| toast.error('Please fix validation errors'); | ||
| }; | ||
|
|
||
| const handleTest = () => { | ||
| const values = form.getValues(); | ||
| if (!values.config.bucket || !values.config.serviceAccountKey) { | ||
| return toast.error('Bucket and Service Account Key are required'); | ||
| } | ||
| testMutation.mutate(values); | ||
| }; | ||
|
|
||
| return ( | ||
| <form | ||
| onSubmit={form.handleSubmit(handleSubmit, handleError)} | ||
| className="col gap-4" | ||
| > | ||
| <InputWithLabel | ||
| label="Name" | ||
| placeholder="Eg. Production GCS Export" | ||
| {...form.register('name')} | ||
| error={form.formState.errors.name?.message} | ||
| /> | ||
|
|
||
| <div className="grid grid-cols-2 gap-4"> | ||
| <InputWithLabel | ||
| label="GCS Bucket" | ||
| placeholder="my-analytics-bucket" | ||
| {...form.register('config.bucket')} | ||
| error={path(['config', 'bucket', 'message'], form.formState.errors)} | ||
| /> | ||
| <InputWithLabel | ||
| label="Prefix" | ||
| placeholder="openpanel-exports" | ||
| {...form.register('config.prefix')} | ||
| error={path(['config', 'prefix', 'message'], form.formState.errors)} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="col gap-1.5"> | ||
| <label className="text-sm font-medium">Format</label> | ||
| <Controller | ||
| name="config.format" | ||
| control={form.control} | ||
| render={({ field }) => ( | ||
| <Select onValueChange={field.onChange} value={field.value}> | ||
| <SelectTrigger className="w-48"> | ||
| <SelectValue placeholder="Select format" /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| <SelectItem value="jsonl_gzip">JSONL (gzip)</SelectItem> | ||
| <SelectItem value="parquet" disabled> | ||
| Parquet (coming soon) | ||
| </SelectItem> | ||
| </SelectContent> | ||
| </Select> | ||
| )} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="col gap-1.5"> | ||
| <label className="text-sm font-medium"> | ||
| Service Account Key (JSON) | ||
| </label> | ||
| <textarea | ||
| className="border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring min-h-32 w-full rounded-md border px-3 py-2 text-sm focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50" | ||
| placeholder='{"type": "service_account", "project_id": "...", ...}' | ||
| {...form.register('config.serviceAccountKey')} | ||
| /> | ||
| {!!path( | ||
| ['config', 'serviceAccountKey', 'message'], | ||
| form.formState.errors, | ||
| ) && ( | ||
| <p className="text-destructive text-xs"> | ||
| { | ||
| path( | ||
| ['config', 'serviceAccountKey', 'message'], | ||
| form.formState.errors, | ||
| ) as any | ||
| } | ||
| </p> | ||
| )} | ||
| <p className="text-muted-foreground text-xs"> | ||
| Paste the contents of your GCS service account JSON key file. The | ||
| service account needs write access to the specified bucket. | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="row gap-4"> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={handleTest} | ||
| disabled={testMutation.isPending} | ||
| > | ||
| {testMutation.isPending ? 'Testing...' : 'Test connection'} | ||
| </Button> | ||
| <Button type="submit" className="flex-1" disabled={mutation.isPending}> | ||
| {mutation.isPending | ||
| ? 'Saving...' | ||
| : defaultValues?.id | ||
| ? 'Update' | ||
| : 'Create'} | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Same
namevalidation gap as the S3 form.handleTestvalidatesbucket/serviceAccountKeybut notname, whiletestExportConnectionvalidates the fullzCreateGCSExportIntegrationschema (which requiresname.min(1)). Testing before entering a Name yields a generic validation failure toast instead of a connection result. See the S3 form comment for the suggested fix.🤖 Prompt for AI Agents