Skip to content

Commit

Permalink
more change
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Jan 6, 2025
1 parent 84e8d21 commit 6ee884c
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {

import { api } from "~/trpc/react";
import { UpdateAwsProviderDialog } from "./integrations/aws/UpdateAwsProviderDialog";
import { UpdateAzureProviderDialog } from "./integrations/azure/UpdateAzureProviderDialog";
import { UpdateGoogleProviderDialog } from "./integrations/google/UpdateGoogleProviderDialog";

type Provider = RouterOutputs["resource"]["provider"]["byWorkspaceId"][number];
Expand Down Expand Up @@ -87,6 +88,18 @@ export const ProviderActionsDropdown: React.FC<{
</DropdownMenuItem>
</UpdateAwsProviderDialog>
)}
{provider.azureConfig != null && (
<UpdateAzureProviderDialog
workspaceId={provider.workspaceId}
resourceProvider={provider}
azureConfig={provider.azureConfig}
onClose={() => setOpen(false)}
>
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>
Edit
</DropdownMenuItem>
</UpdateAzureProviderDialog>
)}
{isManagedProvider && (
<DropdownMenuItem
onSelect={async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { useRouter } from "next/navigation";
import { z } from "zod";

import { createResourceProviderAzure } from "@ctrlplane/db/schema";
import { Button } from "@ctrlplane/ui/button";
import {
Dialog,
Expand All @@ -22,16 +22,12 @@ import {
} from "@ctrlplane/ui/form";
import { Input } from "@ctrlplane/ui/input";

type AzureDialogProps = { workspaceId: string };
type CreateAzureProviderDialogProps = { workspaceId: string };

const schema = z.object({
tenantId: z.string(),
subscriptionId: z.string(),
name: z.string(),
});

export const AzureDialog: React.FC<AzureDialogProps> = ({ workspaceId }) => {
const form = useForm({ schema });
export const CreateAzureProviderDialog: React.FC<
CreateAzureProviderDialogProps
> = ({ workspaceId }) => {
const form = useForm({ schema: createResourceProviderAzure });
const router = useRouter();

const onSubmit = form.handleSubmit((data) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"use client";

import type { UpdateResourceProviderAzure } from "@ctrlplane/db/schema";
import type * as SCHEMA from "@ctrlplane/db/schema";
import { useState } from "react";
import { useRouter } from "next/navigation";

import { updateResourceProviderAzure } from "@ctrlplane/db/schema";
import { Button } from "@ctrlplane/ui/button";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@ctrlplane/ui/dialog";
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
useForm,
} from "@ctrlplane/ui/form";
import { Input } from "@ctrlplane/ui/input";

type UpdateAzureProviderDialogProps = {
workspaceId: string;
resourceProvider: SCHEMA.ResourceProvider;
azureConfig: SCHEMA.ResourceProviderAzure;
children: React.ReactNode;
onClose?: () => void;
};

export const UpdateAzureProviderDialog: React.FC<
UpdateAzureProviderDialogProps
> = ({ workspaceId, resourceProvider, azureConfig, children, onClose }) => {
const [open, setOpen] = useState(false);
const form = useForm({
schema: updateResourceProviderAzure,
defaultValues: { ...azureConfig, ...resourceProvider },
});
const router = useRouter();

const onSubmit = form.handleSubmit((data: UpdateResourceProviderAzure) => {
setOpen(false);
router.push(
`/api/azure/${workspaceId}/${data.tenantId}/${data.subscriptionId}/${data.name}?resourceProviderId=${resourceProvider.id}`,
);
});

return (
<Dialog
open={open}
onOpenChange={(o) => {
setOpen(o);
if (!o) onClose?.();
}}
>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Configure Azure</DialogTitle>
</DialogHeader>
<Form {...form}>
<form onSubmit={onSubmit} className="space-y-4">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="tenantId"
render={({ field }) => (
<FormItem>
<FormLabel>Tenant ID</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="subscriptionId"
render={({ field }) => (
<FormItem>
<FormLabel>Subscription ID</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
</FormItem>
)}
/>

<Button
type="submit"
disabled={
!form.formState.isValid ||
form.formState.isSubmitting ||
!form.formState.isDirty
}
>
Save
</Button>
</form>
</Form>
</DialogContent>
</Dialog>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { IconExternalLink } from "@tabler/icons-react";

import { cn } from "@ctrlplane/ui";
import { buttonVariants } from "@ctrlplane/ui/button";

import { api } from "~/trpc/server";

type Params = { resourceProviderId: string };

export default async function AzureProviderPage({
params,
}: {
params: Params;
}) {
const { resourceProviderId } = params;

const provider =
await api.resource.provider.managed.azure.byProviderId(resourceProviderId);

if (provider == null) return notFound();

const portalUrl = `https://portal.azure.com/#@${provider.azure_tenant.tenantId}/resource/subscriptions/${provider.resource_provider_azure.subscriptionId}/users`;

return (
<div className="mx-auto max-w-2xl space-y-6 p-4">
<div>
<h1 className="text-2xl font-bold">Next steps</h1>
<p className="text-sm text-muted-foreground">
To allow Ctrlplane to scan your Azure resources, you need to grant the
Azure service principal the necessary permissions.
</p>
</div>

<div className="space-y-4">
<div className="space-y-2">
<h2 className="text-lg font-medium">
Step 1: Go to Access Control (IAM) in the Azure portal
</h2>
<Link
href={portalUrl}
className={cn(
buttonVariants({ variant: "outline" }),
"flex w-fit items-center gap-2",
)}
target="_blank"
rel="noopener noreferrer"
>
<IconExternalLink className="h-4 w-4" /> Go to IAM
</Link>
</div>
<h2 className="text-lg font-medium">
Step 2: Click "Add role assignment"
</h2>
<div className="space-y-2">
<h2 className="text-lg font-medium">
Step 3: Configure the role assignment
</h2>
<h3></h3>
</div>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Card } from "@ctrlplane/ui/card";
import { env } from "~/env";
import { api } from "~/trpc/server";
import { AwsActionButton } from "./AwsActionButton";
import { AzureDialog } from "./azure/AzureDialog";
import { CreateAzureProviderDialog } from "./azure/CreateAzureProviderDialog";
import { GoogleActionButton } from "./GoogleActionButton";

export const metadata: Metadata = {
Expand Down Expand Up @@ -137,7 +137,7 @@ const ResourceProviders: React.FC<{ workspaceSlug: string }> = async ({
</ResourceProviderBadges>
</ResourceProviderContent>

<AzureDialog workspaceId={workspace.id} />
<CreateAzureProviderDialog workspaceId={workspace.id} />
</ResourceProviderCard>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default async function ResourceProvidersPage({
});

return (
<div className="scrollbar-thin scrollbar-thumb-neutral-700 scrollbar-track-neutral-800 h-[calc(100vh-40px)] overflow-auto">
<div className="scrollbar-thin scrollbar-thumb-neutral-700 scrollbar-track-neutral-800 h-[calc(100vh-50px)] overflow-auto">
<Table className="w-full border border-x-0 border-t-0 border-b-neutral-800/50">
<TableHeader>
<TableRow>
Expand Down
Loading

0 comments on commit 6ee884c

Please sign in to comment.