Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eric Zheng
slapos.toolbox
Commits
1af096b5
Commit
1af096b5
authored
Jun 24, 2021
by
Eric Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add HTTP basic authentication check
parent
597ad67a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
slapos/promise/plugin/check_http_authentication.py
slapos/promise/plugin/check_http_authentication.py
+40
-0
No files found.
slapos/promise/plugin/check_http_authentication.py
0 → 100644
View file @
1af096b5
from
zope.interface
import
implementer
from
slapos.grid.promise
import
interface
from
slapos.grid.promise.generic
import
GenericPromise
import
requests
@
implementer
(
interface
.
IPromise
)
class
RunPromise
(
GenericPromise
):
def
__init__
(
self
,
config
):
super
(
RunPromise
,
self
).
__init__
(
config
)
self
.
setPeriodicity
(
float
(
self
.
getConfig
(
'frequency'
,
2
)))
def
sense
(
self
):
"""
Check basic HTTP authentication for a service. You should
probably run check_url_available.py first.
"""
url
=
self
.
getConfig
(
'url'
)
username
=
self
.
getConfig
(
'username'
)
password
=
self
.
getConfig
(
'password'
)
try
:
result
=
requests
.
get
(
url
,
auth
=
(
username
,
password
))
except
requests
.
ConnectionError
as
_
:
self
.
logger
.
error
(
'ERROR connection not possible while accessing %r'
%
url
)
return
except
Exception
as
e
:
self
.
logger
.
error
(
'ERROR %r'
%
e
)
return
credentials
=
'(%r, %r)'
%
(
username
,
password
)
if
result
.
ok
:
self
.
logger
.
info
(
'%r authenticated with %s'
%
(
url
,
credentials
))
else
:
self
.
logger
.
error
(
'ERROR could not authenticate %r with %s'
%
\
(
url
,
credentials
))
def
anomaly
(
self
):
return
self
.
_test
(
result_count
=
3
,
failure_amount
=
3
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment