-
Notifications
You must be signed in to change notification settings - Fork 19
Feat/mothership v2 #1551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/mothership v2 #1551
Changes from 3 commits
ff94160
5959549
fcf74d3
67944eb
90ed837
81cc9ff
92e30e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "createdAt": "2025-07-19T22:29:38.790Z", | ||
| "description": "Internal API Key Used By Unraid Connect to access your server resources for the connect.myunraid.net dashboard", | ||
| "id": "7789353b-40f4-4f3b-a230-b1f22909abff", | ||
| "key": "e6e0212193fa1cb468194dd5a4e41196305bc3b5e38532c2f86935bbde317bd0", | ||
| "name": "ConnectInternal", | ||
| "permissions": [], | ||
| "roles": [ | ||
| "CONNECT" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "connectionStatus": "PRE_INIT", | ||
| "error": null, | ||
| "lastPing": null, | ||
| "allowedOrigins": "", | ||
| "timestamp": 1753974976746 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,7 @@ export class CloudService { | |
|
|
||
| private async hardCheckCloud(apiVersion: string, apiKey: string): Promise<CloudResponse> { | ||
| try { | ||
| const mothershipGqlUri = this.configService.getOrThrow<string>('MOTHERSHIP_GRAPHQL_LINK'); | ||
| const mothershipGqlUri = this.configService.getOrThrow<string>('MOTHERSHIP_BASE_URL'); | ||
| const ip = await this.checkDns(); | ||
| const { canReach, baseUrl } = await this.canReachMothership( | ||
| mothershipGqlUri, | ||
|
|
@@ -204,7 +204,7 @@ export class CloudService { | |
| } | ||
|
|
||
| private async hardCheckDns() { | ||
| const mothershipGqlUri = this.configService.getOrThrow<string>('MOTHERSHIP_GRAPHQL_LINK'); | ||
| const mothershipGqlUri = this.configService.getOrThrow<string>('MOTHERSHIP_BASE_URL'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Search for all references to MOTHERSHIP_BASE_URL and MOTHERSHIP_GRAPHQL_LINK
echo "=== MOTHERSHIP_BASE_URL references ==="
rg -n "MOTHERSHIP_BASE_URL" --type ts --type tsx --type js --type jsx
echo -e "\n=== MOTHERSHIP_GRAPHQL_LINK references ==="
rg -n "MOTHERSHIP_GRAPHQL_LINK" --type ts --type tsx --type js --type jsx
echo -e "\n=== Environment configuration files ==="
fd -e env -e env.example --type fRepository: unraid/api Length of output: 250 🏁 Script executed: # Retry search without problematic file types
echo "=== MOTHERSHIP_BASE_URL references ==="
rg -n "MOTHERSHIP_BASE_URL"
echo -e "\n=== MOTHERSHIP_GRAPHQL_LINK references ==="
rg -n "MOTHERSHIP_GRAPHQL_LINK"
echo -e "\n=== Environment files ==="
find . -name ".env*" -type f | grep -v node_modules | head -20Repository: unraid/api Length of output: 1773 🏁 Script executed: # Read the cloud.service.ts file to understand the context
cat -n packages/unraid-api-plugin-connect/src/connection-status/cloud.service.ts | sed -n '90,110p'
echo -e "\n=== Context around line 207 ==="
cat -n packages/unraid-api-plugin-connect/src/connection-status/cloud.service.ts | sed -n '200,220p'
echo -e "\n=== Check environment.ts for MOTHERSHIP_BASE_URL ==="
rg -n "MOTHERSHIP_BASE_URL" api/src/environment.tsRepository: unraid/api Length of output: 2233 🏁 Script executed: # Check environment.ts for configuration definitions
cat -n api/src/environment.ts | sed -n '90,105p'
echo -e "\n=== Full search for MOTHERSHIP_BASE_URL in entire repo ==="
find . -type f \( -name "*.ts" -o -name "*.js" -o -name ".env*" \) ! -path "*/node_modules/*" -exec grep -l "MOTHERSHIP_BASE_URL" {} \;Repository: unraid/api Length of output: 1184 🏁 Script executed: # Check .env.development for MOTHERSHIP_BASE_URL
cat -n api/.env.development | grep -A2 -B2 "MOTHERSHIP"
echo -e "\n=== Full content of .env.development ==="
cat api/.env.developmentRepository: unraid/api Length of output: 2102 🏁 Script executed: # Check other .env files for MOTHERSHIP_BASE_URL
echo "=== .env.staging ==="
grep "MOTHERSHIP" api/.env.staging
echo -e "\n=== .env.production ==="
grep "MOTHERSHIP" api/.env.production
echo -e "\n=== .env.test ==="
grep "MOTHERSHIP" api/.env.test
echo -e "\n=== plugin/.env.example ==="
grep "MOTHERSHIP" plugin/.env.example
echo -e "\n=== Check if MOTHERSHIP_BASE_URL should be in environment.ts ==="
rg -n "export const MOTHERSHIP" api/src/environment.tsRepository: unraid/api Length of output: 417 🏁 Script executed: # Verify configService type and how it accesses config
rg -n "configService.getOrThrow" packages/unraid-api-plugin-connect/src/connection-status/cloud.service.ts | head -5
echo -e "\n=== Check ConfigService implementation ==="
fd -n "config.service" packages/unraid-api-plugin-connect/src --type f
echo -e "\n=== Check if there's a NestJS ConfigModule setup ==="
rg -n "ConfigModule" packages/unraid-api-plugin-connect/src --type ts | head -10Repository: unraid/api Length of output: 1415 Critical: Incomplete refactoring with missing environment configuration for Line 207 uses Furthermore, Required fixes:
🤖 Prompt for AI Agents |
||
| const hostname = new URL(mothershipGqlUri).host; | ||
| const lookup = promisify(lookupDNS); | ||
| const resolve = promisify(resolveDNS); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { Injectable, Logger, OnApplicationBootstrap, OnModuleDestroy } from '@nestjs/common'; | ||
| import { ConfigService } from '@nestjs/config'; | ||
| import { OnEvent } from '@nestjs/event-emitter'; | ||
| import { unlink, writeFile } from 'fs/promises'; | ||
| import { mkdir, unlink, writeFile } from 'fs/promises'; | ||
| import { dirname } from 'path'; | ||
|
|
||
| import { ConfigType, ConnectionMetadata } from '../config/connect.config.js'; | ||
| import { EVENTS } from '../helper/nest-tokens.js'; | ||
|
|
@@ -13,8 +14,8 @@ export class ConnectStatusWriterService implements OnApplicationBootstrap, OnMod | |
| private logger = new Logger(ConnectStatusWriterService.name); | ||
|
|
||
| get statusFilePath() { | ||
| // Use environment variable if provided, otherwise use default path | ||
| return process.env.PATHS_CONNECT_STATUS_FILE_PATH ?? '/var/local/emhttp/connectStatus.json'; | ||
| // Use environment variable if set, otherwise default to /var/local/emhttp/connectStatus.json | ||
| return this.configService.get('PATHS_CONNECT_STATUS') || '/var/local/emhttp/connectStatus.json'; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFix critical path handling issue causing pipeline failures. The pipeline failures indicate that The issue is likely that the configuration value is not being properly typed or retrieved. Apply this fix: get statusFilePath() {
- // Use environment variable if set, otherwise default to /var/local/emhttp/connectStatus.json
- return this.configService.get('PATHS_CONNECT_STATUS') || '/var/local/emhttp/connectStatus.json';
+ // Use environment variable if set, otherwise default to /var/local/emhttp/connectStatus.json
+ return this.configService.get<string>('PATHS_CONNECT_STATUS') || '/var/local/emhttp/connectStatus.json';
}Run this script to verify the configuration service implementation: 🏁 Script executed: #!/bin/bash
# Description: Check how PATHS_CONNECT_STATUS is configured in the environment and config service
# Find configuration files that might define PATHS_CONNECT_STATUS
rg -n "PATHS_CONNECT_STATUS" --type json --type ts
# Look for ConfigService usage patterns
ast-grep --pattern 'configService.get($$$)'Length of output: 428 Enforce string type and validate PATHS_CONNECT_STATUS to prevent TypeError Ensure the config value is both statically typed and runtime-validated in • File: packages/unraid-api-plugin-connect/src/connection-status/connect-status-writer.service.ts get statusFilePath(): string {
- // Use environment variable if set, otherwise default to /var/local/emhttp/connectStatus.json
- return this.configService.get('PATHS_CONNECT_STATUS') || '/var/local/emhttp/connectStatus.json';
+ // Use environment variable if set, otherwise default to /var/local/emhttp/connectStatus.json
+ const rawPath = this.configService.get<string>('PATHS_CONNECT_STATUS');
+ if (typeof rawPath !== 'string') {
+ throw new TypeError(
+ `Invalid config "PATHS_CONNECT_STATUS": expected string, received ${typeof rawPath}`
+ );
+ }
+ return rawPath || '/var/local/emhttp/connectStatus.json';
}Also verify in your configuration files (JSON,
🤖 Prompt for AI Agents |
||
|
|
||
| async onApplicationBootstrap() { | ||
|
|
@@ -59,6 +60,10 @@ export class ConnectStatusWriterService implements OnApplicationBootstrap, OnMod | |
| const data = JSON.stringify(statusData, null, 2); | ||
| this.logger.verbose(`Writing connection status: ${data}`); | ||
|
|
||
| // Ensure the directory exists before writing | ||
| const dir = dirname(this.statusFilePath); | ||
| await mkdir(dir, { recursive: true }); | ||
|
|
||
| await writeFile(this.statusFilePath, data); | ||
| this.logger.verbose(`Status written to ${this.statusFilePath}`); | ||
| } catch (error) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add quotes around the value on line 22.
The
.envfile format requires quoted values for consistent parsing by dotenv libraries.Apply this fix:
📝 Committable suggestion
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 22-22: [UnorderedKey] The PATHS_CONNECT_STATUS key should go before the PATHS_CONNECT_STATUS_FILE_PATH key
(UnorderedKey)
[warning] 22-22: [ValueWithoutQuotes] This value needs to be surrounded in quotes
(ValueWithoutQuotes)
🤖 Prompt for AI Agents