Skip to content

Commit 1e6e2e4

Browse files
Merge pull request #307 from sebulibah/micro_services.consent-logging
Improve logging - satosa.micro_services.consent
2 parents 1340be3 + e4694e6 commit 1e6e2e4

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/satosa/micro_services/consent.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
from jwkest.jws import JWS
1313
from requests.exceptions import ConnectionError
1414

15+
import satosa.logging_util as lu
1516
from satosa.internal import InternalData
16-
from satosa.logging_util import satosa_logging
1717
from satosa.micro_services.base import ResponseMicroService
1818
from satosa.response import Redirect
1919

20+
2021
logger = logging.getLogger(__name__)
2122

2223
STATE_KEY = "CONSENT"
@@ -63,17 +64,22 @@ def _handle_consent_response(self, context):
6364
try:
6465
consent_attributes = self._verify_consent(hash_id)
6566
except ConnectionError as e:
66-
satosa_logging(logger, logging.ERROR,
67-
"Consent service is not reachable, no consent given.", context.state)
67+
msg = "Consent service is not reachable, no consent given."
68+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
69+
logger.error(logline)
6870
# Send an internal_response without any attributes
6971
consent_attributes = None
7072

7173
if consent_attributes is None:
72-
satosa_logging(logger, logging.INFO, "Consent was NOT given", context.state)
74+
msg = "Consent was NOT given"
75+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
76+
logger.info(logline)
7377
# If consent was not given, then don't send any attributes
7478
consent_attributes = []
7579
else:
76-
satosa_logging(logger, logging.INFO, "Consent was given", context.state)
80+
msg = "Consent was given"
81+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
82+
logger.info(logline)
7783

7884
internal_response.attributes = self._filter_attributes(internal_response.attributes, consent_attributes)
7985
return self._end_consent(context, internal_response)
@@ -94,8 +100,9 @@ def _approve_new_consent(self, context, internal_response, id_hash):
94100
try:
95101
ticket = self._consent_registration(consent_args)
96102
except (ConnectionError, UnexpectedResponseError) as e:
97-
satosa_logging(logger, logging.ERROR, "Consent request failed, no consent given: {}".format(str(e)),
98-
context.state)
103+
msg = "Consent request failed, no consent given: {}".format(str(e))
104+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
105+
logger.error(logline)
99106
# Send an internal_response without any attributes
100107
internal_response.attributes = {}
101108
return self._end_consent(context, internal_response)
@@ -125,15 +132,18 @@ def process(self, context, internal_response):
125132
# Check if consent is already given
126133
consent_attributes = self._verify_consent(id_hash)
127134
except requests.exceptions.ConnectionError as e:
128-
satosa_logging(logger, logging.ERROR,
129-
"Consent service is not reachable, no consent given.", context.state)
135+
msg = "Consent service is not reachable, no consent is given."
136+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
137+
logger.error(logline)
130138
# Send an internal_response without any attributes
131139
internal_response.attributes = {}
132140
return self._end_consent(context, internal_response)
133141

134142
# Previous consent was given
135143
if consent_attributes is not None:
136-
satosa_logging(logger, logging.DEBUG, "Previous consent was given", context.state)
144+
msg = "Previous consent was given"
145+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
146+
logger.debug(logline)
137147
internal_response.attributes = self._filter_attributes(internal_response.attributes, consent_attributes)
138148
return self._end_consent(context, internal_response)
139149

0 commit comments

Comments
 (0)