예제 #1
0
    def publish_activity(activity: Activity):  # pylint:disable=unused-argument
        """Publish the activity asynchronously, using the given details."""
        try:
            # find user_id if haven't passed in
            if not activity.actor_id and g and 'jwt_oidc_token_info' in g:
                user: UserModel = UserModel.find_by_jwt_token()
                activity.actor_id = user.id if user else None
            data = {
                'actorId': activity.actor_id,
                'action': activity.action,
                'itemType': 'ACCOUNT',
                'itemName': activity.name,
                'itemId': activity.id,
                'itemValue': activity.value,
                'orgId': activity.org_id,
                'remoteAddr': fetch_remote_addr(),
                'createdAt': f'{datetime.now()}'
            }
            source = 'https://api.auth.bcregistry.gov.bc.ca/v1/accounts'

            payload = {
                'specversion': '1.x-wip',
                'type': 'bc.registry.auth.activity',
                'source': source,
                'id': str(uuid.uuid1()),
                'time': f'{datetime.now()}',
                'datacontenttype': 'application/json',
                'data': data
            }
            publish_response(payload=payload, client_name=CONFIG.NATS_ACTIVITY_CLIENT_NAME,
                             subject=CONFIG.NATS_ACTIVITY_SUBJECT)
        except Exception as err:  # noqa: B902 # pylint: disable=broad-except
            capture_message('Activity Queue Publish Event Error:' + str(err), level='error')
            current_app.logger.error('Activity Queue Publish Event Error:', exc_info=True)
예제 #2
0
def publish_to_mailer(notification_type,
                      org_id: str = None,
                      data=None,
                      business_identifier: str = None):
    """Publish from auth to mailer."""
    if data is None:
        data = {
            'accountId': org_id,
        }
    source: str = None
    if org_id:
        source = f'https://api.auth.bcregistry.gov.bc.ca/v1/accounts/{org_id}'
    elif business_identifier:
        source = f'https://api.auth.bcregistry.gov.bc.ca/v1/entities/{business_identifier}'

    payload = {
        'specversion': '1.x-wip',
        'type': f'bc.registry.auth.{notification_type}',
        'source': source,
        'id': org_id,
        'time': f'{datetime.now()}',
        'datacontenttype': 'application/json',
        'data': data
    }
    publish_response(payload=payload,
                     client_name=CONFIG.NATS_MAILER_CLIENT_NAME,
                     subject=CONFIG.NATS_MAILER_SUBJECT)