Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Document Dealer
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
it-bott-integrasjoner
Document Dealer
Merge requests
!20
Add endpoint for retrieving from the database
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add endpoint for retrieving from the database
dd13
into
DD-12-gamle-okonomidata
Overview
7
Commits
10
Pipelines
28
Changes
1
Merged
Petr.Kalashnikov
requested to merge
dd13
into
DD-12-gamle-okonomidata
1 year ago
Overview
7
Commits
10
Pipelines
28
Changes
1
Expand
Retrieving economy data with Oracle client
Edited
1 year ago
by
Petr.Kalashnikov
0
0
Merge request reports
Compare
DD-12-gamle-okonomidata
version 13
4fbf0997
1 year ago
version 12
32a55920
1 year ago
version 11
0622a930
1 year ago
version 10
9c4a37c2
1 year ago
version 9
c59da3b0
1 year ago
version 8
690e3ba3
1 year ago
version 7
5b005d99
1 year ago
version 6
41259404
1 year ago
version 5
ceffc797
1 year ago
version 4
6c8b4299
1 year ago
version 3
b9cee800
1 year ago
version 2
730de79f
1 year ago
version 1
f8edc32e
1 year ago
DD-12-gamle-okonomidata (base)
and
latest version
latest version
511f4ac1
10 commits,
1 year ago
version 13
4fbf0997
9 commits,
1 year ago
version 12
32a55920
8 commits,
1 year ago
version 11
0622a930
8 commits,
1 year ago
version 10
9c4a37c2
7 commits,
1 year ago
version 9
c59da3b0
6 commits,
1 year ago
version 8
690e3ba3
6 commits,
1 year ago
version 7
5b005d99
5 commits,
1 year ago
version 6
41259404
4 commits,
1 year ago
version 5
ceffc797
3 commits,
1 year ago
version 4
6c8b4299
2 commits,
1 year ago
version 3
b9cee800
1 commit,
1 year ago
version 2
730de79f
1 commit,
1 year ago
version 1
f8edc32e
1 commit,
1 year ago
1 file
+
53
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
document_dealer/main.py
+
53
−
4
Options
import
hashlib
import
datetime
import
urllib
from
functools
import
lru_cache
import
fastapi
import
logging.config
from
typing
import
Optional
,
Union
from
.document_client
import
DocumentClient
from
.oracle_bot
import
OracleClient
,
OracleConfig
from
.config
import
get_config
,
AuthConfig
,
InstanceConfig
app
=
fastapi
.
FastAPI
(
docs_url
=
None
,
redoc_url
=
None
)
@@ -72,6 +75,20 @@ async def authorised(firm: str, token: str, doc_id: str) -> bool:
return
bool
(
token
and
token
==
generated_token
)
@lru_cache
def
get_oracle_client
(
firm
:
str
)
->
OracleClient
|
None
:
instance_config
=
get_instance_config
(
firm
)
if
instance_config
is
None
or
instance_config
.
old_bot
is
None
:
return
None
oracle_config
=
OracleConfig
(
dsn
=
instance_config
.
old_bot
.
database
.
dsn
,
user
=
instance_config
.
old_bot
.
database
.
user
,
password
=
instance_config
.
old_bot
.
database
.
password
,
)
return
OracleClient
(
oracle_config
)
@app.get
(
"
/document
"
)
async
def
get_document
(
firm
:
str
,
@@ -110,9 +127,41 @@ async def get_document(
)
@app.get
(
"
/health
"
)
async
def
health
()
->
fastapi
.
responses
.
Response
:
@app.get
(
"
/economy_data
"
)
async
def
get_economy_data
(
firm
:
str
,
doc_id
:
int
,
authorised
:
bool
=
fastapi
.
Depends
(
authorised
),
)
->
fastapi
.
responses
.
Response
:
if
not
authorised
:
return
fastapi
.
responses
.
PlainTextResponse
(
status_code
=
401
,
content
=
"
Unauthorised
"
)
oracle_client
=
get_oracle_client
(
firm
)
if
oracle_client
is
None
:
return
fastapi
.
responses
.
PlainTextResponse
(
status_code
=
404
)
answer
=
oracle_client
.
get_document
(
doc_id
)
if
not
answer
:
return
fastapi
.
responses
.
PlainTextResponse
(
status_code
=
404
)
headers
=
{
"
Cache-Control
"
:
"
no-store
"
,
}
if
answer
.
filename
:
# Stolen from starlette.FileResponse
content_disposition_filename
=
urllib
.
parse
.
quote
(
answer
.
filename
)
if
content_disposition_filename
!=
answer
.
filename
:
content_disposition
=
"
attachment; filename*=utf-8
''
{}
"
.
format
(
content_disposition_filename
)
else
:
content_disposition
=
'
attachment; filename=
"
{}
"'
.
format
(
answer
.
filename
)
headers
[
"
Content-Disposition
"
]
=
content_disposition
return
fastapi
.
responses
.
Response
(
content
=
"
OK
"
,
media_type
=
"
text/plain
"
,
content
=
answer
.
document
,
media_type
=
answer
.
mimetype
,
headers
=
headers
,
)
Loading