Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mynij-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mynij
mynij-proxy
Commits
8167ceb4
Commit
8167ceb4
authored
Aug 12, 2021
by
Stefane Fermigier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: CI config.
parent
ef13f531
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
38 deletions
+97
-38
.github/workflows/ci.yml
.github/workflows/ci.yml
+39
-0
Makefile
Makefile
+6
-23
setup.cfg
setup.cfg
+9
-0
src/mynij_proxy.py
src/mynij_proxy.py
+12
-15
tox.ini
tox.ini
+31
-0
No files found.
.github/workflows/ci.yml
0 → 100644
View file @
8167ceb4
name
:
CI
on
:
push
:
branches
:
[
main
,
master
]
pull_request
:
branches
:
[
main
,
master
,
dev
]
jobs
:
test
:
runs-on
:
${{ matrix.os }}-latest
strategy
:
fail-fast
:
false
matrix
:
os
:
[
ubuntu
,
macos
]
python-version
:
[
'
3.8'
,
'
3.9'
]
exclude
:
-
os
:
windows
python-version
:
pypy3
steps
:
-
uses
:
actions/checkout@v2
-
uses
:
actions/setup-python@v2
with
:
python-version
:
${{ matrix.python-version }}
-
run
:
pip install -U pip setuptools wheel tox tox-gh-actions poetry
-
id
:
pip-cache
run
:
echo "::set-output name=dir::$(pip cache dir)"
-
uses
:
actions/cache@v2
with
:
path
:
${{ steps.pip-cache.outputs.dir }}
key
:
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys
:
|
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
-
run
:
tox
-
if
:
${{ matrix.os == 'ubuntu' && matrix.python-version == '3.8' }}
run
:
|
pip install codecov
codecov
Makefile
View file @
8167ceb4
...
...
@@ -11,7 +11,7 @@ all: test lint
# Run
#
.PHONY
:
run
:
run
:
gunicorn
-b
localhost:3000
\
--pid
server.pid
\
--keyfile
ssl/httpd.key
\
...
...
@@ -64,7 +64,7 @@ test-randomly:
.PHONY
:
test-with-coverage
:
@
echo
"--> Running Python tests"
py
.
test
--cov
$(PKG)
pytest
--cov
$(PKG)
@
echo
""
.PHONY
:
...
...
@@ -78,14 +78,11 @@ test-with-typeguard:
# Various Checkers
#
.PHONY
:
lint
:
lint-py lint-mypy lint-
rst lint-doc
lint
:
lint-py lint-mypy lint-
bandit
.PHONY
:
lint-ci
:
lint
.PHONY
:
lint-all
:
lint lint-bandit
.PHONY
:
lint-py
:
@
echo
"--> Linting Python files /w flake8"
...
...
@@ -99,23 +96,9 @@ lint-mypy:
@
echo
""
.PHONY
:
lint-travis
:
@
echo
"--> Linting .travis.yml files"
travis lint
--no-interactive
@
echo
""
.PHONY
:
lint-rst
:
@
echo
"--> Linting .rst files"
rst-lint
*
.rst
@
echo
""
.PHONY
:
lint-doc
:
@
echo
"--> Linting doc"
@
echo
"TODO"
#sphinx-build -W -b dummy docs/ docs/_build/
#sphinx-build -b dummy docs/ docs/_build/
lint-bandit
:
@
echo
"--> Security audit w/ Bandit"
bandit
-q
src/
*
.py
@
echo
""
...
...
setup.cfg
View file @
8167ceb4
[isort]
profile = black
[mypy]
ignore_missing_imports = True
warn_redundant_casts = True
warn_no_return = True
warn_unused_ignores = True
# TODO: reenable when ready
# disallow_untyped_defs = True
strict_optional = True
src/mynij_proxy.py
View file @
8167ceb4
import
traceback
from
typing
import
Dict
,
Mapping
,
Tuple
from
__future__
import
annotations
from
typing
import
Mapping
,
Any
import
httpx
from
starlette.applications
import
Starlette
...
...
@@ -8,8 +9,7 @@ from starlette.requests import Request
from
starlette.responses
import
PlainTextResponse
,
Response
from
starlette.routing
import
Route
# Extremely aggressive and hardcoded value
TIMEOUT
=
10
TIMEOUT
=
60
DEFAULT_ACCESS_URL
=
"https://mynij.app.officejs.com"
...
...
@@ -25,11 +25,10 @@ class ProxyEndPoint(HTTPEndpoint):
self
.
url
=
request
.
query_params
[
"url"
]
status_code
,
content
,
new_headers
=
await
self
.
fetch_content
()
# debug(status_code, content, new_headers)
response
=
Response
(
content
,
status_code
,
new_headers
)
return
response
async
def
fetch_content
(
self
)
->
T
uple
[
int
,
bytes
,
dict
]:
async
def
fetch_content
(
self
)
->
t
uple
[
int
,
bytes
,
dict
]:
proxy_query_header
=
self
.
make_query_headers
(
self
.
headers
)
body
=
b""
response_headers
=
{}
...
...
@@ -47,23 +46,21 @@ class ProxyEndPoint(HTTPEndpoint):
# # Invalid SSL Certificate
# status = 526
except
TimeoutError
:
traceback
.
print_exc
()
# Gateway Timeout
status
=
504
except
httpx
.
TransportError
:
traceback
.
print_exc
()
# Service Unavailable
status
=
503
except
httpx
.
HTTPError
:
traceback
.
print_exc
()
# Internal Server Error
status
=
500
return
status
,
body
,
response_headers
def
make_query_headers
(
self
,
headers
:
Mapping
)
->
Mapping
:
@
staticmethod
def
make_query_headers
(
headers
:
Mapping
[
str
,
Any
])
->
dict
[
str
,
str
]:
request_headers
=
{}
HEADERS
=
[
keep_headers
=
[
"Content-Type"
,
"Accept"
,
"Accept-Language"
,
...
...
@@ -71,7 +68,7 @@ class ProxyEndPoint(HTTPEndpoint):
"If-Modified-Since"
,
"If-None-Match"
,
]
for
k
in
HEADERS
:
for
k
in
keep_headers
:
v
=
headers
.
get
(
k
)
if
v
:
request_headers
[
k
]
=
str
(
v
)
...
...
@@ -81,9 +78,9 @@ class ProxyEndPoint(HTTPEndpoint):
def
get_access_url
(
self
):
return
self
.
headers
.
get
(
"Origin"
,
DEFAULT_ACCESS_URL
)
def
filter_response_headers
(
self
,
proxy_response
)
->
D
ict
[
str
,
str
]:
def
filter_response_headers
(
self
,
proxy_response
:
Response
)
->
d
ict
[
str
,
str
]:
headers
=
{}
HEADERS
=
[
keep_headers
=
[
"Content-Disposition"
,
"Content-Type"
,
"Date"
,
...
...
@@ -96,7 +93,7 @@ class ProxyEndPoint(HTTPEndpoint):
]
for
k
,
v
in
proxy_response
.
headers
.
items
():
k
=
k
.
title
()
if
k
in
HEADERS
:
if
k
in
keep_headers
:
headers
[
k
]
=
v
return
headers
...
...
tox.ini
0 → 100644
View file @
8167ceb4
[tox]
envlist
=
py38, py39, lint
skipsdist
=
True
[testenv]
skip_install
=
true
whitelist_externals
=
poetry
sh
make
yarn
commands_pre
=
poetry
install
-q
commands
=
make
test
[testenv:lint]
commands
=
make
lint
safety
check
[gh-actions]
python
=
3.8:
py38
3.9:
py39,
lint
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment