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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
dashboardv3
inventory-provider
Commits
a4ebece6
Commit
a4ebece6
authored
Feb 9, 2024
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
switched default for verify_ssl to False
parent
cffc51ed
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/db/ims.py
+10
-6
10 additions, 6 deletions
inventory_provider/db/ims.py
inventory_provider/tasks/worker.py
+1
-1
1 addition, 1 deletion
inventory_provider/tasks/worker.py
test/test_ims.py
+10
-9
10 additions, 9 deletions
test/test_ims.py
with
21 additions
and
16 deletions
inventory_provider/db/ims.py
+
10
−
6
View file @
a4ebece6
...
...
@@ -200,7 +200,7 @@ class IMS(object):
reconnect_attempts
=
0
def
__init__
(
self
,
base_url
,
username
,
password
,
bearer_token
=
None
,
verify_ssl
=
Tru
e
):
verify_ssl
=
Fals
e
):
IMS
.
base_url
=
base_url
self
.
username
=
username
self
.
password
=
password
...
...
@@ -208,7 +208,7 @@ class IMS(object):
IMS
.
bearer_token
=
bearer_token
@classmethod
def
_init_bearer_token
(
cls
,
username
,
password
,
verify_ssl
=
Tru
e
):
def
_init_bearer_token
(
cls
,
username
,
password
,
verify_ssl
=
Fals
e
):
re_init_time
=
time
.
time
()
if
not
cls
.
bearer_token
or
\
re_init_time
-
cls
.
bearer_token_init_time
\
...
...
@@ -230,7 +230,8 @@ class IMS(object):
def
clear_dynamic_context_cache
(
self
):
if
not
IMS
.
bearer_token
:
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
)
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
,
self
.
verify_ssl
)
while
True
:
logger
.
info
(
'
Clearing Dynamic Context Cache
'
)
response
=
requests
.
put
(
...
...
@@ -238,7 +239,8 @@ class IMS(object):
headers
=
{
'
Authorization
'
:
f
'
Bearer
{
self
.
bearer_token
}
'
},
verify
=
self
.
verify_ssl
)
if
response
.
status_code
==
401
:
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
)
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
,
self
.
verify_ssl
)
continue
response
.
raise_for_status
()
break
...
...
@@ -267,7 +269,8 @@ class IMS(object):
return
entity
if
not
IMS
.
bearer_token
:
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
)
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
,
self
.
verify_ssl
)
def
_is_invalid_login_state
(
response_
):
if
response_
.
status_code
==
requests
.
codes
.
unauthorized
:
...
...
@@ -315,7 +318,8 @@ class IMS(object):
headers
=
{
'
Authorization
'
:
f
'
Bearer
{
self
.
bearer_token
}
'
},
params
=
params
,
verify
=
self
.
verify_ssl
)
if
_is_invalid_login_state
(
response
):
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
)
IMS
.
_init_bearer_token
(
self
.
username
,
self
.
password
,
self
.
verify_ssl
)
else
:
response
.
raise_for_status
()
orig
=
response
.
json
()
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
1
−
1
View file @
a4ebece6
...
...
@@ -764,7 +764,7 @@ def extract_ims_data():
ims_api_url
=
c
[
'
api
'
],
ims_username
=
c
[
'
username
'
],
ims_password
=
c
[
'
password
'
],
verify_ssl
=
c
.
get
(
'
verify-ssl
'
,
Tru
e
)
verify_ssl
=
c
.
get
(
'
verify-ssl
'
,
Fals
e
)
)
...
...
This diff is collapsed.
Click to expand it.
test/test_ims.py
+
10
−
9
View file @
a4ebece6
...
...
@@ -27,11 +27,12 @@ def test_ims_class_login(mocker):
'
dummy_base
'
,
'
dummy_username
'
,
'
dummy_password
'
)
ds
.
get_entity_by_id
(
'
Node
'
,
1234
)
mock_post
.
assert_called_once_with
(
'
dummy_base/login
'
,
auth
=
(
'
dummy_username
'
,
'
dummy_password
'
),
verify
=
True
)
'
dummy_base/login
'
,
auth
=
(
'
dummy_username
'
,
'
dummy_password
'
),
verify
=
False
)
mock_get
.
assert_called_once_with
(
'
dummy_base/ims/Node/1234
'
,
headers
=
{
'
Authorization
'
:
'
Bearer my_bearer_token
'
},
params
=
None
,
verify
=
Tru
e
)
params
=
None
,
verify
=
Fals
e
)
def
test_ims_failed_response
(
mocker
):
...
...
@@ -60,7 +61,7 @@ def test_ims_class_entity_by_id(mocker):
mock_get
.
assert_called_once_with
(
'
dummy_base/ims/Node/1234
'
,
headers
=
{
'
Authorization
'
:
'
Bearer dummy_bt
'
},
params
=
None
,
verify
=
Tru
e
)
params
=
None
,
verify
=
Fals
e
)
def
test_ims_class_entity_by_name
(
mocker
):
...
...
@@ -72,7 +73,7 @@ def test_ims_class_entity_by_name(mocker):
mock_get
.
assert_called_once_with
(
'
dummy_base/ims/Node/byname/
"
dummy_name
"'
,
headers
=
{
'
Authorization
'
:
'
Bearer dummy_bt
'
},
params
=
None
,
verify
=
Tru
e
)
params
=
None
,
verify
=
Fals
e
)
def
test_ims_class_filtered_entities
(
mocker
):
...
...
@@ -88,7 +89,7 @@ def test_ims_class_filtered_entities(mocker):
params
=
{
'
paginatorStartElement
'
:
0
,
'
paginatorNumberOfElements
'
:
50
},
verify
=
Tru
e
)
},
verify
=
Fals
e
)
def
side_effect
(
*
args
,
**
kargs
):
if
kargs
[
'
params
'
][
'
paginatorStartElement
'
]
==
0
:
...
...
@@ -106,14 +107,14 @@ def test_ims_class_filtered_entities(mocker):
params
=
{
'
paginatorStartElement
'
:
0
,
'
paginatorNumberOfElements
'
:
2
},
verify
=
Tru
e
)
},
verify
=
Fals
e
)
mock_multi_get
.
assert_any_call
(
'
dummy_base/ims/Node/filtered/dummy_param=dummy value
'
,
headers
=
{
'
Authorization
'
:
'
Bearer dummy_bt
'
},
params
=
{
'
paginatorStartElement
'
:
2
,
'
paginatorNumberOfElements
'
:
2
},
verify
=
Tru
e
)
},
verify
=
Fals
e
)
assert
mock_multi_get
.
call_count
==
2
assert
res
==
[
1
,
2
,
3
]
...
...
@@ -144,7 +145,7 @@ def test_ims_class_get_all_entities(mocker):
params
=
{
'
paginatorStartElement
'
:
0
,
'
paginatorNumberOfElements
'
:
10
},
verify
=
Tru
e
)
},
verify
=
Fals
e
)
def
test_ims_class_navigation_properties
(
mocker
):
...
...
@@ -156,7 +157,7 @@ def test_ims_class_navigation_properties(mocker):
mock_get
.
assert_called_with
(
'
dummy_base/ims/Node/1234
'
,
headers
=
{
'
Authorization
'
:
'
Bearer dummy_bt
'
},
params
=
{
'
navigationproperty
'
:
6
},
verify
=
Tru
e
)
params
=
{
'
navigationproperty
'
:
6
},
verify
=
Fals
e
)
def
test_ims_class_cache
(
mocker
):
...
...
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
sign in
to comment