Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eduGAIN Connectivity Check
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
edugain
eduGAIN Connectivity Check
Commits
0171f5bd
Commit
0171f5bd
authored
5 years ago
by
Marco Malavolti
Browse files
Options
Downloads
Patches
Plain Diff
Enriched API
parent
16a64574
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api.py
+84
-14
84 additions, 14 deletions
api.py
eccs2.py
+4
-3
4 additions, 3 deletions
eccs2.py
with
88 additions
and
17 deletions
api.py
+
84
−
14
View file @
0171f5bd
...
@@ -4,27 +4,97 @@ from flask import Flask, request
...
@@ -4,27 +4,97 @@ from flask import Flask, request
from
flask_restful
import
Resource
,
Api
from
flask_restful
import
Resource
,
Api
from
json
import
dumps
from
json
import
dumps
from
flask
import
jsonify
from
flask
import
jsonify
from
pathlib
import
PurePath
import
logging
from
logging.handlers
import
RotatingFileHandler
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
api
=
Api
(
app
)
api
=
Api
(
app
)
def
getLogger
(
filename
,
log_level
=
"
DEBUG
"
,
path
=
"
./
"
):
logger
=
logging
.
getLogger
(
filename
)
ch
=
logging
.
FileHandler
(
path
+
filename
,
'
w
'
,
'
utf-8
'
)
if
(
log_level
==
"
DEBUG
"
):
logger
.
setLevel
(
logging
.
DEBUG
)
ch
.
setLevel
(
logging
.
DEBUG
)
elif
(
log_level
==
"
INFO
"
):
logger
.
setLevel
(
logging
.
INFO
)
ch
.
setLevel
(
logging
.
INFO
)
elif
(
log_level
==
"
WARN
"
):
logger
.
setLevel
(
logging
.
WARN
)
ch
.
setLevel
(
logging
.
WARN
)
elif
(
log_level
==
"
ERROR
"
):
logger
.
setLevel
(
logging
.
ERROR
)
ch
.
setLevel
(
logging
.
ERROR
)
elif
(
log_level
==
"
CRITICAL
"
):
logger
.
setLevel
(
logging
.
CRITICAL
)
ch
.
setLevel
(
logging
.
CRITICAL
)
formatter
=
logging
.
Formatter
(
'
%(message)s
'
)
ch
.
setFormatter
(
formatter
)
logger
.
addHandler
(
ch
)
return
logger
class
Test
(
Resource
):
class
Test
(
Resource
):
def
get
(
self
):
def
get
(
self
):
return
{
'
test
'
:
'
ciao
'
}
# Fetches first column that is Employee ID
app
.
logger
.
info
(
"
Test Superato!
"
)
return
{
'
test
'
:
'
It Works!
'
}
class
EccsCheck
(
Resource
):
def
get
(
self
,
idp
):
result
=
{
'
sp
'
:
'
https://sp24-test.garr.it/secure
'
,
'
idp
'
:
idp
,
'
check_result
'
:
'
OK
'
,
'
date
'
:
'
19-02-2020
'
}
return
jsonify
(
result
)
api
.
add_resource
(
Test
,
'
/test
'
)
# Route_1
class
AllChecks
(
Resource
):
api
.
add_resource
(
EccsCheck
,
'
/eccs/<idp>
'
)
# Route_3
def
get
(
self
):
app
.
logger
.
info
(
"
Richiesta
'
AllChecks
'"
)
file_path
=
"
logs/eccs2checks_2020-02-19.log
"
fo
=
open
(
file_path
,
"
r
"
)
result
=
[]
date
=
PurePath
(
file_path
).
parts
[
-
1
].
split
(
'
_
'
)[
1
].
split
(
'
.
'
)[
0
]
lines
=
fo
.
readlines
()
for
line
in
lines
:
check
=
line
.
split
(
"
;
"
)
idp
=
check
[
0
]
sp
=
check
[
1
]
check_result
=
check
[
2
]
result
.
append
(
{
'
sp
'
:
sp
,
'
idp
'
:
idp
,
'
check_result
'
:
check_result
.
rstrip
(
"
\n\r
"
),
'
date
'
:
date
}
)
return
jsonify
(
result
)
class
ChecksByStatus
(
Resource
):
def
get
(
self
,
status
):
file_path
=
"
logs/eccs2checks_2020-02-19.log
"
fo
=
open
(
file_path
,
"
r
"
)
result
=
[]
date
=
PurePath
(
file_path
).
parts
[
-
1
].
split
(
'
_
'
)[
1
].
split
(
'
.
'
)[
0
]
lines
=
fo
.
readlines
()
for
line
in
lines
:
check_status
=
line
.
split
(
'
;
'
)[
2
].
rstrip
(
"
\n\r
"
)
if
(
status
==
check_status
):
check
=
line
.
split
(
"
;
"
)
idp
=
check
[
0
]
sp
=
check
[
1
]
check_result
=
check
[
2
]
result
.
append
(
{
'
sp
'
:
sp
,
'
idp
'
:
idp
,
'
check_result
'
:
check_result
.
rstrip
(
"
\n\r
"
),
'
date
'
:
date
}
)
return
jsonify
(
result
)
api
.
add_resource
(
Test
,
'
/eccs/test
'
)
# Route_1
api
.
add_resource
(
AllChecks
,
'
/eccs/checks/all
'
)
# Route_2
api
.
add_resource
(
ChecksByStatus
,
'
/eccs/checks/<status>
'
)
# Route_3
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
(
port
=
'
5002
'
)
app
.
logger
=
getLogger
(
"
logs/eccs2api.log
"
,
"
INFO
"
)
app
.
run
(
port
=
'
5002
'
)
This diff is collapsed.
Click to expand it.
eccs2.py
+
4
−
3
View file @
0171f5bd
...
@@ -6,6 +6,7 @@ from selenium.webdriver.support.ui import Select
...
@@ -6,6 +6,7 @@ from selenium.webdriver.support.ui import Select
from
selenium.webdriver.common.keys
import
Keys
from
selenium.webdriver.common.keys
import
Keys
from
selenium.common.exceptions
import
NoSuchElementException
from
selenium.common.exceptions
import
NoSuchElementException
from
selenium.common.exceptions
import
TimeoutException
from
selenium.common.exceptions
import
TimeoutException
from
datetime
import
date
import
logging
import
logging
...
@@ -128,8 +129,8 @@ def getLogger(filename,log_level="DEBUG",path="./"):
...
@@ -128,8 +129,8 @@ def getLogger(filename,log_level="DEBUG",path="./"):
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
eccs2log
=
getLogger
(
"
logs/eccs2.log
"
,
"
INFO
"
)
eccs2log
=
getLogger
(
"
logs/eccs2
_
"
+
date
.
today
().
isoformat
()
+
"
.log
"
,
"
INFO
"
)
eccs2checks
=
getLogger
(
"
logs/eccs2checks.log
"
,
"
INFO
"
)
eccs2checks
Log
=
getLogger
(
"
logs/eccs2checks
_
"
+
date
.
today
().
isoformat
()
+
"
.log
"
,
"
INFO
"
)
driver
=
setup
()
driver
=
setup
()
...
@@ -148,7 +149,7 @@ if __name__=="__main__":
...
@@ -148,7 +149,7 @@ if __name__=="__main__":
for
idp
in
listIdPs
:
for
idp
in
listIdPs
:
result
=
[]
result
=
[]
for
sp
in
sps
:
for
sp
in
sps
:
result
.
append
(
checkIdP
(
driver
,
sp
,
idp
,
eccs2checks
))
result
.
append
(
checkIdP
(
driver
,
sp
,
idp
,
eccs2checks
Log
))
# se tutti e 2 i check sono andati bene, allora l'IdP è OK, altrimenti no.
# se tutti e 2 i check sono andati bene, allora l'IdP è OK, altrimenti no.
if
(
result
[
0
]
==
result
[
1
]
==
"
OK
"
):
if
(
result
[
0
]
==
result
[
1
]
==
"
OK
"
):
...
...
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