feat: create certificate on demand
This commit is contained in:
@@ -62,7 +62,7 @@ docker-build: ## docker build
|
|||||||
|
|
||||||
.PHONY: docker-run
|
.PHONY: docker-run
|
||||||
docker-run: docker-build ## docker run
|
docker-run: docker-build ## docker run
|
||||||
@$(DOCKER) run -it -p $(PORT):8080 -v ./data:/data $(DOCKER_TAG) --debug --no-certbot run --token $(TOKEN)
|
@$(DOCKER) run -it -p $(PORT):8080 -v ./data:/data $(DOCKER_TAG) --debug --no-certbot --token $(TOKEN) run
|
||||||
|
|
||||||
# ACTIONS
|
# ACTIONS
|
||||||
|
|
||||||
|
|||||||
@@ -93,13 +93,12 @@ curl -X DELETE \
|
|||||||
- [x] better logger
|
- [x] better logger
|
||||||
- [x] renew command
|
- [x] renew command
|
||||||
- [x] https mode w/ multiple hosts
|
- [x] https mode w/ multiple hosts
|
||||||
- [ ] restart command (on new/deleted host)
|
- [x] create certificate on request
|
||||||
- [ ] proper doc
|
- [ ] certbot symlink certificates for unique path
|
||||||
- [ ] log visits (and store accross sessions)
|
|
||||||
- [ ] deliver visits in /page/visits
|
|
||||||
- [x] better error page
|
- [x] better error page
|
||||||
- [ ] add favicon.ico + special path
|
- [ ] add favicon.ico + special path
|
||||||
- [ ] [http.server security](https://docs.python.org/3/library/http.server.html#http-server-security)
|
- [ ] [http.server security](https://docs.python.org/3/library/http.server.html#http-server-security)
|
||||||
|
- [ ] proper doc
|
||||||
|
|
||||||
### Makefile targets
|
### Makefile targets
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -8,7 +8,7 @@ import re
|
|||||||
import tarfile
|
import tarfile
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from . import data_dir, logs, project
|
from . import cert, data_dir, logs, project
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from . import params, registry
|
from . import params, registry
|
||||||
@@ -27,6 +27,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
*args: typing.Any,
|
*args: typing.Any,
|
||||||
params: params.Parameters,
|
params: params.Parameters,
|
||||||
registry: registry.Registry,
|
registry: registry.Registry,
|
||||||
|
cert_manager: cert.CertManager,
|
||||||
**kwargs: dict[str, typing.Any],
|
**kwargs: dict[str, typing.Any],
|
||||||
) -> None:
|
) -> None:
|
||||||
self.logger = logging.getLogger(self.__class__.__name__)
|
self.logger = logging.getLogger(self.__class__.__name__)
|
||||||
@@ -35,6 +36,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
self.data_dir = data_dir.DataDir(params.data_dir)
|
self.data_dir = data_dir.DataDir(params.data_dir)
|
||||||
self.max_size_bytes = params.max_size_bytes
|
self.max_size_bytes = params.max_size_bytes
|
||||||
self.registry = registry
|
self.registry = registry
|
||||||
|
self.cert_manager = cert_manager
|
||||||
self.certbot_www = os.path.realpath(params.certbot_www)
|
self.certbot_www = os.path.realpath(params.certbot_www)
|
||||||
self.out_size = 0
|
self.out_size = 0
|
||||||
super().__init__(*args, directory=params.data_dir, **kwargs)
|
super().__init__(*args, directory=params.data_dir, **kwargs)
|
||||||
@@ -79,7 +81,8 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
http.HTTPStatus.CREATED,
|
http.HTTPStatus.CREATED,
|
||||||
f"Resource /{sub_path}/ updated",
|
f"Resource /{sub_path}/ updated",
|
||||||
)
|
)
|
||||||
if host is not None:
|
self.registry.add(sub_path)
|
||||||
|
if host is not None and self.cert_manager.create_or_update(host):
|
||||||
self.registry.set_host(sub_path, host)
|
self.registry.set_host(sub_path, host)
|
||||||
self.registry.add(sub_path)
|
self.registry.add(sub_path)
|
||||||
return None
|
return None
|
||||||
|
|||||||
+6
-1
@@ -18,7 +18,12 @@ class StaplerServer:
|
|||||||
self.default_host = params.host.split(":", maxsplit=2)[0]
|
self.default_host = params.host.split(":", maxsplit=2)[0]
|
||||||
|
|
||||||
def request_handler(self, *args: typing.Any) -> http.server.BaseHTTPRequestHandler:
|
def request_handler(self, *args: typing.Any) -> http.server.BaseHTTPRequestHandler:
|
||||||
return handler.RequestHandler(*args, params=self.params, registry=self.registry)
|
return handler.RequestHandler(
|
||||||
|
*args,
|
||||||
|
params=self.params,
|
||||||
|
registry=self.registry,
|
||||||
|
cert_manager=self.cert_manager,
|
||||||
|
)
|
||||||
|
|
||||||
def __get_all_hosts(self) -> list[str]:
|
def __get_all_hosts(self) -> list[str]:
|
||||||
return [self.default_host, *self.registry.get_hosts()]
|
return [self.default_host, *self.registry.get_hosts()]
|
||||||
|
|||||||
Reference in New Issue
Block a user