chore: use new logger
This commit is contained in:
parent
099bd3bcb8
commit
ea8ecfb28f
@ -80,8 +80,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch {
|
||||||
console.error(error)
|
|
||||||
return json({
|
return json({
|
||||||
error: 'Invalid API key',
|
error: 'Invalid API key',
|
||||||
})
|
})
|
||||||
|
|||||||
@ -9,8 +9,8 @@ import { resolve } from 'node:path'
|
|||||||
import { parse } from 'yaml'
|
import { parse } from 'yaml'
|
||||||
|
|
||||||
import { IntegrationFactory, loadIntegration } from '~/integration'
|
import { IntegrationFactory, loadIntegration } from '~/integration'
|
||||||
|
import { HeadscaleConfig, loadConfig } from '~/utils/config/headscale'
|
||||||
import { HeadscaleConfig, loadConfig } from './headscale'
|
import log from '~/utils/log'
|
||||||
|
|
||||||
export interface HeadplaneContext {
|
export interface HeadplaneContext {
|
||||||
headscaleUrl: string
|
headscaleUrl: string
|
||||||
@ -67,19 +67,26 @@ export async function loadContext(): Promise<HeadplaneContext> {
|
|||||||
context = {
|
context = {
|
||||||
headscaleUrl,
|
headscaleUrl,
|
||||||
cookieSecret,
|
cookieSecret,
|
||||||
integration: loadIntegration(),
|
integration: await loadIntegration(),
|
||||||
config: contextData,
|
config: contextData,
|
||||||
acl: await checkAcl(config),
|
acl: await checkAcl(config),
|
||||||
oidc: await checkOidc(config),
|
oidc: await checkOidc(config),
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Completed loading the Headplane Context')
|
log.info('CTXT', 'Starting Headplane with Context')
|
||||||
console.log('Headscale URL:', headscaleUrl)
|
log.info('CTXT', 'HEADSCALE_URL: %s', headscaleUrl)
|
||||||
console.log('Integration:', context.integration?.name ?? 'None')
|
log.info('CTXT', 'Integration: %s', context.integration?.name ?? 'None')
|
||||||
console.log('Config:', contextData.read ? `Found ${contextData.write ? '' : '(Read Only)'}` : 'Unavailable')
|
log.info('CTXT', 'Config: %s', contextData.read
|
||||||
console.log('ACL:', context.acl.read ? `Found ${context.acl.write ? '' : '(Read Only)'}` : 'Unavailable')
|
? `Found ${contextData.write ? '' : '(Read Only)'}`
|
||||||
console.log('OIDC:', context.oidc ? 'Configured' : 'Unavailable')
|
: 'Unavailable',
|
||||||
|
)
|
||||||
|
|
||||||
|
log.info('CTXT', 'ACL: %s', context.acl.read
|
||||||
|
? `Found ${context.acl.write ? '' : '(Read Only)'}`
|
||||||
|
: 'Unavailable',
|
||||||
|
)
|
||||||
|
|
||||||
|
log.info('CTXT', 'OIDC: %s', context.oidc ? 'Configured' : 'Unavailable')
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import { resolve } from 'node:path'
|
|||||||
import { type Document, parseDocument } from 'yaml'
|
import { type Document, parseDocument } from 'yaml'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
import log from '~/utils/log'
|
||||||
|
|
||||||
const goBool = z
|
const goBool = z
|
||||||
.union([z.boolean(), z.literal('true'), z.literal('false')])
|
.union([z.boolean(), z.literal('true'), z.literal('false')])
|
||||||
.transform((value) => {
|
.transform((value) => {
|
||||||
@ -229,13 +231,13 @@ export async function loadConfig(path?: string) {
|
|||||||
},
|
},
|
||||||
} as HeadscaleConfig
|
} as HeadscaleConfig
|
||||||
|
|
||||||
console.log('Loaded Headscale configuration in non-strict mode')
|
log.warn('CFGX', 'Loaded Headscale configuration in non-strict mode')
|
||||||
console.log('By using this mode you forfeit GitHub issue support')
|
log.warn('CFGX', 'By using this mode you forfeit GitHub issue support')
|
||||||
console.log('This is very dangerous and comes with a few caveats:')
|
log.warn('CFGX', 'This is very dangerous and comes with a few caveats:')
|
||||||
console.log('- Headplane could very easily crash')
|
log.warn('CFGX', 'Headplane could very easily crash')
|
||||||
console.log('- Headplane could break your Headscale installation')
|
log.warn('CFGX', 'Headplane could break your Headscale installation')
|
||||||
console.log('- The UI could throw random errors/show incorrect data')
|
log.warn('CFGX', 'The UI could throw random errors/show incorrect data')
|
||||||
console.log('')
|
log.warn('CFGX', '')
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,19 +245,19 @@ export async function loadConfig(path?: string) {
|
|||||||
config = await HeadscaleConfig.parseAsync(configYaml.toJSON())
|
config = await HeadscaleConfig.parseAsync(configYaml.toJSON())
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof z.ZodError) {
|
if (error instanceof z.ZodError) {
|
||||||
console.log('Failed to parse the Headscale configuration file!')
|
log.error('CFGX', 'Recieved invalid configuration file')
|
||||||
console.log('The following schema issues were found:')
|
log.error('CFGX', 'The following schema issues were found:')
|
||||||
for (const issue of error.issues) {
|
for (const issue of error.issues) {
|
||||||
const path = issue.path.map(String).join('.')
|
const path = issue.path.map(String).join('.')
|
||||||
const message = issue.message
|
const message = issue.message
|
||||||
|
|
||||||
console.log(`- '${path}': ${message}`)
|
log.error('CFGX', ` '${path}': ${message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('')
|
log.error('CFGX', '')
|
||||||
console.log('Please fix the configuration file and try again.')
|
log.error('CFGX', 'Resolve these issues and try again.')
|
||||||
console.log('Headplane will operate as if no config is present.')
|
log.error('CFGX', 'Headplane will operate without the config')
|
||||||
console.log('')
|
log.error('CFGX', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user