mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Store the hidden flag and allowed hosts on a secret
This commit is contained in:
1 parent
d7131dd895
commit
0a5c514062
9 files changed
+378
-23
No files matched your search
@@ -59,10 +59,64 @@ export const SecretValueSchema = z
|
||||
`Value must be at most ${SECRET_VALUE_MAX_BYTES} bytes`,
|
||||
)
|
||||
|
||||
export const SetSecretRequestSchema = z.object({
|
||||
value: SecretValueSchema,
|
||||
environment: EnvironmentNameSchema.optional(),
|
||||
})
|
||||
export const SECRET_ALLOWED_HOSTS_MAX = 20
|
||||
|
||||
const SECRET_ALLOWED_HOST_MAX_LENGTH = 253
|
||||
|
||||
const ALLOWED_HOST_LABEL_PATTERN = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?'
|
||||
|
||||
const ALLOWED_HOST_PATTERN = new RegExp(
|
||||
`^(?:\\*\\.)?(?:${ALLOWED_HOST_LABEL_PATTERN}\\.)*${ALLOWED_HOST_LABEL_PATTERN}$`,
|
||||
'i',
|
||||
)
|
||||
|
||||
export const SecretAllowedHostSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.superRefine((host, ctx) => {
|
||||
if (host.length > SECRET_ALLOWED_HOST_MAX_LENGTH) {
|
||||
ctx.addIssue({ code: 'custom', message: `Host must be at most ${SECRET_ALLOWED_HOST_MAX_LENGTH} characters` })
|
||||
return
|
||||
}
|
||||
if (!ALLOWED_HOST_PATTERN.test(host) || /^\d+$/.test(host.split('.').pop() ?? '')) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Host must be a hostname or a *.wildcard hostname without a scheme, port, path, or IP address',
|
||||
})
|
||||
}
|
||||
})
|
||||
.transform((host) => host.toLowerCase())
|
||||
|
||||
export const SetSecretRequestSchema = z
|
||||
.object({
|
||||
value: SecretValueSchema,
|
||||
environment: EnvironmentNameSchema.optional(),
|
||||
agentHidden: z.boolean().optional(),
|
||||
allowedHosts: z.array(SecretAllowedHostSchema).max(SECRET_ALLOWED_HOSTS_MAX).optional(),
|
||||
})
|
||||
.superRefine((data, ctx) => {
|
||||
const hosts = data.allowedHosts ?? []
|
||||
if (data.agentHidden === true) {
|
||||
if (hosts.length === 0) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Hidden secrets require at least one allowed host',
|
||||
path: ['allowedHosts'],
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
if (hosts.length > 0) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'Allowed hosts require agentHidden to be true',
|
||||
path: ['allowedHosts'],
|
||||
})
|
||||
}
|
||||
})
|
||||
.transform((data) =>
|
||||
data.allowedHosts ? { ...data, allowedHosts: [...new Set(data.allowedHosts)] } : data,
|
||||
)
|
||||
|
||||
export type SetSecretRequest = z.infer<typeof SetSecretRequestSchema>
|
||||
|
||||
@@ -71,6 +125,8 @@ export const SecretEntrySchema = z.object({
|
||||
environment: z.string().nullable(),
|
||||
updatedAt: z.number(),
|
||||
value: z.string().optional(),
|
||||
agentHidden: z.boolean().optional(),
|
||||
allowedHosts: z.array(z.string()).optional(),
|
||||
})
|
||||
|
||||
export type SecretEntry = z.infer<typeof SecretEntrySchema>
|
||||
|
||||
Reference in new issue
Block a user