Exemple #1
0
    def create_audit_entry(self, request, transaction_id=None, **kwargs):
        entry = AuditLogEntry(
            actor=request.user if request.user.is_authenticated() else None,
            # TODO(jtcunning): assert that REMOTE_ADDR is a real IP.
            ip_address=request.META['REMOTE_ADDR'],
            **kwargs
        )

        # Only create a real AuditLogEntry record if we are passing an event type
        # otherwise, we want to still log to our actual logging
        if entry.event is not None:
            entry.save()

        extra = {
            'ip_address': entry.ip_address,
            'organization_id': entry.organization_id,
            'object_id': entry.target_object,
            'entry_id': entry.id,
            'actor_label': entry.actor_label
        }

        if transaction_id is not None:
            extra['transaction_id'] = transaction_id

        audit_logger.info(entry.get_event_display(), extra=extra)

        return entry
Exemple #2
0
    def create_audit_entry(self, request, transaction_id=None, **kwargs):
        entry = AuditLogEntry(
            actor=request.user if request.user.is_authenticated() else None,
            # TODO(jtcunning): assert that REMOTE_ADDR is a real IP.
            ip_address=request.META['REMOTE_ADDR'],
            **kwargs)

        # Only create a real AuditLogEntry record if we are passing an event type
        # otherwise, we want to still log to our actual logging
        if entry.event is not None:
            entry.save()

        extra = {
            'ip_address': entry.ip_address,
            'organization_id': entry.organization_id,
            'object_id': entry.target_object,
            'entry_id': entry.id,
            'actor_label': entry.actor_label
        }

        if transaction_id is not None:
            extra['transaction_id'] = transaction_id

        audit_logger.info(entry.get_event_display(), extra=extra)

        return entry
Exemple #3
0
    def create_audit_entry(self, request, transaction_id=None, **kwargs):
        user = request.user if request.user.is_authenticated() else None
        api_key = request.auth if isinstance(request.auth, ApiKey) else None

        entry = AuditLogEntry(actor=user,
                              actor_key=api_key,
                              ip_address=request.META['REMOTE_ADDR'],
                              **kwargs)

        # Only create a real AuditLogEntry record if we are passing an event type
        # otherwise, we want to still log to our actual logging
        if entry.event is not None:
            entry.save()

        extra = {
            'ip_address': entry.ip_address,
            'organization_id': entry.organization_id,
            'object_id': entry.target_object,
            'entry_id': entry.id,
            'actor_label': entry.actor_label
        }
        if entry.actor_id:
            extra['actor_id'] = entry.actor_id
        if entry.actor_key_id:
            extra['actor_key_id'] = entry.actor_key_id
        if transaction_id is not None:
            extra['transaction_id'] = transaction_id

        audit_logger.info(entry.get_event_display(), extra=extra)

        return entry
Exemple #4
0
    def create_audit_entry(self, request, transaction_id=None, **kwargs):
        user = request.user if request.user.is_authenticated() else None
        api_key = request.auth if isinstance(request.auth, ApiKey) else None

        entry = AuditLogEntry(
            actor=user, actor_key=api_key, ip_address=request.META['REMOTE_ADDR'], **kwargs
        )

        # Only create a real AuditLogEntry record if we are passing an event type
        # otherwise, we want to still log to our actual logging
        if entry.event is not None:
            entry.save()

        extra = {
            'ip_address': entry.ip_address,
            'organization_id': entry.organization_id,
            'object_id': entry.target_object,
            'entry_id': entry.id,
            'actor_label': entry.actor_label
        }
        if entry.actor_id:
            extra['actor_id'] = entry.actor_id
        if entry.actor_key_id:
            extra['actor_key_id'] = entry.actor_key_id
        if transaction_id is not None:
            extra['transaction_id'] = transaction_id

        audit_logger.info(entry.get_event_display(), extra=extra)

        return entry
Exemple #5
0
def org_delete_confirm(request):
    from sentry.models import AuditLogEntry

    org = Organization.get_default()
    entry = AuditLogEntry(
        organization=org,
        actor=request.user,
        ip_address=request.META['REMOTE_ADDR'],
    )

    return MailPreview(
        html_template='sentry/emails/org_delete_confirm.html',
        text_template='sentry/emails/org_delete_confirm.txt',
        context={
            'organization':
            org,
            'audit_log_entry':
            entry,
            'eta':
            timezone.now() + timedelta(days=1),
            'url':
            absolute_uri(
                reverse(
                    'sentry-restore-organization',
                    args=[org.slug],
                )),
        },
    ).render(request)
