Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Arkindex
api-client
Commits
efff8a42
Commit
efff8a42
authored
5 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle deprecated endpoints
parent
8486ae37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#28254
passed
5 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/client.py
+25
-3
25 additions, 3 deletions
arkindex/client.py
with
25 additions
and
3 deletions
arkindex/client.py
+
25
−
3
View file @
efff8a42
...
...
@@ -4,6 +4,7 @@ Arkindex API Client
import
os
import
apistar
import
logging
import
warnings
import
yaml
from
arkindex.auth
import
TokenSessionAuthentication
from
arkindex.pagination
import
ResponsePaginator
...
...
@@ -33,6 +34,14 @@ def options_from_env():
return
options
def
_find_operation
(
schema
,
operation_id
):
for
path_object
in
schema
[
'
paths
'
].
values
():
for
operation
in
path_object
.
values
():
if
operation
[
'
operationId
'
]
==
operation_id
:
return
operation
raise
KeyError
(
"
Operation
'
{}
'
not found
"
.
format
(
operation_id
))
class
ArkindexClient
(
apistar
.
Client
):
"""
An Arkindex API client.
...
...
@@ -52,8 +61,16 @@ class ArkindexClient(apistar.Client):
schema
=
yaml
.
safe_load
(
f
.
read
())
super
().
__init__
(
schema
,
**
kwargs
)
# Remove domains from each endpoint; allows APIStar to properly handle our base URL
# Post-processing of the parsed schema
for
link_info
in
self
.
document
.
walk_links
():
# Look for deprecated links
# https://github.com/encode/apistar/issues/664
operation
=
_find_operation
(
schema
,
link_info
.
link
.
name
)
link_info
.
link
.
deprecated
=
operation
.
get
(
'
deprecated
'
,
False
)
# Remove domains from each endpoint; allows APIStar to properly handle our base URL
# https://github.com/encode/apistar/issues/657
original_url
=
urlsplit
(
link_info
.
link
.
url
)
# Removes the scheme and netloc
new_url
=
(
''
,
''
,
*
original_url
[
2
:])
...
...
@@ -110,16 +127,19 @@ class ArkindexClient(apistar.Client):
self
.
transport
.
session
.
auth
.
token
=
resp
[
'
auth_token
'
]
return
resp
def
request
(
self
,
*
args
,
**
kwargs
):
def
request
(
self
,
operation_id
,
*
args
,
**
kwargs
):
"""
Perform an API request.
:param args: Arguments passed to the APIStar client.
:param kwargs: Keyword arguments passed to the APIStar client.
"""
link
=
self
.
lookup_operation
(
operation_id
)
if
link
.
deprecated
:
warnings
.
warn
(
"
Endpoint
'
{}
'
is deprecated.
"
.
format
(
operation_id
),
DeprecationWarning
)
if
self
.
sleep_duration
:
logger
.
debug
(
'
Delaying request by {:f} seconds...
'
.
format
(
self
.
sleep_duration
))
sleep
(
self
.
sleep_duration
)
return
super
().
request
(
*
args
,
**
kwargs
)
return
super
().
request
(
operation_id
,
*
args
,
**
kwargs
)
def
custom_request
(
self
,
operation_id
,
content
=
None
,
encoding
=
'
text/plain
'
,
**
params
):
"""
...
...
@@ -136,6 +156,8 @@ class ArkindexClient(apistar.Client):
url
=
self
.
get_url
(
link
,
params
)
query_params
=
self
.
get_query_params
(
link
,
params
)
if
link
.
deprecated
:
warnings
.
warn
(
"
Endpoint
'
{}
'
is deprecated.
"
.
format
(
operation_id
),
DeprecationWarning
)
if
self
.
sleep_duration
:
logger
.
debug
(
'
Delaying request by {:f} seconds...
'
.
format
(
self
.
sleep_duration
))
sleep
(
self
.
sleep_duration
)
...
...
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