Skip to content
Open
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
3 changes: 2 additions & 1 deletion .mise/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ run = [{ task = "*:fix" }, { task = "web:lingui" }]
[env]
# default environment variables for development
NODE_ENV = "development"
YUCCA_API_PORT = 3000
YUCCA_API_PORT = 3020
RESTIC_API_PORT = 3010
S3_ACCESS_KEY_ID = "minio"
S3_SECRET_ACCESS_KEY = "miniominio"
Expand All @@ -57,6 +57,7 @@ POSTGRES_HOST = "localhost"
POSTGRES_USERNAME = "postgres"
POSTGRES_PASSWORD = "postgres"
POSTGRES_DATABASE = "yucca"
POSTGRES_PORT = 15432
JWT_SECRET = "cca13c34b450a77c1d4b9ecd25dff6aebc6d7417afdb31864f5943c59abd03a1"
OIDC_ISSUER = "http://localhost:8092"
OIDC_CLIENT_ID = "client ID"
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
POSTGRES_USER: postgres
POSTGRES_DB: yucca
ports:
- 5432:5432
- 15432:5432
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres -d yucca']
interval: 1s
Expand Down
2 changes: 1 addition & 1 deletion packages/common/server/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const schema = z.object({
S3_FORCE_PATH_STYLE: z.coerce.boolean().default(false),

POSTGRES_HOST: z.string(),
POSTGRES_PORT: z.number().default(5432),
POSTGRES_PORT: z.coerce.number().default(5432),
POSTGRES_USERNAME: z.string(),
POSTGRES_PASSWORD: z.string(),
POSTGRES_DATABASE: z.string(),
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

<main class="p-4">
<Button
onclick={() => (location.href = defaults.baseUrl + "api/auth/oidc/login")}
onclick={() =>
(location.href = defaults.baseUrl + "api/yucca/auth/oidc/login")}
>{$t`Login`}</Button
>

Expand Down
11 changes: 6 additions & 5 deletions packages/web/src/routes/dashboard/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { page } from "$app/state";
import {
AppShell,
AppShellHeader,
Expand All @@ -9,11 +10,10 @@
HStack,
NavbarItem,
} from "@immich/ui";
import { defaults } from "yucca-api-client";
import { t } from "svelte-i18n-lingui";
import { page } from "$app/state";
import { mdiViewDashboard, mdiBackupRestore } from "@mdi/js";
import { mdiBackupRestore, mdiViewDashboard } from "@mdi/js";
import { setProvider, yuccaApiProvider } from "orchestration-ui";
import { t } from "svelte-i18n-lingui";
import { defaults } from "yucca-api-client";

const { data, children } = $props();

Expand All @@ -29,7 +29,8 @@
<HStack>
<Avatar name={data.user!.name} />
<Button
onclick={() => (location.href = defaults.baseUrl + "api/auth/logout")}
onclick={() =>
(location.href = defaults.baseUrl + "api/yucca/auth/logout")}
>{$t`Logout`}</Button
>
</HStack>
Expand Down
2 changes: 1 addition & 1 deletion packages/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:3000/',
target: `http://localhost:${process.env.YUCCA_API_PORT}/`,
secure: true,
changeOrigin: true,
ws: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/yucca-api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CryptoRepository } from './repositories/crypto.repository';
import { DatabaseRepository } from './repositories/database.repository';
import { OidcRepository } from './repositories/oidc.repository';
import { RepositoryRepository } from './repositories/repository.repository';
import { ResticApiRepository } from './repositories/resticApi.repository';
import { SessionRepository } from './repositories/session.repository';
import { UserRepository } from './repositories/user.repository';
import { AuthService } from './services/auth.service';
Expand All @@ -31,6 +32,7 @@ export const controllers = [AuthController, RepositoryController];
export const providers = [
WideContextRepository,
LoggerRepository,
ResticApiRepository,
DatabaseRepository,
CryptoRepository,
OidcRepository,
Expand Down
10 changes: 10 additions & 0 deletions packages/yucca-api/src/repositories/resticApi.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { env } from '@common/server/env';
import { Injectable } from '@nestjs/common';

@Injectable()
export class ResticApiRepository {
getEndpoint() {
return new URL(`http://100.64.0.6:${env.RESTIC_API_PORT}`);
// return new URL(`http://localhost:${env.RESTIC_API_PORT}`);
}
}
11 changes: 9 additions & 2 deletions packages/yucca-api/src/services/repository.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { env } from '@common/server/env';
import { WideContextRepository } from '@common/server/otel';
import { Injectable, Scope, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { AuthDto } from 'src/dto/auth.dto';
import { RepositoryCreateRequestDto, RepositoryUpdateRequestDto } from 'src/dto/repository.dto';
import { RepositoryRepository } from 'src/repositories/repository.repository';
import { ResticApiRepository } from 'src/repositories/resticApi.repository';

@Injectable({ scope: Scope.REQUEST })
export class RepositoryService {
constructor(
private readonly jwt: JwtService,
private readonly repositoryRepository: RepositoryRepository,
private readonly wideContext: WideContextRepository,
private readonly resticApi: ResticApiRepository,
) {}

async create(auth: AuthDto, dto: RepositoryCreateRequestDto) {
Expand Down Expand Up @@ -80,6 +81,12 @@ export class RepositoryService {
});

this.wideContext.addContext('repositoryId', repository.id);
return { url: `rest:http://restic:${token}@localhost:${env.RESTIC_API_PORT}/${repository.id}/` };

const url = this.resticApi.getEndpoint();
url.username = 'restic';
url.password = token;
url.pathname = repository.id;

return { url: url.href };
}
}
6 changes: 3 additions & 3 deletions packages/yucca-sdk/orchestration-api/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ async function bootstrap() {
}),
);

app.enableCors();
app.enableCors({ origin: 'http://localhost:5174' });
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.setGlobalPrefix('/api');
await app.listen(ORCHESTRATION_PORT);
app.setGlobalPrefix('/api/yucca');
await app.listen(ORCHESTRATION_PORT, '127.0.0.1');
}

void bootstrap();
2 changes: 1 addition & 1 deletion packages/yucca-sdk/orchestration-api/bin/sync-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
}),
);

app.setGlobalPrefix('api');
app.setGlobalPrefix('api/yucca');

const builder = new DocumentBuilder()
.setTitle('yucca')
Expand Down
43 changes: 20 additions & 23 deletions packages/yucca-sdk/orchestration-api/openapi-specs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi": "3.0.0",
"paths": {
"/api/auth/oidc/login": {
"/api/yucca/auth/oidc/login": {
"get": {
"operationId": "oidcAuthorize",
"parameters": [
Expand All @@ -24,7 +24,7 @@
]
}
},
"/api/auth/oidc/callback": {
"/api/yucca/auth/oidc/callback": {
"get": {
"operationId": "oidcCallback",
"parameters": [],
Expand All @@ -38,7 +38,7 @@
]
}
},
"/api/backend": {
"/api/yucca/backend": {
"get": {
"operationId": "getBackends",
"parameters": [],
Expand All @@ -59,7 +59,7 @@
]
}
},
"/api/debug": {
"/api/yucca/debug": {
"get": {
"operationId": "resetOrchestrator",
"parameters": [],
Expand All @@ -73,7 +73,7 @@
]
}
},
"/api/fs": {
"/api/yucca/fs": {
"get": {
"operationId": "getFileListing",
"parameters": [
Expand Down Expand Up @@ -103,7 +103,7 @@
]
}
},
"/api/onboarding": {
"/api/yucca/onboarding": {
"get": {
"operationId": "onboardingStatus",
"parameters": [],
Expand All @@ -124,7 +124,7 @@
]
}
},
"/api/onboarding/recovery-key": {
"/api/yucca/onboarding/recovery-key": {
"get": {
"operationId": "currentRecoveryKey",
"parameters": [],
Expand Down Expand Up @@ -179,7 +179,7 @@
]
}
},
"/api/repository": {
"/api/yucca/repository": {
"post": {
"operationId": "createRepository",
"parameters": [
Expand Down Expand Up @@ -238,7 +238,7 @@
]
}
},
"/api/repository/{id}": {
"/api/yucca/repository/{id}": {
"patch": {
"operationId": "updateRepository",
"parameters": [
Expand Down Expand Up @@ -314,7 +314,7 @@
]
}
},
"/api/repository/{id}/import": {
"/api/yucca/repository/{id}/import": {
"get": {
"operationId": "checkImportRepository",
"parameters": [
Expand Down Expand Up @@ -388,7 +388,7 @@
]
}
},
"/api/repository/{id}/runs": {
"/api/yucca/repository/{id}/runs": {
"get": {
"operationId": "getRunHistory",
"parameters": [
Expand Down Expand Up @@ -418,7 +418,7 @@
]
}
},
"/api/repository/{id}/snapshots": {
"/api/yucca/repository/{id}/snapshots": {
"get": {
"operationId": "getSnapshots",
"parameters": [
Expand Down Expand Up @@ -448,7 +448,7 @@
]
}
},
"/api/repository/{id}/snapshots/{snapshot}": {
"/api/yucca/repository/{id}/snapshots/{snapshot}": {
"post": {
"operationId": "restoreSnapshot",
"parameters": [
Expand Down Expand Up @@ -532,7 +532,7 @@
]
}
},
"/api/repository/{id}/snapshots/{snapshot}/listing": {
"/api/yucca/repository/{id}/snapshots/{snapshot}/listing": {
"get": {
"operationId": "getSnapshotListing",
"parameters": [
Expand Down Expand Up @@ -578,7 +578,7 @@
]
}
},
"/api/logs/{id}": {
"/api/yucca/logs/{id}": {
"get": {
"operationId": "logStreamSse",
"parameters": [
Expand All @@ -601,7 +601,7 @@
]
}
},
"/api/tasks": {
"/api/yucca/tasks": {
"get": {
"operationId": "getRunningTasks",
"parameters": [],
Expand All @@ -622,7 +622,7 @@
]
}
},
"/api/schedule": {
"/api/yucca/schedule": {
"post": {
"operationId": "createSchedule",
"parameters": [],
Expand Down Expand Up @@ -672,7 +672,7 @@
]
}
},
"/api/schedule/{id}": {
"/api/yucca/schedule/{id}": {
"patch": {
"operationId": "updateSchedule",
"parameters": [
Expand Down Expand Up @@ -733,7 +733,7 @@
]
}
},
"/api/schedule/{id}/{repositoryId}": {
"/api/yucca/schedule/{id}/{repositoryId}": {
"put": {
"operationId": "addRepositoryToSchedule",
"parameters": [
Expand Down Expand Up @@ -863,10 +863,7 @@
"type": "string"
},
"isDirectory": {
"type": "array",
"items": {
"type": "boolean"
}
"type": "boolean"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FilesystemListingItemDto {
@ApiProperty({ type: () => String })
path!: string;

@ApiProperty({ type: () => [Boolean] })
@ApiProperty({ type: () => Boolean })
isDirectory!: boolean;
}

Expand Down
19 changes: 18 additions & 1 deletion packages/yucca-sdk/orchestration-api/src/dto/schedule.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsArray, IsBoolean, IsOptional, IsString } from 'class-validator';
import { IsArray, IsBoolean, IsOptional, IsString, Validate, ValidatorConstraint, type ValidatorConstraintInterface } from 'class-validator';
import { CronJob } from 'cron';

@ValidatorConstraint({ name: 'cronValidator' })
class CronValidator implements ValidatorConstraintInterface {
validate(expression: string): boolean {
try {
new CronJob(expression, () => {});
return true;
} catch {
return false;
}
}
}

const IsCronExpression = () => Validate(CronValidator, { message: 'Invalid cron expression' });

export class ScheduleDto {
@ApiProperty({ type: String })
Expand Down Expand Up @@ -31,6 +46,7 @@ export class ScheduleCreateRequestDto {

@ApiProperty({ type: String })
@IsString()
@IsCronExpression()
cron!: string;

@ApiProperty({ type: [String] })
Expand Down Expand Up @@ -58,6 +74,7 @@ export class ScheduleUpdateRequestDto {
@ApiProperty({ type: String, required: false })
@IsOptional()
@IsString()
@IsCronExpression()
cron?: string;

@ApiProperty({ type: [String], required: false })
Expand Down
Loading
Loading