From dacda2913734dfe9d863c07942c382b3127ac200 Mon Sep 17 00:00:00 2001 From: Christophe Mehay Date: Sat, 9 May 2020 18:04:14 +0200 Subject: [PATCH] Do not exit if matched environment variable cannot be parsed --- Dockerfile | 13 ++++++++---- Makefile | 5 ++++- onions/Onions.py | 54 +++++++++++++++++++++++++++++------------------- poetry.lock | 43 ++++---------------------------------- pyproject.toml | 5 +++-- tox.ini | 2 +- 6 files changed, 54 insertions(+), 68 deletions(-) diff --git a/Dockerfile b/Dockerfile index 05ae0d7..d277663 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,19 +23,24 @@ RUN apk add --no-cache git libevent-dev openssl-dev gcc make automake ca-cer RUN mkdir -p /etc/tor/ -COPY onions /usr/local/src/onions/onions -COPY poetry.lock pyproject.toml /usr/local/src/onions/ -COPY assets/torrc /var/local/tor/torrc.tpl +COPY pyproject.toml /usr/local/src/onions/ RUN cd /usr/local/src/onions && apk add --no-cache openssl-dev libffi-dev gcc libc-dev && \ - poetry install --no-dev && \ + poetry install --no-dev --no-root && \ apk del libffi-dev gcc libc-dev openssl-dev +COPY onions /usr/local/src/onions/onions +COPY poetry.lock /usr/local/src/onions/ +RUN cd /usr/local/src/onions && poetry install --no-dev + RUN mkdir -p ${HOME}/.tor && \ addgroup -S -g 107 tor && \ adduser -S -G tor -u 104 -H -h ${HOME} tor COPY assets/entrypoint-config.yml / +COPY assets/torrc /var/local/tor/torrc.tpl + + VOLUME ["/var/lib/tor/hidden_service/"] diff --git a/Makefile b/Makefile index 3a0533e..60f5fbd 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ rebuild: docker-compose -f docker-compose.build.yml build --no-cache run: build - docker-compose -f docker-compose-v1.yml up --force-recreate + docker-compose -f docker-compose.v1.yml up --force-recreate run-v2: build docker-compose -f docker-compose.v2.yml up --force-recreate @@ -35,5 +35,8 @@ run-v2-socket: build run-v3: build docker-compose -f docker-compose.v3.yml up --force-recreate +shell-v3: build + docker-compose -f docker-compose.v3.yml run tor--rm tor sh + run-v3-latest: docker-compose -f docker-compose.v3.latest.yml up --force-recreate diff --git a/onions/Onions.py b/onions/Onions.py index 5ad2fa7..2a36d40 100644 --- a/onions/Onions.py +++ b/onions/Onions.py @@ -116,7 +116,11 @@ class Setup(object): for key, val in os.environ.items(): m = match(reg, key) if m: - self.add_new_service(host=m.groups()[0].lower(), name=val) + try: + self.add_new_service(host=m.groups()[0].lower(), name=val) + except BaseException as e: + logging.error(f"Fail to setup from {key} environment") + logging.error(e) def _set_ports(self, host, ports): self.add_new_service(host=host, ports=ports) @@ -129,7 +133,11 @@ class Setup(object): for key, val in os.environ.items(): m = match(reg, key) if m: - call(m.groups()[0].lower(), val) + try: + call(m.groups()[0].lower(), val) + except BaseException as e: + logging.error(f"Fail to setup from {key} environment") + logging.error(e) def _setup_keys_and_ports_from_env(self): self._setup_from_env( @@ -228,29 +236,33 @@ class Setup(object): self.apply_conf() def check_services(self): + to_remove = set() for group in self.services: - for service in group.services: - if not service.ports: - raise Exception( - 'Service {name} has not ports set'.format( - name=service.host + try: + for service in group.services: + if not service.ports: + raise Exception( + 'Service {name} has not ports set'.format( + name=service.host + ) ) - ) - if len(group.services) > 1 and [ - True for p in service.ports if p.is_socket - ]: - raise Exception( - 'Cannot use socket and ports ' - 'in the same service'.format( - name=service.host + if len(group.services) > 1 and [ + True for p in service.ports if p.is_socket + ]: + raise Exception( + f'Cannot use socket and ports ' + f'in the same {service.host}' ) + if len(set(dict(group)['urls'])) != len(dict(group)['urls']): + raise Exception( + f'Same port for multiple services in ' + f'{group.name} group' ) - if len(set(dict(group)['urls'])) != len(dict(group)['urls']): - raise Exception( - 'Same port for multiple services in {name} group'.format( - name=group.name - ) - ) + except Exception as e: + logging.error(e) + to_remove.add(group) + for group in to_remove: + self.services.remove(group) class Onions(Setup): diff --git a/poetry.lock b/poetry.lock index 202d8cd..f80c4f2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -171,9 +171,8 @@ version = "1.4.15" license = ["editdistance"] [[package]] -category = "dev" +category = "main" description = "Read metadata from Python packages" -marker = "python_version < \"3.8\"" name = "importlib-metadata" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" @@ -186,27 +185,6 @@ zipp = ">=0.5" docs = ["sphinx", "rst.linker"] testing = ["packaging", "importlib-resources"] -[[package]] -category = "dev" -description = "Read resources from Python packages" -marker = "python_version < \"3.7\"" -name = "importlib-resources" -optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" -version = "1.5.0" - -[package.dependencies] -[package.dependencies.importlib-metadata] -python = "<3.8" -version = "*" - -[package.dependencies.zipp] -python = "<3.8" -version = ">=0.4" - -[package.extras] -docs = ["sphinx", "rst.linker", "jaraco.packaging"] - [[package]] category = "dev" description = "A Python utility / library to sort Python imports." @@ -365,10 +343,6 @@ virtualenv = ">=15.2" python = "<3.8" version = "*" -[package.dependencies.importlib-resources] -python = "<3.7" -version = "*" - [[package]] category = "dev" description = "Library for building powerful interactive command lines in Python" @@ -604,10 +578,6 @@ six = ">=1.9.0,<2" python = "<3.8" version = ">=0.12,<2" -[package.dependencies.importlib-resources] -python = "<3.7" -version = ">=1.0,<2" - [package.extras] docs = ["sphinx (>=3)", "sphinx-argparse (>=0.2.5)", "sphinx-rtd-theme (>=0.4.3)", "towncrier (>=19.9.0rc1)", "proselint (>=0.10.2)"] testing = ["pytest (>=4)", "coverage (>=5)", "coverage-enable-subprocess (>=1)", "pytest-xdist (>=1.31.0)", "pytest-mock (>=2)", "pytest-env (>=0.6.2)", "pytest-randomly (>=1)", "pytest-timeout", "packaging (>=20.0)", "xonsh (>=0.9.16)"] @@ -643,9 +613,8 @@ python-versions = "*" version = "1.12.1" [[package]] -category = "dev" +category = "main" description = "Backport of pathlib-compatible object wrapper for zip files" -marker = "python_version < \"3.8\"" name = "zipp" optional = false python-versions = ">=3.6" @@ -656,8 +625,8 @@ docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["jaraco.itertools", "func-timeout"] [metadata] -content-hash = "d633e7f5e1330a54e28f987277095aa445a44f022d4407e2da8588fdff49ee2f" -python-versions = ">= 3.6.1, < 3.8" +content-hash = "6e1eec0c17109c00a24dd51d3bb7a6a47fe528bd4ef6a0da0679fd513dbf8adc" +python-versions = ">= 3.7, < 3.8" [metadata.files] appdirs = [ @@ -765,10 +734,6 @@ importlib-metadata = [ {file = "importlib_metadata-1.6.0-py2.py3-none-any.whl", hash = "sha256:2a688cbaa90e0cc587f1df48bdc97a6eadccdcd9c35fb3f976a09e3b5016d90f"}, {file = "importlib_metadata-1.6.0.tar.gz", hash = "sha256:34513a8a0c4962bc66d35b359558fd8a5e10cd472d37aec5f66858addef32c1e"}, ] -importlib-resources = [ - {file = "importlib_resources-1.5.0-py2.py3-none-any.whl", hash = "sha256:85dc0b9b325ff78c8bef2e4ff42616094e16b98ebd5e3b50fe7e2f0bbcdcde49"}, - {file = "importlib_resources-1.5.0.tar.gz", hash = "sha256:6f87df66833e1942667108628ec48900e02a4ab4ad850e25fbf07cb17cf734ca"}, -] isort = [ {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, {file = "isort-4.3.21.tar.gz", hash = "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1"}, diff --git a/pyproject.toml b/pyproject.toml index 83cdec3..d416d34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ classifiers=[ "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.7", "Topic :: System :: Installation/Setup", ] packages = [ @@ -23,10 +23,11 @@ packages = [ onions = "onions:main" [tool.poetry.dependencies] -python = ">= 3.6.1, < 3.8" +python = ">= 3.7, < 3.8" pytor = "^0.1.5" Jinja2 = "^2.10" pyentrypoint = "^0.5.2" +importlib_metadata = "^1.6.0" [tool.poetry.dev-dependencies] autopep8 = "^1.5.2" diff --git a/tox.ini b/tox.ini index e997cb2..474299f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] isolated_build = true -envlist = py36, py37 +envlist = py37 [testenv] whitelist_externals = poetry