Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/private';
import { CONTROL_PANEL_ADMIN_ENAMES_FILE } from '$env/static/private';
import { readFile, stat } from 'node:fs/promises';
import { resolve } from 'node:path';

Expand All @@ -19,7 +19,7 @@ export function normalizeEName(value: string): string {
}

function getAllowlistPath(): string {
const configuredPath = env.CONTROL_PANEL_ADMIN_ENAMES_FILE?.trim();
const configuredPath = CONTROL_PANEL_ADMIN_ENAMES_FILE?.trim();
return resolve(process.cwd(), configuredPath || DEFAULT_ALLOWLIST_PATH);
}

Expand Down
4 changes: 2 additions & 2 deletions infrastructure/control-panel/src/lib/server/auth/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/private';
import { CONTROL_PANEL_JWT_SECRET } from '$env/static/private';
import { jwtVerify, SignJWT } from 'jose';

export const AUTH_COOKIE_NAME = 'control_panel_auth';
Expand All @@ -9,7 +9,7 @@ type AuthTokenPayload = {
};

function getJwtSecret(): Uint8Array {
const secret = env.CONTROL_PANEL_JWT_SECRET || 'control-panel-dev-secret-change-me';
const secret = CONTROL_PANEL_JWT_SECRET || 'control-panel-dev-secret-change-me';
return new TextEncoder().encode(secret);
}

Expand Down
8 changes: 4 additions & 4 deletions infrastructure/control-panel/src/lib/services/loki.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/private';
import { LOKI_PASSWORD, LOKI_URL, LOKI_USERNAME } from '$env/static/private';

export interface LogEntry {
timestamp: string;
Expand Down Expand Up @@ -34,9 +34,9 @@ export class LokiService {
private processedLogIds = new Set<string>(); // Track processed logs to prevent duplicates

constructor() {
this.baseUrl = env.LOKI_URL || 'http://localhost:3100';
this.username = env.LOKI_USERNAME || 'admin';
this.password = env.LOKI_PASSWORD || 'admin';
this.baseUrl = LOKI_URL || 'http://localhost:3100';
this.username = LOKI_USERNAME || 'admin';
this.password = LOKI_PASSWORD || 'admin';
}

private getAuthHeaders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { env } from '$env/dynamic/private';
import {
NOTIFICATION_TRIGGER_PORT,
NOTIFICATION_TRIGGER_URL,
PROVISIONER_URL,
PUBLIC_PROVISIONER_URL
} from '$env/static/private';

export interface NotificationPayload {
title: string;
Expand All @@ -22,9 +27,9 @@ export interface SendResult {
}

function getBaseUrl(): string {
const url = env.NOTIFICATION_TRIGGER_URL;
const url = NOTIFICATION_TRIGGER_URL;
if (url) return url;
const port = env.NOTIFICATION_TRIGGER_PORT || '3998';
const port = NOTIFICATION_TRIGGER_PORT || '3998';
return `http://localhost:${port}`;
}

Expand All @@ -49,9 +54,7 @@ export async function sendNotification(request: SendNotificationRequest): Promis
}

export async function getDevicesWithTokens(): Promise<{ token: string; eName: string }[]> {
const { env } = await import('$env/dynamic/private');
const provisionerUrl =
env.PUBLIC_PROVISIONER_URL || env.PROVISIONER_URL || 'http://localhost:3001';
const provisionerUrl = PUBLIC_PROVISIONER_URL || PROVISIONER_URL || 'http://localhost:3001';
try {
const response = await fetch(`${provisionerUrl}/api/devices/list`, {
signal: AbortSignal.timeout(10000)
Expand All @@ -68,9 +71,7 @@ export async function getDevicesWithTokens(): Promise<{ token: string; eName: st
export async function getDevicesByEName(
eName: string
): Promise<{ token: string; eName: string }[]> {
const { env } = await import('$env/dynamic/private');
const provisionerUrl =
env.PUBLIC_PROVISIONER_URL || env.PROVISIONER_URL || 'http://localhost:3001';
const provisionerUrl = PUBLIC_PROVISIONER_URL || PROVISIONER_URL || 'http://localhost:3001';
try {
const response = await fetch(
`${provisionerUrl}/api/devices/by-ename/${encodeURIComponent(eName)}`,
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/control-panel/src/lib/services/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { env } from '$env/dynamic/public';
import { PUBLIC_REGISTRY_URL } from '$env/static/public';

export interface Platform {
name: string;
Expand All @@ -19,7 +19,7 @@ export class RegistryService {
private baseUrl: string;

constructor() {
this.baseUrl = env.PUBLIC_REGISTRY_URL || 'https://registry.w3ds.metastate.foundation';
this.baseUrl = PUBLIC_REGISTRY_URL || 'https://registry.w3ds.metastate.foundation';
}

async getEVaults(): Promise<RegistryVault[]> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { env } from '$env/dynamic/public';
import { PUBLIC_CONTROL_PANEL_URL } from '$env/static/public';
import { json, type RequestHandler } from '@sveltejs/kit';
import { createAuthSession } from '$lib/server/auth/sessions';

export const GET: RequestHandler = async ({ url }) => {
const sessionId = createAuthSession();
const baseUrl = env.PUBLIC_CONTROL_PANEL_URL || url.origin;
const baseUrl = PUBLIC_CONTROL_PANEL_URL || url.origin;
const redirect = new URL('/api/auth', baseUrl).toString();
const platform = 'control-panel';
const uri = `w3ds://auth?redirect=${encodeURIComponent(redirect)}&session=${encodeURIComponent(sessionId)}&platform=${encodeURIComponent(platform)}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';
import { PUBLIC_CONTROL_PANEL_URL, PUBLIC_REGISTRY_URL } from '$env/static/public';
import { registryService, type RegistryVault } from '$lib/services/registry';

const USER_ONTOLOGY_ID = '550e8400-e29b-41d4-a716-446655440000';
Expand Down Expand Up @@ -143,7 +143,7 @@ async function resolveVaultIdentity(
}

async function requestPlatformToken(platform: string): Promise<string> {
const registryUrl = env.PUBLIC_REGISTRY_URL || 'https://registry.staging.metastate.foundation';
const registryUrl = PUBLIC_REGISTRY_URL || 'https://registry.staging.metastate.foundation';
const response = await fetch(new URL('/platforms/certification', registryUrl).toString(), {
method: 'POST',
headers: {
Expand All @@ -167,7 +167,7 @@ async function requestPlatformToken(platform: string): Promise<string> {

export const GET: RequestHandler = async ({ url }) => {
try {
const platform = env.PUBLIC_CONTROL_PANEL_URL || url.origin;
const platform = PUBLIC_CONTROL_PANEL_URL || url.origin;
let token: string | undefined;
try {
token = await requestPlatformToken(platform);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { EREPUTATION_BASE_URL, VISUALIZER_API_KEY } from '$env/static/private';

export const GET: RequestHandler = async () => {
const baseUrl = env.EREPUTATION_BASE_URL || 'http://localhost:8765';
const baseUrl = EREPUTATION_BASE_URL || 'http://localhost:8765';

try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 5000);
const response = await fetch(`${baseUrl}/api/references/all`, {
headers: env.VISUALIZER_API_KEY ? { 'x-visualizer-key': env.VISUALIZER_API_KEY } : {},
headers: VISUALIZER_API_KEY ? { 'x-visualizer-key': VISUALIZER_API_KEY } : {},
signal: controller.signal
});
clearTimeout(timeout);
Expand Down
Loading