-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Oldřich Jedlička <[email protected]>
- Loading branch information
0 parents
commit 2686055
Showing
12 changed files
with
992 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/.project | ||
/.pydevproject | ||
/SubregSimulator.egg-info/ | ||
*.pyc | ||
*.crt | ||
*.pem | ||
*.key | ||
subregsim.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Dockerfile for production (sources taken from Git) | ||
# 1. Build as: docker build -t subregsim:latest . | ||
# 2. Prepare configuration file and certificates (both optional) - see argument "-c" in next step | ||
# 3. Run as: docker run --rm -it -v $PWD/server-certificate.crt:/config/server-certificate.crt -v $PWD/server-certificate.key:/config/server-certificate.key -v $PWD/subregsim.conf:/config/subregsim.conf subregsim:latest -c /config/subregsim.conf | ||
|
||
# Base image | ||
FROM alpine:edge as base | ||
|
||
RUN mkdir /python | ||
ENV PYTHONUSERBASE=/python | ||
ENV PATH="$PYTHONUSERBASE/bin:$PATH" | ||
|
||
RUN apk add --no-cache python3~3.6 py3-openssl | ||
|
||
# Build phase | ||
FROM base as build | ||
|
||
RUN mkdir /build | ||
WORKDIR /build | ||
|
||
RUN apk add --no-cache git py3-setuptools && \ | ||
pip3 install --upgrade pip | ||
|
||
RUN git clone -q https://github.com/oldium/subregsim.git && \ | ||
cd subregsim && \ | ||
pip3 install --user -r requirements.txt && \ | ||
pip3 install --user . | ||
|
||
# Final phase | ||
FROM base | ||
|
||
EXPOSE 80 443 | ||
|
||
COPY --from=build /python /python | ||
|
||
ENTRYPOINT ["/python/bin/subregsim"] | ||
CMD ["--help"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Docker file for development (sources taken from the current directory) | ||
# 1. Build as: docker build -t subregsim:develop-latest -f Dockerfile.development . | ||
# 2. Prepare configuration file and certificates (both optional) - see argument "-c" in next step | ||
# 3. Run as: docker run --rm -it -v $PWD/server-certificate.crt:/config/server-certificate.crt -v $PWD/server-certificate.key:/config/server-certificate.key -v $PWD/subregsim.conf:/config/subregsim.conf -v $PWD/.:/source subregsim:develop-latest -c /config/subregsim.conf | ||
|
||
# Base image | ||
FROM alpine:edge as base | ||
|
||
RUN mkdir /python | ||
ENV PYTHONUSERBASE=/python | ||
ENV PATH="$PYTHONUSERBASE/bin:$PATH" | ||
|
||
RUN apk add --no-cache python3~3.6 py3-openssl | ||
|
||
# Build phase | ||
FROM base as build | ||
|
||
RUN mkdir /build | ||
WORKDIR /build | ||
|
||
RUN apk add --no-cache git py3-setuptools && \ | ||
pip3 install --upgrade pip | ||
|
||
RUN mkdir /source | ||
WORKDIR /source | ||
|
||
COPY requirements.txt /source/ | ||
RUN cd /source && pip3 install --user -r requirements.txt | ||
|
||
COPY setup.py setup.cfg README.md /source/ | ||
COPY ./subregsim /source/subregsim | ||
RUN pip3 install --user -e . | ||
|
||
# Final phase | ||
FROM base | ||
|
||
EXPOSE 80 443 | ||
|
||
COPY --from=build /python /python | ||
|
||
RUN mkdir /source | ||
VOLUME ["/source"] | ||
|
||
ENTRYPOINT ["/python/bin/subregsim"] | ||
CMD ["--help"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License version 3 as | ||
published by the Free Software Foundation. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Include the README | ||
include *.md | ||
|
||
# Include the license file | ||
include LICENSE.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Simple Subreg.cz API simulator | ||
|
||
The simulator of the Subreg.cz API implements just few methods fulfilling | ||
needs of the Python [lexicon][lexicon] library. | ||
|
||
The home page of the project is [here][subregsim-home]. | ||
|
||
[lexicon]: https://github.com/AnalogJ/lexicon | ||
[subregsim-home]: https://github.com/oldium/subregsim | ||
|
||
## Installation | ||
|
||
Fetch the sources: | ||
|
||
``` | ||
git clone -q https://github.com/oldium/subregsim.git | ||
cd subregsim | ||
``` | ||
|
||
Install dependencies: | ||
|
||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
Install subregsim Python package, including the `subregsim` binary (like in | ||
`Dockerfile`): | ||
|
||
``` | ||
pip install . | ||
``` | ||
|
||
or in editable mode (like in `Dockerfile.development`): | ||
|
||
``` | ||
pip install -e . | ||
``` | ||
|
||
|
||
## Configuration | ||
|
||
### Basic Setup | ||
|
||
The configuration can be supplied in two ways: | ||
|
||
1. See `subregsim.conf.sample`, copy it to `subregsim.conf` and change it to | ||
suite your needs. Use `-c subregsim.conf` argument to `subregsim`. | ||
|
||
2. All configuration options can be supplied on command-line. | ||
|
||
### SSL Setup | ||
|
||
#### Local Certificate Authority | ||
|
||
Generate self-signed certificate for your Certificate Authority (use your own `subj` string): | ||
|
||
``` | ||
openssl req -x509 -newkey rsa:4096 -nodes -keyout test-ca.key -sha256 -days 1825 -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=Test System CA" -out test-ca.csr | ||
``` | ||
|
||
Now you have file `test-ca.key` with private key of Certificate Authority and | ||
`test-ca.crt` with certificate. You can now import the `test-ca.crt` | ||
file into your test system. | ||
|
||
#### Domain Certificate | ||
|
||
Now generate domain certificate, replace `example.com` with your domain (and use your own `subj` string): | ||
|
||
``` | ||
openssl req -newkey rsa:4096 -nodes -keyout server-certificate.key -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" -out server-certificate.csr | ||
``` | ||
|
||
The file `server-certificate.key` is the private key, the file `server-certificate.csr` is certificate signing request. | ||
|
||
#### Signed Domain Certificate | ||
|
||
Now sign the request with your Certificate Authority: | ||
|
||
``` | ||
openssl x509 -req -in server-certificate.csr -CA test-ca.pem -CAkey test-ca.key -CAcreateserial -out server-certificate.crt -days 1825 -sha256 | ||
``` | ||
|
||
The file `server-certificate.crt` (together with `server-certificate.key`) can now be used by the test server. | ||
|
||
## Docker | ||
|
||
### Production image | ||
|
||
Build from sources (optional step - you can use official image): | ||
|
||
``` | ||
docker build -t subregsim:latest . | ||
``` | ||
|
||
Run as (uses `subregsim.conf` and generated certificates): | ||
|
||
``` | ||
docker run --rm -it -v $PWD/server-certificate.crt:/config/server-certificate.crt -v $PWD/server-certificate.key:/config/server-certificate.key -v $PWD/subregsim.conf:/config/subregsim.conf subregsim:latest -c /config/subregsim.conf | ||
``` | ||
|
||
### Development image | ||
|
||
Build from sources: | ||
|
||
``` | ||
docker build -t subregsim:develop-latest -f Dockerfile.development . | ||
``` | ||
|
||
Run as (uses `subregsim.conf` and generated certificates): | ||
|
||
``` | ||
docker run --rm -it -v $PWD/server-certificate.crt:/config/server-certificate.crt -v $PWD/server-certificate.key:/config/server-certificate.key -v $PWD/subregsim.conf:/config/subregsim.conf -v $PWD/.:/source subregsim:develop-latest -c /config/subregsim.conf | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Package requirements | ||
|
||
future | ||
git+https://github.com/oldium/pysimplesoap.git@fix-typeerror#egg=PySimpleSOAP | ||
configargparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[metadata] | ||
# This includes the license file in the wheel. | ||
license_file = LICENSE.txt | ||
|
||
[bdist_wheel] | ||
# This flag says to generate wheels that support both Python 2 and Python | ||
# 3. If your code will not run unchanged on both Python 2 and 3, you will | ||
# need to generate separate wheels for each Python version that you | ||
# support. Removing this line (or setting universal to 0) will prevent | ||
# bdist_wheel from trying to make a universal wheel. For more see: | ||
# https://packaging.python.org/tutorials/distributing-packages/#wheels | ||
universal=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"""A setuptools based setup module. | ||
See: | ||
https://packaging.python.org/en/latest/distributing.html | ||
https://github.com/pypa/sampleproject | ||
""" | ||
|
||
# Always prefer setuptools over distutils | ||
from setuptools import setup, find_packages | ||
# To use a consistent encoding | ||
import codecs | ||
import os | ||
import re | ||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
# Get the long description from the README file | ||
with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
def read(*parts): | ||
with codecs.open(os.path.join(here, *parts), 'r') as fp: | ||
return fp.read() | ||
|
||
def find_version(*file_paths): | ||
version_file = read(*file_paths) | ||
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", | ||
version_file, re.M) | ||
if version_match: | ||
return version_match.group(1) | ||
raise RuntimeError("Unable to find version string.") | ||
|
||
setup( | ||
name='SubregSimulator', | ||
version=find_version("subregsim", "__main__.py"), | ||
description='Simple Subreg.cz API simulator', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
|
||
url='https://github.com/oldium/subregsim', | ||
|
||
author='Oldřich Jedlička', | ||
author_email='[email protected]', | ||
|
||
# See https://pypi.org/classifiers/ | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
'Topic :: Software Development :: Testing', | ||
'Topic :: Utilities', | ||
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
'Programming Language :: Python :: 3.7', | ||
], | ||
|
||
keywords='subreg api simulator', | ||
|
||
packages=find_packages(exclude=['contrib', 'config', 'docs', 'tests']), | ||
|
||
# See https://packaging.python.org/en/latest/requirements.html | ||
install_requires=['future', | ||
'PySimpleSOAP', | ||
'configargparse'], | ||
extras_require={}, | ||
|
||
entry_points={ | ||
'console_scripts': [ | ||
'subregsim=subregsim.__main__:main', | ||
], | ||
}, | ||
|
||
project_urls={ | ||
'Bug Reports': 'https://github.com/oldium/subregsim/issues', | ||
'Say Thanks!': 'https://saythanks.io/to/oldium', | ||
'Source': 'https://github.com/oldium/subregsim/', | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Docker configuration, read README.md for details | ||
|
||
# Required simulator user name | ||
username = username | ||
|
||
# Required simulator password | ||
password = password | ||
|
||
# Required simulator domain | ||
domain = example.com | ||
|
||
# Host name or IP address to listen on (use 127.0.0.1 for testing on localhost, | ||
# or 0.0.0.0 to accept any address for testing with Docker) | ||
host = 0.0.0.0 | ||
|
||
# Port to listen on when in HTTP mode | ||
#port = 80 | ||
|
||
# If you want to switch to HTTPS (SSL), uncomment the following line | ||
#ssl = true | ||
|
||
# Port to listen on when in HTTPS (SSL) mode | ||
#ssl-port = 443 | ||
|
||
# SSL server certificate in PEM format (may contain private key) | ||
#ssl-certificate = /config/server-certificate.crt | ||
|
||
# SSL server private key in PEM format (not necessary if present in the certificate file) | ||
#ssl-private-key = /config/server-certificate.key |
Empty file.
Oops, something went wrong.