feat: add known hosts
This commit is contained in:
parent
ecf10628c3
commit
3afb7d5cf4
3 changed files with 159 additions and 46 deletions
|
|
@ -5,6 +5,7 @@ let
|
|||
allowedProxyContentKeys = [ "type" "ip" "port" "proxyWebsockets" ];
|
||||
allowedWebContentKeys = [ "type" "files" ];
|
||||
allowedWebFileKeys = [ "path" "filePath" "contentType" "status" ];
|
||||
allowedInlineContentKeys = [ "body" "contentType" "status" ];
|
||||
|
||||
ensureNoUnknownKeys = context: obj: allowedKeys:
|
||||
let
|
||||
|
|
@ -37,10 +38,10 @@ let
|
|||
else
|
||||
throw "Endpoint at index ${toString index} must define type as a string.";
|
||||
_type =
|
||||
if lib.elem typeValue [ "proxy" "web" ] then
|
||||
if lib.elem typeValue [ "proxy" "web" "inline" ] then
|
||||
null
|
||||
else
|
||||
throw "Endpoint at index ${toString index} type must be 'proxy' or 'web'.";
|
||||
throw "Endpoint at index ${toString index} type must be 'proxy', 'web', or 'inline'.";
|
||||
_domain =
|
||||
if endpoint ? domain && builtins.isString endpoint.domain && endpoint.domain != "" then
|
||||
null
|
||||
|
|
@ -62,13 +63,14 @@ let
|
|||
else
|
||||
throw "Endpoint at index ${toString index} must define force_ssl as a bool.";
|
||||
contentValue =
|
||||
if endpoint ? content && builtins.isAttrs endpoint.content then
|
||||
if endpoint ? content then
|
||||
endpoint.content
|
||||
else
|
||||
throw "Endpoint at index ${toString index} must define content as an attrset.";
|
||||
throw "Endpoint at index ${toString index} must define content.";
|
||||
_content =
|
||||
if typeValue == "proxy" then
|
||||
let
|
||||
_attrs = if builtins.isAttrs contentValue then null else throw "Proxy endpoint at index ${toString index} must define content as an attrset.";
|
||||
____ = ensureNoUnknownKeys "Proxy content at endpoint index ${toString index}" contentValue allowedProxyContentKeys;
|
||||
in
|
||||
if !(contentValue ? type) || !builtins.isString contentValue.type then
|
||||
|
|
@ -82,51 +84,78 @@ let
|
|||
else
|
||||
null
|
||||
else
|
||||
let
|
||||
____ = ensureNoUnknownKeys "Web content at endpoint index ${toString index}" contentValue allowedWebContentKeys;
|
||||
filesValue =
|
||||
if contentValue ? files && builtins.isList contentValue.files then
|
||||
contentValue.files
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} must define content.files as a list.";
|
||||
_____ =
|
||||
if contentValue ? type && contentValue.type == "store" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} must define content.type = 'store'.";
|
||||
______ = lib.imap0 (fileIndex: file:
|
||||
if typeValue == "web" then
|
||||
let
|
||||
_attrs = if builtins.isAttrs contentValue then null else throw "Web endpoint at index ${toString index} must define content as an attrset.";
|
||||
____ = ensureNoUnknownKeys "Web content at endpoint index ${toString index}" contentValue allowedWebContentKeys;
|
||||
filesValue =
|
||||
if contentValue ? files && builtins.isList contentValue.files then
|
||||
contentValue.files
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} must define content.files as a list.";
|
||||
_____ =
|
||||
if contentValue ? type && contentValue.type == "store" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} must define content.type = 'store'.";
|
||||
______ = lib.imap0 (fileIndex: file:
|
||||
let
|
||||
_______ =
|
||||
if builtins.isAttrs file then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must be an attrset.";
|
||||
________ = ensureNoUnknownKeys "Web endpoint at index ${toString index} file at position ${toString fileIndex}" file allowedWebFileKeys;
|
||||
_________ =
|
||||
if file ? path && builtins.isString file.path && file.path != "" && builtins.substring 0 1 file.path != "/" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define path as a relative path string.";
|
||||
__________ =
|
||||
if file ? filePath && (builtins.isString file.filePath || builtins.isPath file.filePath) then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define filePath as string or path.";
|
||||
___________ =
|
||||
if file ? contentType && builtins.isString file.contentType && file.contentType != "" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define contentType as non-empty string.";
|
||||
____________ =
|
||||
if file ? status && builtins.isInt file.status then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define status as int.";
|
||||
in
|
||||
file
|
||||
) filesValue;
|
||||
in
|
||||
null
|
||||
else
|
||||
if builtins.isString contentValue then
|
||||
null
|
||||
else if builtins.isAttrs contentValue then
|
||||
let
|
||||
____ = ensureNoUnknownKeys "Inline content at endpoint index ${toString index}" contentValue allowedInlineContentKeys;
|
||||
_____ =
|
||||
if contentValue ? body && builtins.isString contentValue.body then
|
||||
null
|
||||
else
|
||||
throw "Inline endpoint at index ${toString index} must define content.body as a string when content is an attrset.";
|
||||
______ =
|
||||
if !(contentValue ? contentType) || (builtins.isString contentValue.contentType && contentValue.contentType != "") then
|
||||
null
|
||||
else
|
||||
throw "Inline endpoint at index ${toString index} content.contentType must be a non-empty string when provided.";
|
||||
_______ =
|
||||
if builtins.isAttrs file then
|
||||
if !(contentValue ? status) || builtins.isInt contentValue.status then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must be an attrset.";
|
||||
________ = ensureNoUnknownKeys "Web endpoint at index ${toString index} file at position ${toString fileIndex}" file allowedWebFileKeys;
|
||||
_________ =
|
||||
if file ? path && builtins.isString file.path && file.path != "" && builtins.substring 0 1 file.path != "/" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define path as a relative path string.";
|
||||
__________ =
|
||||
if file ? filePath && (builtins.isString file.filePath || builtins.isPath file.filePath) then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define filePath as string or path.";
|
||||
___________ =
|
||||
if file ? contentType && builtins.isString file.contentType && file.contentType != "" then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define contentType as non-empty string.";
|
||||
____________ =
|
||||
if file ? status && builtins.isInt file.status then
|
||||
null
|
||||
else
|
||||
throw "Web endpoint at index ${toString index} file at position ${toString fileIndex} must define status as int.";
|
||||
throw "Inline endpoint at index ${toString index} content.status must be an int when provided.";
|
||||
in
|
||||
file
|
||||
) filesValue;
|
||||
in
|
||||
null;
|
||||
null
|
||||
else
|
||||
throw "Inline endpoint at index ${toString index} must define content as a string or an attrset.";
|
||||
in
|
||||
endpoint;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue