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
b783fd0e
Commit
b783fd0e
authored
10 months ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Added a custom HTTP IPV4 adaptor to force IPV4.
parent
fada137f
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!37
Feature/dboard3 921
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inventory_provider/gap.py
+27
-2
27 additions, 2 deletions
inventory_provider/gap.py
with
27 additions
and
2 deletions
inventory_provider/gap.py
+
27
−
2
View file @
b783fd0e
import
concurrent.futures
import
logging
import
socket
import
requests
from
flask
import
current_app
import
concurrent.futures
from
requests.adapters
import
HTTPAdapter
from
urllib3.poolmanager
import
PoolManager
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -10,6 +13,23 @@ GRANT_TYPE = 'client_credentials'
SCOPE
=
'
openid profile email aarc
'
class
IPv4Adapter
(
HTTPAdapter
):
"""
A custom adapter that forces the use of IPv4.
"""
def
init_poolmanager
(
self
,
connections
,
maxsize
,
block
=
False
,
**
pool_kwargs
):
pool_kwargs
[
'
socket_options
'
]
=
[(
socket
.
IPPROTO_IP
,
socket
.
IP_TOS
,
0
)]
self
.
poolmanager
=
PoolManager
(
num_pools
=
connections
,
maxsize
=
maxsize
,
block
=
block
,
**
pool_kwargs
)
def
proxy_manager_for
(
self
,
proxy
,
**
proxy_kwargs
):
proxy_kwargs
[
'
socket_options
'
]
=
[(
socket
.
IPPROTO_IP
,
socket
.
IP_TOS
,
0
)]
return
super
().
proxy_manager_for
(
proxy
,
**
proxy_kwargs
)
def
get_token_endpoint
(
discovery_endpoint_url
:
str
)
->
str
:
response
=
requests
.
get
(
discovery_endpoint_url
)
response
.
raise_for_status
()
...
...
@@ -36,7 +56,12 @@ def make_request(body: dict, token: str) -> dict:
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
api_url
=
f
'
{
config
[
"
orchestrator
"
][
"
url
"
]
}
/api/graphql
'
headers
=
{
'
Authorization
'
:
f
'
Bearer
{
token
}
'
}
response
=
requests
.
post
(
api_url
,
headers
=
headers
,
json
=
body
)
session
=
requests
.
Session
()
# Mount the adapter to force IPv4
adapter
=
IPv4Adapter
()
session
.
mount
(
'
http://
'
,
adapter
)
session
.
mount
(
'
https://
'
,
adapter
)
response
=
session
.
post
(
api_url
,
headers
=
headers
,
json
=
body
)
response
.
raise_for_status
()
return
response
.
json
()
...
...
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