Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
geant-swd
dashboardv3
inventory-provider
Commits
de506e31
Commit
de506e31
authored
4 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
added routes for OTRS data and export
parent
1890626b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/__init__.py
+5
-2
5 additions, 2 deletions
inventory_provider/__init__.py
inventory_provider/routes/ims_otrs.py
+68
-0
68 additions, 0 deletions
inventory_provider/routes/ims_otrs.py
with
73 additions
and
2 deletions
inventory_provider/__init__.py
+
5
−
2
View file @
de506e31
...
...
@@ -52,8 +52,11 @@ def create_app():
# OTRS routes
from
inventory_provider.routes
import
otrs_jobs
app
.
register_blueprint
(
otrs_jobs
.
routes
,
url_prefix
=
'
/otrs
'
)
from
inventory_provider.routes
import
ims_otrs
app
.
register_blueprint
(
ims_otrs
.
routes
,
url_prefix
=
'
/otrs
'
)
# from inventory_provider.routes import otrs_jobs
# app.register_blueprint(otrs_jobs.routes, url_prefix='/otrs')
# end of OTRS routes
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/ims_otrs.py
0 → 100644
+
68
−
0
View file @
de506e31
import
csv
import
html
from
io
import
StringIO
import
requests
from
flask
import
Blueprint
,
request
,
Response
,
current_app
from
inventory_provider.db
import
ims_data
from
inventory_provider.db.ims
import
IMS
from
inventory_provider.routes
import
common
from
inventory_provider.tasks.ims_worker
import
OTRSFiles
,
export_data_for_otrs
routes
=
Blueprint
(
"
otrs
"
,
__name__
)
@routes.after_request
def
after_request
(
resp
):
return
common
.
after_request
(
resp
)
def
get_otrs_data
(
fn
):
ims_config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
][
"
ims
"
]
ds
=
IMS
(
ims_config
[
'
api
'
],
ims_config
[
'
username
'
],
ims_config
[
'
password
'
])
with
StringIO
()
as
sio
:
writer
=
csv
.
writer
(
sio
,
delimiter
=
'
^
'
)
writer
.
writerows
(
fn
(
ds
))
data
=
sio
.
getvalue
()
return
Response
(
response
=
data
,
status
=
requests
.
codes
.
ok
,
mimetype
=
"
text/html
"
)
@routes.route
(
'
customer-companies
'
)
def
get_customer_companies_data
():
return
get_otrs_data
(
ims_data
.
otrs_get_customer_company_rows
)
@routes.route
(
'
customer-users
'
)
def
get_customer_users_data
():
return
get_otrs_data
(
ims_data
.
otrs_get_customer_users_rows
)
@routes.route
(
'
export
'
)
def
send_exports
():
files_value
=
request
.
args
.
get
(
'
files
'
,
None
)
if
files_value
:
try
:
files_value
=
int
(
files_value
)
except
ValueError
:
return
Response
(
response
=
html
.
escape
(
'
<files> should be an Integer
'
),
status
=
requests
.
codes
.
bad_request
,
mimetype
=
"
text/html
"
)
if
files_value
<
0
or
files_value
>
sum
(
OTRSFiles
):
return
Response
(
response
=
html
.
escape
(
f
'
Bad value for <files>
{
files_value
}
'
),
status
=
requests
.
codes
.
bad_request
,
mimetype
=
"
text/html
"
)
task
=
export_data_for_otrs
.
delay
(
files_value
)
return
Response
(
response
=
task
.
id
,
status
=
requests
.
codes
.
ok
,
mimetype
=
"
text/html
"
)
\ No newline at end of file
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