mirror of
https://codeberg.org/MarkusThielker/next-ory.git
synced 2025-07-04 13:59:17 +00:00
NORY-59: move stack status requests to protected server actions
This commit is contained in:
parent
cca60935e2
commit
b29c19f322
3 changed files with 135 additions and 51 deletions
83
dashboard/src/lib/action/metadata.ts
Normal file
83
dashboard/src/lib/action/metadata.ts
Normal file
|
@ -0,0 +1,83 @@
|
|||
'use server';
|
||||
|
||||
import { getHydraMetadataApi, getKetoMetadataApi, getKratosMetadataApi } from '@/ory/sdk/server';
|
||||
import { MetadataApiReady } from '@/components/status-card';
|
||||
import { checkPermission, requireSession } from '@/lib/action/authentication';
|
||||
|
||||
export async function kratosMetadata() {
|
||||
|
||||
const session = await requireSession();
|
||||
const allowed = await checkPermission('admin.stack.status', 'access', session.identity!.id);
|
||||
if (!allowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const api = await getKratosMetadataApi();
|
||||
|
||||
const version = await api.getVersion()
|
||||
.then(res => res.data.version)
|
||||
.catch(() => undefined);
|
||||
|
||||
const status = await fetch(process.env.ORY_KRATOS_ADMIN_URL + '/health/ready')
|
||||
.then((response) => response.json() as MetadataApiReady)
|
||||
.catch(() => {
|
||||
return { errors: ['No instance running'] } as MetadataApiReady;
|
||||
});
|
||||
|
||||
return {
|
||||
version,
|
||||
status,
|
||||
};
|
||||
}
|
||||
|
||||
export async function hydraMetadata() {
|
||||
|
||||
const session = await requireSession();
|
||||
const allowed = await checkPermission('admin.stack.status', 'access', session.identity!.id);
|
||||
if (!allowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const api = await getHydraMetadataApi();
|
||||
|
||||
const version = await api.getVersion()
|
||||
.then(res => res.data.version)
|
||||
.catch(() => undefined);
|
||||
|
||||
const status = await fetch(process.env.ORY_HYDRA_ADMIN_URL + '/health/ready')
|
||||
.then((response) => response.json() as MetadataApiReady)
|
||||
.catch(() => {
|
||||
return { errors: ['No instance running'] } as MetadataApiReady;
|
||||
});
|
||||
|
||||
return {
|
||||
version,
|
||||
status,
|
||||
};
|
||||
}
|
||||
|
||||
export async function ketoMetadata() {
|
||||
|
||||
const session = await requireSession();
|
||||
const allowed = await checkPermission('admin.stack.status', 'access', session.identity!.id);
|
||||
if (!allowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
const api = await getKetoMetadataApi();
|
||||
|
||||
const version = await api.getVersion()
|
||||
.then(res => res.data.version)
|
||||
.catch(() => undefined);
|
||||
|
||||
const status = await fetch(process.env.ORY_KETO_ADMIN_URL + '/health/ready')
|
||||
.then((response) => response.json() as MetadataApiReady)
|
||||
.catch(() => {
|
||||
return { errors: ['No instance running'] } as MetadataApiReady;
|
||||
});
|
||||
|
||||
return {
|
||||
version,
|
||||
status,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue