-
Notifications
You must be signed in to change notification settings - Fork 107
feat: insecure tls & cacert for self-hosted repos #277
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import * as React from "react"; | ||
| import { ChevronDown } from "lucide-react"; | ||
| import { cn } from "~/client/lib/utils"; | ||
|
|
||
| interface CollapsibleProps extends React.HTMLAttributes<HTMLDivElement> { | ||
| open?: boolean; | ||
| onOpenChange?: (open: boolean) => void; | ||
| defaultOpen?: boolean; | ||
| } | ||
|
|
||
| const CollapsibleContext = React.createContext<{ | ||
| open: boolean; | ||
| setOpen: React.Dispatch<React.SetStateAction<boolean>>; | ||
| }>({ | ||
| open: false, | ||
| setOpen: () => {}, | ||
| }); | ||
|
|
||
| const Collapsible = React.forwardRef<HTMLDivElement, CollapsibleProps>( | ||
| ({ className, open: controlledOpen, onOpenChange, defaultOpen = false, children, ...props }, ref) => { | ||
| const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen); | ||
|
|
||
| const isControlled = controlledOpen !== undefined; | ||
| const open = isControlled ? controlledOpen : uncontrolledOpen; | ||
|
|
||
| const setOpen = React.useCallback( | ||
| (value: React.SetStateAction<boolean>) => { | ||
| const newValue = typeof value === "function" ? value(open) : value; | ||
| if (!isControlled) { | ||
| setUncontrolledOpen(newValue); | ||
| } | ||
| onOpenChange?.(newValue); | ||
| }, | ||
| [isControlled, open, onOpenChange], | ||
| ); | ||
|
|
||
| return ( | ||
| <CollapsibleContext.Provider value={{ open, setOpen }}> | ||
| <div ref={ref} className={cn(className)} {...props}> | ||
| {children} | ||
| </div> | ||
| </CollapsibleContext.Provider> | ||
| ); | ||
| }, | ||
| ); | ||
| Collapsible.displayName = "Collapsible"; | ||
|
|
||
| interface CollapsibleTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {} | ||
|
|
||
| const CollapsibleTrigger = React.forwardRef<HTMLButtonElement, CollapsibleTriggerProps>( | ||
| ({ className, children, ...props }, ref) => { | ||
| const { open, setOpen } = React.useContext(CollapsibleContext); | ||
|
|
||
| return ( | ||
| <button | ||
| ref={ref} | ||
| type="button" | ||
| className={cn( | ||
| "flex w-full items-center justify-between py-2 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180", | ||
| className, | ||
| )} | ||
| data-state={open ? "open" : "closed"} | ||
| onClick={() => setOpen(!open)} | ||
| {...props} | ||
| > | ||
| {children} | ||
| <ChevronDown className="h-4 w-4 shrink-0 transition-transform duration-200" /> | ||
| </button> | ||
| ); | ||
| }, | ||
| ); | ||
| CollapsibleTrigger.displayName = "CollapsibleTrigger"; | ||
|
|
||
| interface CollapsibleContentProps extends React.HTMLAttributes<HTMLDivElement> {} | ||
|
|
||
| const CollapsibleContent = React.forwardRef<HTMLDivElement, CollapsibleContentProps>( | ||
| ({ className, children, ...props }, ref) => { | ||
| const { open } = React.useContext(CollapsibleContext); | ||
|
|
||
| return ( | ||
| <div | ||
| ref={ref} | ||
| className={cn( | ||
| "overflow-hidden transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down", | ||
| className, | ||
| )} | ||
| data-state={open ? "open" : "closed"} | ||
| hidden={!open} | ||
| {...props} | ||
| > | ||
| {open && children} | ||
| </div> | ||
| ); | ||
| }, | ||
| ); | ||
| CollapsibleContent.displayName = "CollapsibleContent"; | ||
|
|
||
| export { Collapsible, CollapsibleTrigger, CollapsibleContent }; | ||
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
112 changes: 112 additions & 0 deletions
112
app/client/modules/repositories/components/repository-forms/advanced-tls-form.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,112 @@ | ||
| import type { UseFormReturn } from "react-hook-form"; | ||
| import { | ||
| FormControl, | ||
| FormDescription, | ||
| FormField, | ||
| FormItem, | ||
| FormLabel, | ||
| FormMessage, | ||
| } from "../../../../components/ui/form"; | ||
| import { Textarea } from "../../../../components/ui/textarea"; | ||
| import { Checkbox } from "../../../../components/ui/checkbox"; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from "../../../../components/ui/tooltip"; | ||
| import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../../../../components/ui/collapsible"; | ||
| import type { RepositoryFormValues } from "../create-repository-form"; | ||
| import { cn } from "~/client/lib/utils"; | ||
|
|
||
| type Props = { | ||
| form: UseFormReturn<RepositoryFormValues>; | ||
| }; | ||
|
|
||
| export const AdvancedForm = ({ form }: Props) => { | ||
| const insecureTls = form.watch("insecureTls"); | ||
| const cacert = form.watch("cacert"); | ||
|
|
||
| return ( | ||
| <Collapsible> | ||
| <CollapsibleTrigger className="w-full text-muted-foreground hover:no-underline"> | ||
| Advanced Settings | ||
| </CollapsibleTrigger> | ||
| <CollapsibleContent className="pb-4 space-y-4"> | ||
| <FormField | ||
| control={form.control} | ||
| name="insecureTls" | ||
| render={({ field }) => ( | ||
| <FormItem className="flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4"> | ||
| <FormControl> | ||
| <Tooltip delayDuration={500}> | ||
| <TooltipTrigger asChild> | ||
| <div> | ||
| <Checkbox | ||
| checked={field.value ?? false} | ||
| disabled={!!cacert} | ||
| onCheckedChange={(checked) => { | ||
| field.onChange(checked); | ||
| }} | ||
| /> | ||
| </div> | ||
| </TooltipTrigger> | ||
| <TooltipContent className={cn({ hidden: !cacert })}> | ||
| <p className="max-w-xs"> | ||
| This option is disabled because a CA certificate is provided. Remove the CA certificate to skip | ||
| TLS validation instead. | ||
| </p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </FormControl> | ||
| <div className="space-y-1 leading-none"> | ||
| <FormLabel>Skip TLS certificate verification</FormLabel> | ||
| <FormDescription> | ||
| Disable TLS certificate verification for HTTPS connections with self-signed certificates. This is | ||
| insecure and should only be used for testing. | ||
| </FormDescription> | ||
| </div> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| <FormField | ||
| control={form.control} | ||
| name="cacert" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>CA Certificate (Optional)</FormLabel> | ||
| <FormControl> | ||
| <Tooltip delayDuration={500}> | ||
| <TooltipTrigger asChild> | ||
| <div> | ||
| <Textarea | ||
| placeholder={"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"} | ||
| rows={6} | ||
| disabled={insecureTls} | ||
| {...field} | ||
| /> | ||
| </div> | ||
| </TooltipTrigger> | ||
| <TooltipContent className={cn({ hidden: !insecureTls })}> | ||
| <p className="max-w-xs"> | ||
| CA certificate is disabled because TLS validation is being skipped. Uncheck "Skip TLS Certificate | ||
| Verification" to provide a custom CA certificate. | ||
| </p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </FormControl> | ||
| <FormDescription> | ||
| Custom CA certificate for self-signed certificates (PEM format). This applies to HTTPS | ||
| connections. | ||
| <a | ||
| href="https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#rest-server" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="text-primary hover:underline" | ||
| > | ||
| Learn more | ||
| </a> | ||
| </FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </CollapsibleContent> | ||
| </Collapsible> | ||
| ); | ||
| }; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.