Exemplo n.º 1
0
def test_yield_logs_for_export_timeout(logs_model):
    # Add some logs.
    kinds = list(LogEntryKind.select())
    user = model.user.get_user("devtable")

    start_timestamp = datetime.utcnow()
    timestamp = start_timestamp

    for kind in kinds:
        for _ in range(0, 2):
            logs_model.log_action(
                kind.name,
                namespace_name="devtable",
                repository_name="simple",
                performer=user,
                ip="1.2.3.4",
                timestamp=timestamp,
            )
            timestamp = timestamp + timedelta(seconds=1)

    # Yield the logs. Since we set the timeout to nothing, it should immediately fail.
    simple_repo = model.repository.get_repository("devtable", "simple")
    with pytest.raises(LogsIterationTimeout):
        list(
            logs_model.yield_logs_for_export(
                start_timestamp,
                timestamp + timedelta(minutes=1),
                repository_id=simple_repo.id,
                max_query_time=timedelta(seconds=0),
            )
        )
Exemplo n.º 2
0
def get_log_entry_kinds():
    kind_map = {}
    for kind in LogEntryKind.select():
        kind_map[kind.id] = kind.name
        kind_map[kind.name] = kind.id

    return kind_map
Exemplo n.º 3
0
def test_yield_logs_for_export(logs_model):
    # Add some logs.
    kinds = list(LogEntryKind.select())
    user = model.user.get_user('devtable')

    start_timestamp = datetime.utcnow()
    timestamp = start_timestamp

    for kind in kinds:
        for index in range(0, 10):
            logs_model.log_action(kind.name,
                                  namespace_name='devtable',
                                  repository_name='simple',
                                  performer=user,
                                  ip='1.2.3.4',
                                  timestamp=timestamp)
            timestamp = timestamp + timedelta(seconds=1)

    # Yield the logs.
    simple_repo = model.repository.get_repository('devtable', 'simple')
    logs_found = []
    for logs in logs_model.yield_logs_for_export(start_timestamp,
                                                 timestamp +
                                                 timedelta(minutes=10),
                                                 repository_id=simple_repo.id):
        logs_found.extend(logs)

    # Ensure we found all added logs.
    assert len(logs_found) == len(kinds) * 10
Exemplo n.º 4
0
def test_logs(namespace_name, repo_name, performer_name, check_args,
              expect_results, logs_model):
    # Add some logs.
    kinds = list(LogEntryKind.select())
    user = model.user.get_user(performer_name)

    start_timestamp = datetime.utcnow()
    timestamp = start_timestamp

    for kind in kinds:
        for index in range(0, 3):
            logs_model.log_action(kind.name,
                                  namespace_name=namespace_name,
                                  repository_name=repo_name,
                                  performer=user,
                                  ip='1.2.3.4',
                                  timestamp=timestamp)
            timestamp = timestamp + timedelta(seconds=1)

    found = _lookup_logs(logs_model, start_timestamp,
                         start_timestamp + timedelta(minutes=10), **check_args)
    if expect_results:
        assert len(found) == len(kinds) * 3
    else:
        assert not found

    aggregated_counts = logs_model.get_aggregated_log_counts(
        start_timestamp, start_timestamp + timedelta(minutes=10), **check_args)
    if expect_results:
        assert len(aggregated_counts) == len(kinds)
        for ac in aggregated_counts:
            assert ac.count == 3
    else:
        assert not aggregated_counts
