Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tosca2doc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTI Tools
tosca2doc
Commits
acccb51e
Commit
acccb51e
authored
5 years ago
by
carignani
Browse files
Options
Downloads
Patches
Plain Diff
fixed proxy URL issue and improved error messages
parent
15a4f039
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/web_app.py
+39
-10
39 additions, 10 deletions
src/web_app.py
with
39 additions
and
10 deletions
src/web_app.py
+
39
−
10
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
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment