Skip to content

Commit

Permalink
Dynamic auth set up
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina committed Jul 31, 2024
1 parent c606ce2 commit 6e7a8ae
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 199 deletions.
15 changes: 13 additions & 2 deletions ui/api/kafka/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@ export async function getKafkaClusters(): Promise<ClusterList[]> {
const url = `${process.env.BACKEND_URL}/api/kafkas?${kafkaClustersQuery}`;
try {
const res = await fetch(url, {
headers: await getHeaders(),
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
const rawData = await res.json();
log.trace(rawData, "getKafkaClusters response");
return ClustersResponseSchema.parse(rawData).data;
return ClustersResponseSchema.parse(rawData).data.map((c) => ({
...c,
attributes: {
...c.attributes,
authMethod: {
method: "scram-sha",
},
},
}));
} catch (err) {
log.error(err, "getKafkaClusters");
return [];
Expand Down
100 changes: 67 additions & 33 deletions ui/api/kafka/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ export const ClusterListSchema = z.object({
name: z.string(),
namespace: z.string().nullable().optional(),
kafkaVersion: z.string().nullable().optional(),
authMethod: z
.union([
z.object({
method: z.literal("anonymous"),
}),
z.object({
method: z.literal("scram-sha"),
}),
z.object({
method: z.literal("oauth"),
clientId: z.string(),
clientSecret: z.string(),
issuer: z.string(),
}),
])
.nullable()
.optional(),
}),
});
export const ClustersResponseSchema = z.object({
Expand All @@ -35,22 +52,28 @@ const ClusterDetailSchema = z.object({
nodes: z.array(NodeSchema),
controller: NodeSchema,
authorizedOperations: z.array(z.string()),
listeners: z.array(
z.object({
type: z.string(),
bootstrapServers: z.string().nullable(),
authType: z.string().nullable(),
}),
).nullable().optional(),
conditions: z.array(
z.object({
type: z.string().optional(),
status: z.string().optional(),
reason: z.string().optional(),
message: z.string().optional(),
lastTransitionTime: z.string().optional(),
}),
).nullable().optional(),
listeners: z
.array(
z.object({
type: z.string(),
bootstrapServers: z.string().nullable(),
authType: z.string().nullable(),
}),
)
.nullable()
.optional(),
conditions: z
.array(
z.object({
type: z.string().optional(),
status: z.string().optional(),
reason: z.string().optional(),
message: z.string().optional(),
lastTransitionTime: z.string().optional(),
}),
)
.nullable()
.optional(),
nodePools: z.array(z.string()).optional().nullable(),
}),
});
Expand All @@ -64,24 +87,35 @@ export const ClusterKpisSchema = z.object({
total_topics: z.number().optional(),
total_partitions: z.number().optional(),
underreplicated_topics: z.number().optional(),
replica_count: z.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
}).optional(),
leader_count: z.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
}).optional(),
volume_stats_capacity_bytes: z.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
}).optional(),
volume_stats_used_bytes: z.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
}).optional(),
replica_count: z
.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
})
.optional(),
leader_count: z
.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
})
.optional(),
volume_stats_capacity_bytes: z
.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
})
.optional(),
volume_stats_used_bytes: z
.object({
byNode: z.record(z.number()).optional(),
total: z.number().optional(),
})
.optional(),
});
export type ClusterKpis = z.infer<typeof ClusterKpisSchema>;

export const MetricRangeSchema = z.record(z.string(), z.record(z.number()).optional());
export const MetricRangeSchema = z.record(
z.string(),
z.record(z.number()).optional(),
);
export type MetricRange = z.infer<typeof MetricRangeSchema>;
7 changes: 3 additions & 4 deletions ui/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { AppLayoutProvider } from "@/app/[locale]/AppLayoutProvider";
import { AppSessionProvider } from "@/app/[locale]/AppSessionProvider";
import NextIntlProvider from "@/app/[locale]/NextIntlProvider";
import { SessionRefresher } from "@/app/[locale]/SessionRefresher";
import { getAuthOptions } from "@/app/api/auth/[...nextauth]/route";

import { authOptions } from "@/utils/authOptions";
import { getServerSession } from "next-auth";
import { getTranslations } from "next-intl/server";
import { notFound } from "next/navigation";
Expand All @@ -23,16 +23,15 @@ export default async function Layout({ children, params: { locale } }: Props) {
} catch (error) {
notFound();
}
const authOptions = await getAuthOptions();
const session = await getServerSession(authOptions);
return (
<html lang="en">
<body>
<NextIntlProvider locale={locale} messages={messages}>
<AppSessionProvider session={session}>
<AppLayoutProvider>
<AppLayout>
{children}
</AppLayout>
<AppLayout>{children}</AppLayout>
</AppLayoutProvider>
<SessionRefresher />
</AppSessionProvider>
Expand Down
17 changes: 17 additions & 0 deletions ui/app/api/auth/[...nextauth]/anonymous.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";

export function makeAnonymous(): AuthOptions {
const provider = CredentialsProvider({
name: "Unauthenticated",
credentials: {},
async authorize() {
return { id: "1", name: "Anonymous", email: "[email protected]" };
},
});

return {
providers: [provider],
callbacks: {},
};
}
Loading

0 comments on commit 6e7a8ae

Please sign in to comment.