Exemple #6
0
def create_audit_entry(request, transaction_id=None, logger=None, **kwargs):
    from sentry.models import ApiKey  # Django 1.9 setup issue
    from sentry.models import AuditLogEntry  # Django 1.9 setup issue
    from sentry.models import AuditLogEntryEvent  # Django 1.9 setup issue
    user = request.user if request.user.is_authenticated() else None
    api_key = request.auth if hasattr(request, 'auth') \
        and isinstance(request.auth, ApiKey) else None

    entry = AuditLogEntry(actor=user,
                          actor_key=api_key,
                          ip_address=request.META['REMOTE_ADDR'],
                          **kwargs)

    # Only create a real AuditLogEntry record if we are passing an event type
    # otherwise, we want to still log to our actual logging
    if entry.event is not None:
        entry.save()

    if entry.event == AuditLogEntryEvent.ORG_REMOVE:
        create_org_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE:
        create_project_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.TEAM_REMOVE:
        create_team_delete_log(entry)

    extra = {
        'ip_address': entry.ip_address,
        'organization_id': entry.organization_id,
        'object_id': entry.target_object,
        'entry_id': entry.id,
        'actor_label': entry.actor_label
    }
    if entry.actor_id:
        extra['actor_id'] = entry.actor_id
    if entry.actor_key_id:
        extra['actor_key_id'] = entry.actor_key_id
    if transaction_id is not None:
        extra['transaction_id'] = transaction_id

    if logger:
        logger.info(entry.get_event_display(), extra=extra)

    return entry
Exemple #7
0
def create_audit_entry(request, transaction_id=None, logger=None, **kwargs):
    user = kwargs.pop("actor",
                      request.user if request.user.is_authenticated else None)
    api_key = (request.auth if hasattr(request, "auth")
               and isinstance(request.auth, ApiKey) else None)

    entry = AuditLogEntry(actor=user,
                          actor_key=api_key,
                          ip_address=request.META["REMOTE_ADDR"],
                          **kwargs)

    # Only create a real AuditLogEntry record if we are passing an event type
    # otherwise, we want to still log to our actual logging
    if entry.event is not None:
        entry.save()

    if entry.event == AuditLogEntryEvent.ORG_REMOVE:
        create_org_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE:
        create_project_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.TEAM_REMOVE:
        create_team_delete_log(entry)

    extra = {
        "ip_address": entry.ip_address,
        "organization_id": entry.organization_id,
        "object_id": entry.target_object,
        "entry_id": entry.id,
        "actor_label": entry.actor_label,
    }
    if entry.actor_id:
        extra["actor_id"] = entry.actor_id
    if entry.actor_key_id:
        extra["actor_key_id"] = entry.actor_key_id
    if transaction_id is not None:
        extra["transaction_id"] = transaction_id

    if logger:
        logger.info(entry.get_event_display(), extra=extra)

    return entry
Exemple #8
0
def create_audit_entry_from_user(user,
                                 api_key=None,
                                 ip_address=None,
                                 transaction_id=None,
                                 logger=None,
                                 **kwargs):
    entry = AuditLogEntry(actor=user,
                          actor_key=api_key,
                          ip_address=ip_address,
                          **kwargs)

    # Only create a real AuditLogEntry record if we are passing an event type
    # otherwise, we want to still log to our actual logging
    if entry.event is not None:
        entry.save()

    if entry.event == AuditLogEntryEvent.ORG_REMOVE:
        create_org_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.PROJECT_REMOVE:
        create_project_delete_log(entry)

    elif entry.event == AuditLogEntryEvent.TEAM_REMOVE:
        create_team_delete_log(entry)

    extra = {
        "ip_address": entry.ip_address,
        "organization_id": entry.organization_id,
        "object_id": entry.target_object,
        "entry_id": entry.id,
        "actor_label": entry.actor_label,
    }
    if entry.actor_id:
        extra["actor_id"] = entry.actor_id
    if entry.actor_key_id:
        extra["actor_key_id"] = entry.actor_key_id
    if transaction_id is not None:
        extra["transaction_id"] = transaction_id

    if logger:
        logger.info(entry.get_event_display(), extra=extra)

    return entry
Exemple #9
0
def org_delete_confirm(request):
    from sentry.models import AuditLogEntry

    org = Organization.get_default()
    entry = AuditLogEntry(
        organization=org, actor=request.user, ip_address=request.META["REMOTE_ADDR"]
    )

    return MailPreview(
        html_template="sentry/emails/org_delete_confirm.html",
        text_template="sentry/emails/org_delete_confirm.txt",
        context={
            "organization": org,
            "audit_log_entry": entry,
            "eta": timezone.now() + timedelta(days=1),
            "url": absolute_uri(reverse("sentry-restore-organization", args=[org.slug])),
        },
    ).render(request)