Exemplo n.º 5
0
def initialize_database():
    db_encrypter.initialize(FieldEncrypter("anothercrazykey!"))
    db.create_tables(all_models)

    Role.create(name="admin")
    Role.create(name="write")
    Role.create(name="read")
    TeamRole.create(name="admin")
    TeamRole.create(name="creator")
    TeamRole.create(name="member")
    Visibility.create(name="public")
    Visibility.create(name="private")

    LoginService.create(name="google")
    LoginService.create(name="github")
    LoginService.create(name="quayrobot")
    LoginService.create(name="ldap")
    LoginService.create(name="jwtauthn")
    LoginService.create(name="keystone")
    LoginService.create(name="dex")
    LoginService.create(name="oidc")

    BuildTriggerService.create(name="github")
    BuildTriggerService.create(name="custom-git")
    BuildTriggerService.create(name="bitbucket")
    BuildTriggerService.create(name="gitlab")

    AccessTokenKind.create(name="build-worker")
    AccessTokenKind.create(name="pushpull-token")

    LogEntryKind.create(name="account_change_plan")
    LogEntryKind.create(name="account_change_cc")
    LogEntryKind.create(name="account_change_password")
    LogEntryKind.create(name="account_convert")

    LogEntryKind.create(name="create_robot")
    LogEntryKind.create(name="delete_robot")

    LogEntryKind.create(name="create_repo")
    LogEntryKind.create(name="push_repo")
    LogEntryKind.create(name="pull_repo")
    LogEntryKind.create(name="delete_repo")
    LogEntryKind.create(name="create_tag")
    LogEntryKind.create(name="move_tag")
    LogEntryKind.create(name="delete_tag")
    LogEntryKind.create(name="revert_tag")
    LogEntryKind.create(name="add_repo_permission")
    LogEntryKind.create(name="change_repo_permission")
    LogEntryKind.create(name="delete_repo_permission")
    LogEntryKind.create(name="change_repo_visibility")
    LogEntryKind.create(name="change_repo_trust")
    LogEntryKind.create(name="add_repo_accesstoken")
    LogEntryKind.create(name="delete_repo_accesstoken")
    LogEntryKind.create(name="set_repo_description")
    LogEntryKind.create(name="change_repo_state")

    LogEntryKind.create(name="build_dockerfile")

    LogEntryKind.create(name="org_create_team")
    LogEntryKind.create(name="org_delete_team")
    LogEntryKind.create(name="org_invite_team_member")
    LogEntryKind.create(name="org_delete_team_member_invite")
    LogEntryKind.create(name="org_add_team_member")
    LogEntryKind.create(name="org_team_member_invite_accepted")
    LogEntryKind.create(name="org_team_member_invite_declined")
    LogEntryKind.create(name="org_remove_team_member")
    LogEntryKind.create(name="org_set_team_description")
    LogEntryKind.create(name="org_set_team_role")

    LogEntryKind.create(name="create_prototype_permission")
    LogEntryKind.create(name="modify_prototype_permission")
    LogEntryKind.create(name="delete_prototype_permission")

    LogEntryKind.create(name="setup_repo_trigger")
    LogEntryKind.create(name="delete_repo_trigger")

    LogEntryKind.create(name="create_application")
    LogEntryKind.create(name="update_application")
    LogEntryKind.create(name="delete_application")
    LogEntryKind.create(name="reset_application_client_secret")

    # Note: These next two are deprecated.
    LogEntryKind.create(name="add_repo_webhook")
    LogEntryKind.create(name="delete_repo_webhook")

    LogEntryKind.create(name="add_repo_notification")
    LogEntryKind.create(name="delete_repo_notification")
    LogEntryKind.create(name="reset_repo_notification")

    LogEntryKind.create(name="regenerate_robot_token")

    LogEntryKind.create(name="repo_verb")

    LogEntryKind.create(name="repo_mirror_enabled")
    LogEntryKind.create(name="repo_mirror_disabled")
    LogEntryKind.create(name="repo_mirror_config_changed")
    LogEntryKind.create(name="repo_mirror_sync_started")
    LogEntryKind.create(name="repo_mirror_sync_failed")
    LogEntryKind.create(name="repo_mirror_sync_success")
    LogEntryKind.create(name="repo_mirror_sync_now_requested")
    LogEntryKind.create(name="repo_mirror_sync_tag_success")
    LogEntryKind.create(name="repo_mirror_sync_tag_failed")
    LogEntryKind.create(name="repo_mirror_sync_test_success")
    LogEntryKind.create(name="repo_mirror_sync_test_failed")
    LogEntryKind.create(name="repo_mirror_sync_test_started")

    LogEntryKind.create(name="service_key_create")
    LogEntryKind.create(name="service_key_approve")
    LogEntryKind.create(name="service_key_delete")
    LogEntryKind.create(name="service_key_modify")
    LogEntryKind.create(name="service_key_extend")
    LogEntryKind.create(name="service_key_rotate")

    LogEntryKind.create(name="take_ownership")

    LogEntryKind.create(name="manifest_label_add")
    LogEntryKind.create(name="manifest_label_delete")

    LogEntryKind.create(name="change_tag_expiration")
    LogEntryKind.create(name="toggle_repo_trigger")

    LogEntryKind.create(name="create_app_specific_token")
    LogEntryKind.create(name="revoke_app_specific_token")

    ImageStorageLocation.create(name="local_eu")
    ImageStorageLocation.create(name="local_us")

    ApprBlobPlacementLocation.create(name="local_eu")
    ApprBlobPlacementLocation.create(name="local_us")

    ImageStorageTransformation.create(name="squash")
    ImageStorageTransformation.create(name="aci")

    ImageStorageSignatureKind.create(name="gpg2")

    # NOTE: These MUST be copied over to NotificationKind, since every external
    # notification can also generate a Quay.io notification.
    ExternalNotificationEvent.create(name="repo_push")
    ExternalNotificationEvent.create(name="build_queued")
    ExternalNotificationEvent.create(name="build_start")
    ExternalNotificationEvent.create(name="build_success")
    ExternalNotificationEvent.create(name="build_cancelled")
    ExternalNotificationEvent.create(name="build_failure")
    ExternalNotificationEvent.create(name="vulnerability_found")

    ExternalNotificationEvent.create(name="repo_mirror_sync_started")
    ExternalNotificationEvent.create(name="repo_mirror_sync_success")
    ExternalNotificationEvent.create(name="repo_mirror_sync_failed")

    ExternalNotificationMethod.create(name="quay_notification")
    ExternalNotificationMethod.create(name="email")
    ExternalNotificationMethod.create(name="webhook")

    ExternalNotificationMethod.create(name="flowdock")
    ExternalNotificationMethod.create(name="hipchat")
    ExternalNotificationMethod.create(name="slack")

    NotificationKind.create(name="repo_push")
    NotificationKind.create(name="build_queued")
    NotificationKind.create(name="build_start")
    NotificationKind.create(name="build_success")
    NotificationKind.create(name="build_cancelled")
    NotificationKind.create(name="build_failure")
    NotificationKind.create(name="vulnerability_found")
    NotificationKind.create(name="service_key_submitted")

    NotificationKind.create(name="password_required")
    NotificationKind.create(name="over_private_usage")
    NotificationKind.create(name="expiring_license")
    NotificationKind.create(name="maintenance")
    NotificationKind.create(name="org_team_invite")

    NotificationKind.create(name="repo_mirror_sync_started")
    NotificationKind.create(name="repo_mirror_sync_success")
    NotificationKind.create(name="repo_mirror_sync_failed")

    NotificationKind.create(name="test_notification")

    QuayRegion.create(name="us")
    QuayService.create(name="quay")

    MediaType.create(name="text/plain")
    MediaType.create(name="application/json")
    MediaType.create(name="text/markdown")
    MediaType.create(name="application/vnd.cnr.blob.v0.tar+gzip")
    MediaType.create(name="application/vnd.cnr.package-manifest.helm.v0.json")
    MediaType.create(name="application/vnd.cnr.package-manifest.kpm.v0.json")
    MediaType.create(
        name="application/vnd.cnr.package-manifest.docker-compose.v0.json")
    MediaType.create(name="application/vnd.cnr.package.kpm.v0.tar+gzip")
    MediaType.create(name="application/vnd.cnr.package.helm.v0.tar+gzip")
    MediaType.create(
        name="application/vnd.cnr.package.docker-compose.v0.tar+gzip")
    MediaType.create(name="application/vnd.cnr.manifests.v0.json")
    MediaType.create(name="application/vnd.cnr.manifest.list.v0.json")

    for media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
        MediaType.create(name=media_type)

    for media_type in DOCKER_SCHEMA2_CONTENT_TYPES:
        MediaType.create(name=media_type)

    for media_type in OCI_CONTENT_TYPES:
        MediaType.create(name=media_type)

    LabelSourceType.create(name="manifest")
    LabelSourceType.create(name="api", mutable=True)
    LabelSourceType.create(name="internal")

    UserPromptKind.create(name="confirm_username")
    UserPromptKind.create(name="enter_name")
    UserPromptKind.create(name="enter_company")

    RepositoryKind.create(name="image")
    RepositoryKind.create(name="application")

    ApprTagKind.create(name="tag")
    ApprTagKind.create(name="release")
    ApprTagKind.create(name="channel")

    DisableReason.create(name="user_toggled")
    DisableReason.create(name="successive_build_failures")
    DisableReason.create(name="successive_build_internal_errors")

    TagKind.create(name="tag")
Exemplo n.º 6
0
 def _get_log_count(self):
     return (LogEntry3.select().where(LogEntry3.kind == LogEntryKind.get(
         name=self.log_kind)).count())
Exemplo n.º 7
0
def initialize_database():
    db.create_tables(all_models)

    Role.create(name='admin')
    Role.create(name='write')
    Role.create(name='read')
    TeamRole.create(name='admin')
    TeamRole.create(name='creator')
    TeamRole.create(name='member')
    Visibility.create(name='public')
    Visibility.create(name='private')

    LoginService.create(name='google')
    LoginService.create(name='github')
    LoginService.create(name='quayrobot')
    LoginService.create(name='ldap')
    LoginService.create(name='jwtauthn')
    LoginService.create(name='keystone')
    LoginService.create(name='dex')
    LoginService.create(name='oidc')

    BuildTriggerService.create(name='github')
    BuildTriggerService.create(name='custom-git')
    BuildTriggerService.create(name='bitbucket')
    BuildTriggerService.create(name='gitlab')

    AccessTokenKind.create(name='build-worker')
    AccessTokenKind.create(name='pushpull-token')

    LogEntryKind.create(name='account_change_plan')
    LogEntryKind.create(name='account_change_cc')
    LogEntryKind.create(name='account_change_password')
    LogEntryKind.create(name='account_convert')

    LogEntryKind.create(name='create_robot')
    LogEntryKind.create(name='delete_robot')

    LogEntryKind.create(name='create_repo')
    LogEntryKind.create(name='push_repo')
    LogEntryKind.create(name='pull_repo')
    LogEntryKind.create(name='delete_repo')
    LogEntryKind.create(name='create_tag')
    LogEntryKind.create(name='move_tag')
    LogEntryKind.create(name='delete_tag')
    LogEntryKind.create(name='revert_tag')
    LogEntryKind.create(name='add_repo_permission')
    LogEntryKind.create(name='change_repo_permission')
    LogEntryKind.create(name='delete_repo_permission')
    LogEntryKind.create(name='change_repo_visibility')
    LogEntryKind.create(name='change_repo_trust')
    LogEntryKind.create(name='add_repo_accesstoken')
    LogEntryKind.create(name='delete_repo_accesstoken')
    LogEntryKind.create(name='set_repo_description')
    LogEntryKind.create(name='change_repo_state')

    LogEntryKind.create(name='build_dockerfile')

    LogEntryKind.create(name='org_create_team')
    LogEntryKind.create(name='org_delete_team')
    LogEntryKind.create(name='org_invite_team_member')
    LogEntryKind.create(name='org_delete_team_member_invite')
    LogEntryKind.create(name='org_add_team_member')
    LogEntryKind.create(name='org_team_member_invite_accepted')
    LogEntryKind.create(name='org_team_member_invite_declined')
    LogEntryKind.create(name='org_remove_team_member')
    LogEntryKind.create(name='org_set_team_description')
    LogEntryKind.create(name='org_set_team_role')

    LogEntryKind.create(name='create_prototype_permission')
    LogEntryKind.create(name='modify_prototype_permission')
    LogEntryKind.create(name='delete_prototype_permission')

    LogEntryKind.create(name='setup_repo_trigger')
    LogEntryKind.create(name='delete_repo_trigger')

    LogEntryKind.create(name='create_application')
    LogEntryKind.create(name='update_application')
    LogEntryKind.create(name='delete_application')
    LogEntryKind.create(name='reset_application_client_secret')

    # Note: These next two are deprecated.
    LogEntryKind.create(name='add_repo_webhook')
    LogEntryKind.create(name='delete_repo_webhook')

    LogEntryKind.create(name='add_repo_notification')
    LogEntryKind.create(name='delete_repo_notification')
    LogEntryKind.create(name='reset_repo_notification')

    LogEntryKind.create(name='regenerate_robot_token')

    LogEntryKind.create(name='repo_verb')

    LogEntryKind.create(name='repo_mirror_enabled')
    LogEntryKind.create(name='repo_mirror_disabled')
    LogEntryKind.create(name='repo_mirror_config_changed')
    LogEntryKind.create(name='repo_mirror_sync_started')
    LogEntryKind.create(name='repo_mirror_sync_failed')
    LogEntryKind.create(name='repo_mirror_sync_success')
    LogEntryKind.create(name='repo_mirror_sync_now_requested')
    LogEntryKind.create(name='repo_mirror_sync_tag_success')
    LogEntryKind.create(name='repo_mirror_sync_tag_failed')
    LogEntryKind.create(name='repo_mirror_sync_test_success')
    LogEntryKind.create(name='repo_mirror_sync_test_failed')
    LogEntryKind.create(name='repo_mirror_sync_test_started')

    LogEntryKind.create(name='service_key_create')
    LogEntryKind.create(name='service_key_approve')
    LogEntryKind.create(name='service_key_delete')
    LogEntryKind.create(name='service_key_modify')
    LogEntryKind.create(name='service_key_extend')
    LogEntryKind.create(name='service_key_rotate')

    LogEntryKind.create(name='take_ownership')

    LogEntryKind.create(name='manifest_label_add')
    LogEntryKind.create(name='manifest_label_delete')

    LogEntryKind.create(name='change_tag_expiration')
    LogEntryKind.create(name='toggle_repo_trigger')

    LogEntryKind.create(name='create_app_specific_token')
    LogEntryKind.create(name='revoke_app_specific_token')

    ImageStorageLocation.create(name='local_eu')
    ImageStorageLocation.create(name='local_us')

    ApprBlobPlacementLocation.create(name='local_eu')
    ApprBlobPlacementLocation.create(name='local_us')

    ImageStorageTransformation.create(name='squash')
    ImageStorageTransformation.create(name='aci')

    ImageStorageSignatureKind.create(name='gpg2')

    # NOTE: These MUST be copied over to NotificationKind, since every external
    # notification can also generate a Quay.io notification.
    ExternalNotificationEvent.create(name='repo_push')
    ExternalNotificationEvent.create(name='build_queued')
    ExternalNotificationEvent.create(name='build_start')
    ExternalNotificationEvent.create(name='build_success')
    ExternalNotificationEvent.create(name='build_cancelled')
    ExternalNotificationEvent.create(name='build_failure')
    ExternalNotificationEvent.create(name='vulnerability_found')

    ExternalNotificationEvent.create(name='repo_mirror_sync_started')
    ExternalNotificationEvent.create(name='repo_mirror_sync_success')
    ExternalNotificationEvent.create(name='repo_mirror_sync_failed')

    ExternalNotificationMethod.create(name='quay_notification')
    ExternalNotificationMethod.create(name='email')
    ExternalNotificationMethod.create(name='webhook')

    ExternalNotificationMethod.create(name='flowdock')
    ExternalNotificationMethod.create(name='hipchat')
    ExternalNotificationMethod.create(name='slack')

    NotificationKind.create(name='repo_push')
    NotificationKind.create(name='build_queued')
    NotificationKind.create(name='build_start')
    NotificationKind.create(name='build_success')
    NotificationKind.create(name='build_cancelled')
    NotificationKind.create(name='build_failure')
    NotificationKind.create(name='vulnerability_found')
    NotificationKind.create(name='service_key_submitted')

    NotificationKind.create(name='password_required')
    NotificationKind.create(name='over_private_usage')
    NotificationKind.create(name='expiring_license')
    NotificationKind.create(name='maintenance')
    NotificationKind.create(name='org_team_invite')

    NotificationKind.create(name='repo_mirror_sync_started')
    NotificationKind.create(name='repo_mirror_sync_success')
    NotificationKind.create(name='repo_mirror_sync_failed')

    NotificationKind.create(name='test_notification')

    QuayRegion.create(name='us')
    QuayService.create(name='quay')

    MediaType.create(name='text/plain')
    MediaType.create(name='application/json')
    MediaType.create(name='text/markdown')
    MediaType.create(name='application/vnd.cnr.blob.v0.tar+gzip')
    MediaType.create(name='application/vnd.cnr.package-manifest.helm.v0.json')
    MediaType.create(name='application/vnd.cnr.package-manifest.kpm.v0.json')
    MediaType.create(
        name='application/vnd.cnr.package-manifest.docker-compose.v0.json')
    MediaType.create(name='application/vnd.cnr.package.kpm.v0.tar+gzip')
    MediaType.create(name='application/vnd.cnr.package.helm.v0.tar+gzip')
    MediaType.create(
        name='application/vnd.cnr.package.docker-compose.v0.tar+gzip')
    MediaType.create(name='application/vnd.cnr.manifests.v0.json')
    MediaType.create(name='application/vnd.cnr.manifest.list.v0.json')

    for media_type in DOCKER_SCHEMA1_CONTENT_TYPES:
        MediaType.create(name=media_type)

    for media_type in DOCKER_SCHEMA2_CONTENT_TYPES:
        MediaType.create(name=media_type)

    LabelSourceType.create(name='manifest')
    LabelSourceType.create(name='api', mutable=True)
    LabelSourceType.create(name='internal')

    UserPromptKind.create(name='confirm_username')
    UserPromptKind.create(name='enter_name')
    UserPromptKind.create(name='enter_company')

    RepositoryKind.create(name='image')
    RepositoryKind.create(name='application')

    ApprTagKind.create(name='tag')
    ApprTagKind.create(name='release')
    ApprTagKind.create(name='channel')

    DisableReason.create(name='user_toggled')
    DisableReason.create(name='successive_build_failures')
    DisableReason.create(name='successive_build_internal_errors')

    TagKind.create(name='tag')