Skip to content

Commit 497886e

Browse files
committed
Rework email sending as a reference placed in a context.
1 parent 08dba13 commit 497886e

19 files changed

Lines changed: 85 additions & 75 deletions

mig/server/grid_notify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def send_notifications(configuration):
130130
notify_message = "Found %s new events since: %s\n\n" \
131131
% (total_events, timestr) \
132132
+ notify_message
133-
status = configuration.send_email(
133+
status = send_email(configuration,
134134
recipient,
135135
subject,
136136
notify_message)

mig/shared/conf.py

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@
3737
from mig.shared.fileio import unpickle
3838

3939

40-
_RUNTIME_ASSISTANTS = {
41-
'send_email': None,
42-
}
43-
44-
45-
def default_runtime_assistants():
46-
runtime_services = dict(_RUNTIME_ASSISTANTS)
47-
48-
from mig.shared.notification import send_email
49-
runtime_services['send_email'] = send_email
50-
51-
return runtime_services
52-
53-
5440
class RuntimeConfiguration:
5541
"""A proxy object to be passed in-place of a Configuration which can be
5642
extended with information relevant only at runtime.
@@ -66,9 +52,9 @@ class RuntimeConfiguration:
6652
to callers without being mixed in with the statuc data.
6753
"""
6854

69-
def __init__(self, configuration, assistants):
55+
def __init__(self, configuration):
7056
object.__setattr__(self, '_configuration', configuration)
71-
object.__setattr__(self, '_assistants', assistants)
57+
object.__setattr__(self, '_context', {})
7258

7359
def __delattr__(self, attr):
7460
return setattr(self._configuration, attr)
@@ -79,28 +65,11 @@ def __getattr__(self, attr):
7965
def __setattr__(self, attr, value):
8066
return setattr(self._configuration, attr, value)
8167

82-
def get_assistant(self, assistant_name):
83-
return self._assistants[assistant_name]
84-
85-
def send_email(self, *args, **kwargs):
86-
send_email = self._assistants['send_email']
87-
return send_email(self, *args, **kwargs)
88-
89-
@classmethod
90-
def create(cls, configuration, assistants):
91-
supplied_assistants = set(assistants.keys())
92-
expected_assistants = set(_RUNTIME_ASSISTANTS.keys())
93-
94-
missing_assistants = expected_assistants - supplied_assistants
95-
if missing_assistants:
96-
raise RuntimeError('missing runtime assistants: %s'
97-
% (missing_assistants,))
98-
99-
return cls(configuration, assistants)
68+
def context_get(self, context_key):
69+
return self._context.get(context_key, None)
10070

101-
@staticmethod
102-
def default_assistants():
103-
return default_runtime_assistants()
71+
def context_set(self, context_key, context_value):
72+
self._context[context_key] = context_value
10473

10574

10675
def get_configuration_object(config_file=None,
@@ -135,8 +104,7 @@ def get_configuration_object(config_file=None,
135104
if raw:
136105
return configuration
137106

138-
assistants = RuntimeConfiguration.default_assistants()
139-
return RuntimeConfiguration(configuration, assistants)
107+
return RuntimeConfiguration(configuration)
140108

141109

142110
def get_resource_configuration(resource_home, unique_resource_name,

mig/shared/configuration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'skip_log',
8484
'verbose',
8585
'logger',
86+
'_context',
8687
])
8788

8889

mig/shared/functionality/autocreate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def main(client_id, user_arguments_dict, environ=None):
740740
logger.info('Send email: to: %s, header: %s, smtp_server: %s'
741741
% (email, email_header, smtp_server))
742742
logger.debug('email body: %s' % email_msg)
743-
if not configuration.send_email(email, email_header, email_msg):
743+
if not send_email(configuration, email, email_header, email_msg):
744744
output_objects.append({
745745
'object_type': 'error_text', 'text': """An error occurred trying
746746
to send your account welcome email. Please contact support (%s) and include the

mig/shared/functionality/extcertaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def main(client_id, user_arguments_dict):
316316

317317
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
318318
% (admin_email, email_header, email_msg, smtp_server))
319-
if not configuration.send_email(admin_email, email_header, email_msg):
319+
if not send_email(configuration, admin_email, email_header, email_msg):
320320
output_objects.append({'object_type': 'error_text', 'text':
321321
"""An error occurred trying to inform the site
322322
admins about your request for existing certificate sign up. Please contact %s site

mig/shared/functionality/extoidaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def main(client_id, user_arguments_dict):
282282

283283
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
284284
% (admin_email, email_header, email_msg, smtp_server))
285-
if not configuration.send_email(admin_email, email_header, email_msg):
285+
if not send_email(configuration, admin_email, email_header, email_msg):
286286
output_objects.append({'object_type': 'error_text', 'text':
287287
"""An error occurred trying to inform the site
288288
admins about your request for OpenID account access. Please contact %s site

mig/shared/functionality/peersaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def main(client_id, user_arguments_dict):
309309
logger.info('Sending invitation: to: %s, header: %s, msg: %s, smtp_server: %s'
310310
% (peer_email, email_header, email_msg,
311311
smtp_server))
312-
if configuration.send_email(peer_email, email_header, email_msg):
312+
if send_email(configuration, peer_email, email_header, email_msg):
313313
succeeded.append(peer_email)
314314
else:
315315
failed.append(peer_email)
@@ -368,7 +368,7 @@ def main(client_id, user_arguments_dict):
368368

369369
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
370370
% (admin_email, email_header, email_msg, smtp_server))
371-
if not configuration.send_email(admin_email, email_header, email_msg):
371+
if not send_email(configuration, admin_email, email_header, email_msg):
372372
output_objects.append({'object_type': 'error_text', 'text': '''
373373
An error occurred trying to send the email about your %s peers to the site
374374
administrators. Please contact %s site support at %s or manually inform the

mig/shared/functionality/reqcertaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def main(client_id, user_arguments_dict):
346346

347347
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
348348
% (admin_email, email_header, email_msg, smtp_server))
349-
if not configuration.send_email(admin_email, email_header, email_msg):
349+
if not send_email(configuration, admin_email, email_header, email_msg):
350350
output_objects.append({'object_type': 'error_text', 'text':
351351
"""An error occurred trying to inform the site
352352
admins about your request for certificate sign up. Please contact %s site

mig/shared/functionality/reqoidaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def main(client_id, user_arguments_dict):
357357

358358
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
359359
% (admin_email, email_header, email_msg, smtp_server))
360-
if not configuration.send_email(admin_email, email_header, email_msg):
360+
if not send_email(configuration, admin_email, email_header, email_msg):
361361
output_objects.append({'object_type': 'error_text', 'text':
362362
"""An error occurred trying to inform the site
363363
admins about your request for OpenID account access. Please contact %s site

mig/shared/functionality/reqpwresetaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def main(client_id, user_arguments_dict):
271271

272272
logger.info('Sending email: to: %s, header: %s, msg: %s, smtp_server: %s'
273273
% (email_to, email_header, email_msg, smtp_server))
274-
if not configuration.send_email(email_to, email_header, email_msg):
274+
if not send_email(configuration, email_to, email_header, email_msg):
275275
output_objects.append({'object_type': 'error_text', 'text':
276276
"""An error occurred trying to send the email
277277
for an account %s password reset request. Please contact %s site support at %s

0 commit comments

Comments
 (0)