Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CTI Tools
tosca2doc
Commits
acccb51e
Commit
acccb51e
authored
May 16, 2019
by
carignani
Browse files
fixed proxy URL issue and improved error messages
parent
15a4f039
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/web_app.py
View file @
acccb51e
...
...
@@ -13,8 +13,37 @@ import config
import
tosca2doc
import
doc2tosca
app
=
Flask
(
__name__
)
class
ReverseProxied
(
object
):
def
__init__
(
self
,
app
,
script_name
=
None
,
scheme
=
None
,
server
=
None
):
self
.
app
=
app
self
.
script_name
=
script_name
self
.
scheme
=
scheme
self
.
server
=
server
print
(
"Reverse Proxy set up"
)
def
__call__
(
self
,
environ
,
start_response
):
print
(
"ReverseProxy called"
)
script_name
=
environ
.
get
(
'HTTP_X_SCRIPT_NAME'
,
''
)
or
self
.
script_name
if
script_name
:
environ
[
'SCRIPT_NAME'
]
=
script_name
path_info
=
environ
[
'PATH_INFO'
]
if
path_info
.
startswith
(
script_name
):
environ
[
'PATH_INFO'
]
=
path_info
[
len
(
script_name
):]
scheme
=
environ
.
get
(
'HTTP_X_SCHEME'
,
''
)
or
self
.
scheme
if
scheme
:
environ
[
'wsgi.url_scheme'
]
=
scheme
server
=
environ
.
get
(
'HTTP_X_FORWARDED_HOST'
,
''
)
or
self
.
server
print
(
'HTTP_X_FORWARDED_SERVER '
+
environ
.
get
(
'HTTP_X_FORWARDED_SERVER'
))
print
(
'HTTP_X_FORWARDED_FOR '
+
environ
.
get
(
'HTTP_X_FORWARDED_FOR'
))
print
(
'HTTP_X_FORWARDED_HOST '
+
environ
.
get
(
'HTTP_X_FORWARDED_HOST'
))
if
server
:
environ
[
'HTTP_HOST'
]
=
server
return
self
.
app
(
environ
,
start_response
)
app
=
Flask
(
__name__
)
app
.
wsgi_app
=
ReverseProxied
(
app
.
wsgi_app
,
script_name
=
'/tosca-ie'
)
UPLOAD_FOLDER
=
'/tmp/upload'
...
...
@@ -59,8 +88,8 @@ def tosca2doc_info():
def
mk_tosca2doc
():
if
'file'
not
in
request
.
files
:
flash
(
'No file
part
'
)
return
redirect
(
request
.
url
)
flash
(
'
Error:
No file
uploaded.
'
)
return
redirect
(
"/tosca-ie"
)
ufiles
=
request
.
files
.
getlist
(
"file"
)
...
...
@@ -75,15 +104,15 @@ def mk_tosca2doc():
# print uploaded_file.read()
# print "-------------------"
if
not
found
:
flash
(
'
No file part
'
)
print
(
'
No file part
'
)
return
redirect
(
"/"
)
flash
(
'
Error: some TOSCA module missing. Make sure to upload definitions for NSD, VNFD, PNFD.
'
)
print
(
'
Error: TOSCA module missing.
'
)
return
redirect
(
"/
tosca-ie
"
)
for
file
in
ufiles
:
if
file
.
filename
==
''
:
print
(
'No selected file'
)
flash
(
'
No selected file
'
)
return
redirect
(
"/"
)
print
(
'
Error:
No selected file'
)
flash
(
'
Error: No file uploaded or wrong name.
'
)
return
redirect
(
"/
tosca-ie
"
)
tmp_dir
=
tempfile
.
mkdtemp
()
g
.
tmp_dir
=
tmp_dir
...
...
@@ -164,4 +193,4 @@ def mk_doc2tosca():
return
send_file
(
zip_path
,
as_attachment
=
True
)
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
,
host
=
'0.0.0.0'
)
\ No newline at end of file
app
.
run
(
debug
=
True
,
host
=
'0.0.0.0'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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