Skip to content

Commit 983b2d3

Browse files
Merge pull request #308 from sebulibah/satosa.micro_services.account_linking-logger
Improve logging - satosa.micro_services.account_linking
2 parents 1e6e2e4 + 7ededfc commit 983b2d3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/satosa/micro_services/account_linking.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
from satosa.internal import InternalData
1212
from ..exception import SATOSAAuthenticationError
13-
from ..logging_util import satosa_logging
1413
from ..micro_services.base import ResponseMicroService
1514
from ..response import Redirect
1615

16+
import satosa.logging_util as lu
1717
logger = logging.getLogger(__name__)
1818

1919

@@ -53,8 +53,9 @@ def _handle_al_response(self, context):
5353
status_code, message = self._get_uuid(context, internal_response.auth_info.issuer, internal_response.attributes['issuer_user_id'])
5454

5555
if status_code == 200:
56-
satosa_logging(logger, logging.INFO, "issuer/id pair is linked in AL service",
57-
context.state)
56+
msg = "issuer/id pair is linked in AL service"
57+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
58+
logger.info(logline)
5859
internal_response.subject_id = message
5960
if self.id_to_attr:
6061
internal_response.attributes[self.id_to_attr] = [message]
@@ -64,8 +65,9 @@ def _handle_al_response(self, context):
6465
else:
6566
# User selected not to link their accounts, so the internal.response.subject_id is based on the
6667
# issuers id/sub which is fine
67-
satosa_logging(logger, logging.INFO, "User selected to not link their identity in AL service",
68-
context.state)
68+
msg = "User selected to not link their identity in AL service"
69+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
70+
logger.info(logline)
6971
del context.state[self.name]
7072
return super().process(context, internal_response)
7173

@@ -94,15 +96,17 @@ def process(self, context, internal_response):
9496
# Store the issuer subject_id/sub because we'll need it in handle_al_response
9597
internal_response.attributes['issuer_user_id'] = internal_response.subject_id
9698
if status_code == 200:
97-
satosa_logging(logger, logging.INFO, "issuer/id pair is linked in AL service",
98-
context.state)
99+
msg = "issuer/id pair is linked in AL service"
100+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
101+
logger.info(logline)
99102
internal_response.subject_id = message
100103
data['user_id'] = message
101104
if self.id_to_attr:
102105
internal_response.attributes[self.id_to_attr] = [message]
103106
else:
104-
satosa_logging(logger, logging.INFO, "issuer/id pair is not linked in AL service. Got a ticket",
105-
context.state)
107+
msg = "issuer/id pair is not linked in AL service. Got a ticket"
108+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
109+
logger.info(logline)
106110
data['ticket'] = message
107111
jws = JWS(json.dumps(data), alg=self.signing_key.alg).sign_compact([self.signing_key])
108112
context.state[self.name] = internal_response.to_dict()
@@ -137,12 +141,14 @@ def _get_uuid(self, context, issuer, id):
137141
response = requests.get(request)
138142
except Exception as con_exc:
139143
msg = "Could not connect to account linking service"
140-
satosa_logging(logger, logging.CRITICAL, msg, context.state, exc_info=True)
144+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
145+
logger.critical(logline)
141146
raise SATOSAAuthenticationError(context.state, msg) from con_exc
142147

143148
if response.status_code not in [200, 404]:
144-
msg = "Got status code '%s' from account linking service" % (response.status_code)
145-
satosa_logging(logger, logging.CRITICAL, msg, context.state)
149+
msg = "Got status code '{}' from account linking service".format(response.status_code)
150+
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
151+
logger.critical(logline)
146152
raise SATOSAAuthenticationError(context.state, msg)
147153

148154
return response.status_code, response.text

0 commit comments

Comments
 (0)