Commit bda5235f authored by David Nichols's avatar David Nichols
Browse files

added an HTTP file handler building block to the repo (tests pending!)

parent 086a1d7d
Pipeline #21090 passed with stage
in 12 minutes and 15 seconds
......@@ -19,6 +19,9 @@ TEST_FILES=$(shell find test -name \*.q\* -o -name \*.yaml | sort)
TESTS=$(shell find test -name \*.qtest | sort)
#MAKE_RELEASE=~/src/Qorus/git/qorus-docker/remote/python/make-release.py
MAKE_RELEASE=make-release
all:
@echo "usage: make release|load-all|load-building-blocks|load-tests|test"
@echo " release: make the building block release package"
......@@ -30,7 +33,7 @@ all:
dummy:
release: ${BB_FILES} ${BB_JAVA} ${BB_MODULES}
make-release -mcf -U. -Puser/building-blocks building-blocks-$(VERSION) $^
${MAKE_RELEASE} -mcf -U. -Puser/building-blocks building-blocks-$(VERSION) $^
load-all: load-building-blocks load-tests
load-bb: load-building-blocks
......@@ -52,7 +55,7 @@ load-building-blocks: ${BB_FILES}
cp $$mod ${OMQ_DIR}/user/modules; \
done
# make a temporary load file
make-release -l/tmp/building-blocks.qrf -U. $^
${MAKE_RELEASE} -l/tmp/building-blocks.qrf -U. $^
# load the release
oload /tmp/building-blocks.qrf -lvRA
# delete the temporary load file
......@@ -60,7 +63,7 @@ load-building-blocks: ${BB_FILES}
load-tests: ${TEST_FILES}
# make a temporary load file
make-release -l/tmp/building-blocks-tests.qrf -U. $^
${MAKE_RELEASE} -l/tmp/building-blocks-tests.qrf -U. $^
# load the release
oload /tmp/building-blocks-tests.qrf -lvRA
# delete the temporary load file
......
......@@ -46,8 +46,9 @@
"generic",
"service",
"job",
"kafka",
"kafka",
"step",
"test"
"test",
"zookeeper"
]
}
%new-style
%strict-args
%require-types
%enable-all-warnings
%requires Util
#! The base HTTP handler class
class BBM_HttpFileHandlerBase inherits ServiceFileHandler, BBM_HttpAuthenticatorBase, BBM_CorsBase {
public {
const ErrorMap = {
"NONE": 0,
"BRIEF": 1,
"VERBOSE": 2,
};
}
#! Creates the object
constructor() :
ServiceFileHandler(
substitute_env_vars(ServiceApi::getConfigItemValue("http-file-handler-file-root")),
BBM_HttpFileHandlerBase::getRootUriPath(),
BBM_HttpFileHandlerBase::getOptions(),
),
BBM_CorsBase("http") {
}
static string getRootUriPath() {
string uri_path = ServiceApi::getConfigItemValue("http-root-uri");
if (uri_path != "/") {
uri_path =~ s/^\///;
}
return uri_path;
}
static *hash<auto> getOptions() {
# return constructor options
return {
"default_target": ServiceApi::getConfigItemValue("http-file-handler-default-target"),
#"po": ServiceApi::getConfigItemValue("http-file-handler-template-parse-options"),
"auth": BBM_HttpAuthenticatorBase::getAuthenticator("http-auth-name"),
"error_level": ErrorMap{ServiceApi::getConfigItemValue("http-file-handler-error-level")},
};
}
#! top-level request handling method
hash<HttpResponseInfo> handleRequest(HttpListenerInterface listener, Socket s, hash<auto> cx, hash<auto> hdr, *data body) {
if (hdr.method == "OPTIONS") {
return handleOptions(cx);
}
hash<HttpResponseInfo> rv = ServiceFileHandler::handleRequest(listener, s, cx, hdr, body);
if ((rv."code" / 100) == 2) {
rv.hdr += getCorsResponseHeaders(cx);
}
return rv;
}
}
#! The HTTP service base class; includes a parametrized handler class as well
class BBM_HttpFileHandler inherits BBM_HttpServiceGenericBase {
private AbstractServiceHttpHandler getHandlerImpl() {
return new BBM_HttpFileHandlerBase();
}
}
# This is a generated file, don't edit!
type: class
name: BBM_HttpFileHandler
desc: A generic building block for HTTP file handling
lang: qore
author:
- Qore Technologies, s.r.o.
base-class-name: BBM_HttpServiceGenericBase
requires:
- BBM_HttpServiceGenericBase
- BBM_HttpAuthenticatorBase
- BBM_CorsBase
version: "1.0"
code: BBM_HttpFileHandler-1.0.qclass
config-items:
- name: http-listener-bind-address
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-cert-location
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-cert-format
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-key-location
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-key-format
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-key-password
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-ssl-mode
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-accept-all-certs
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-listener-capture-client-certs
parent:
interface-type: class
interface-name: BBM_HttpServiceGenericBase
interface-version: "1.0"
- name: http-root-uri
description: "The root URI path for the HTTP service"
strictly_local: true
config_group: HTTP Handler
- name: http-root-uri-is-regex
default_value:
false
type: bool
description: "set to true if 'root-uri' is a regular expression pattern"
config_group: HTTP Handler
- name: http-auth-name
default_value:
"default"
allowed_values:
- "permissive"
- "default"
- "default-basic"
config_group: HTTP Handler
description: "A string identifying the authenticator; the following values are allowed:\n
- **`default`**: the default Qorus authenticator; new connections must have valid credentials for Qorus\n
- **`default-basic`**: the same as **`default`** except in case of an unauthorized request, a `WWW-Authenticate` header is returned indicating that HTTP basic authentication is required\n
- **`permissive`**: no authentication is required; all requests are automatically accepted"
strictly_local: true
- name: http-match-content-types
default_value:
null
type: "*list"
description: "an optional list of string content types that will cause external requests to match this handler"
config_group: HTTP Handler
- name: http-match-headers
default_value:
null
type: "*list"
description: "an optional list of string header names (in lower case) that will cause external requests with those headers to match this handler"
config_group: HTTP Handler
- name: http-cors-enable
default_value:
false
config_group: HTTP Handler CORS
description: set to `true` to enable CORS
strictly_local: true
type: bool
- name: http-cors-methods
default_value:
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
config_group: HTTP Handler CORS
description: HTTP methods allowed with CORS; ignored if `http-cors-enable` is `false`
strictly_local: true
type: list
- name: http-cors-max-age
default_value:
9999999
config_group: HTTP Handler CORS
description: the value for the `Access-Control-Max-Age` header
strictly_local: true
type: int
- name: http-cors-headers
default_value:
- Content-Type
- content-type
- Content-Language
- content-language
- Accept
- Accept-Language
- Authorization
config_group: HTTP Handler CORS
description: values for the `Access-Control-Allow-Headers` header
strictly_local: true
type: "*list"
- name: http-cors-credentials
default_value:
false
config_group: HTTP Handler CORS
description: 'if `true` then the `Access-Control-Allow-Credentials: true` header is sent'
strictly_local: true
type: bool
- name: http-file-handler-file-root
description: The filesystem root directory for serving files
config_group: HTTP/S File Handler Main
strictly_local: true
- name: http-file-handler-default-target
default_value:
null
description: >-
The default relative URI path (i.e. default resource) to serve if a request
cannot be satisfied
config_group: HTTP/S File Handler Main
type: "*string"
strictly_local: true
- name: http-file-handler-error-level
default_value:
"BRIEF"
description: |-
The default level of error reporting:
- `NONE`: no errors are reported
- `BRIEF`: a brief one-line description of errors is reported
- `VERBOSE`: the full stack trace is reported for errors
config_group: HTTP/S File Handler Main
allowed_values:
- "NONE"
- "BRIEF"
- "VERBOSE"
strictly_local: true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment