2013-10-10 03:52:28 +00:00
|
|
|
import logging
|
2014-01-13 21:32:51 +00:00
|
|
|
import json
|
2013-10-18 20:36:11 +00:00
|
|
|
import hashlib
|
2014-01-03 21:32:00 +00:00
|
|
|
import random
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
from datetime import datetime, timedelta
|
2014-01-31 02:35:39 +00:00
|
|
|
from peewee import (SqliteDatabase, create_model_tables, drop_model_tables,
|
|
|
|
savepoint_sqlite)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
from data.database import *
|
2013-10-10 03:52:28 +00:00
|
|
|
from data import model
|
2014-03-12 16:37:06 +00:00
|
|
|
from data.model import oauth
|
2014-04-03 21:31:46 +00:00
|
|
|
from app import app, storage as store
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2013-10-19 00:18:23 +00:00
|
|
|
SAMPLE_DIFFS = ['test/data/sample/diffs/diffs%s.json' % i
|
|
|
|
for i in range(1, 10)]
|
2014-02-17 20:17:39 +00:00
|
|
|
|
|
|
|
IMAGE_UUIDS = ['ab5160d1-8fb4-4022-a135-3c4de7f6ed97',
|
|
|
|
'4259533e-868d-4db3-9a78-fc24ffc03a2b',
|
|
|
|
'c2c6dc6e-24d1-4f15-a616-81c41e3e3629',
|
|
|
|
'8ec59952-8f5a-4fa0-897e-57c3337e1914',
|
|
|
|
'08a8ab1f-4aaa-4337-88ab-5b5c71a8d492',
|
|
|
|
'4a71f3db-cbb1-4c3b-858f-1be032b3e875',
|
|
|
|
'd40d531a-c70c-47f9-bf5b-2a4381db2d60',
|
|
|
|
'6fe6cebb-52b2-4036-892e-b86d6487a56b',
|
|
|
|
'e969ff76-e87d-4ea3-8cb3-0db9b5bcb8d9',
|
|
|
|
'2e3b616b-301f-437c-98ab-37352f444a60',
|
|
|
|
]
|
|
|
|
|
2014-01-14 20:47:13 +00:00
|
|
|
SAMPLE_CMDS = [["/bin/bash"],
|
2014-01-13 21:32:51 +00:00
|
|
|
["/bin/sh", "-c",
|
|
|
|
"echo \"PasswordAuthentication no\" >> /etc/ssh/sshd_config"],
|
|
|
|
["/bin/sh", "-c",
|
|
|
|
"sed -i 's/#\\(force_color_prompt\\)/\\1/' /etc/skel/.bashrc"],
|
2014-01-14 20:28:24 +00:00
|
|
|
["/bin/sh", "-c", "#(nop) EXPOSE [8080]"],
|
2014-01-14 20:47:13 +00:00
|
|
|
["/bin/sh", "-c",
|
|
|
|
"#(nop) MAINTAINER Jake Moshenko <jake@devtable.com>"],
|
2014-01-13 21:32:51 +00:00
|
|
|
None]
|
2013-10-18 20:36:11 +00:00
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
REFERENCE_DATE = datetime(2013, 6, 23)
|
2013-11-08 03:43:43 +00:00
|
|
|
TEST_STRIPE_ID = 'cus_2tmnh3PkXQS8NG'
|
2013-10-18 22:28:37 +00:00
|
|
|
|
2013-10-18 20:36:11 +00:00
|
|
|
def __gen_checksum(image_id):
|
|
|
|
h = hashlib.md5(image_id)
|
2013-10-19 00:35:14 +00:00
|
|
|
return 'tarsum+sha256:' + h.hexdigest() + h.hexdigest()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
def __gen_image_id(repo, image_num):
|
|
|
|
str_to_hash = "%s/%s/%s" % (repo.namespace, repo.name, image_num)
|
2013-10-18 20:36:11 +00:00
|
|
|
|
|
|
|
h = hashlib.md5(str_to_hash)
|
2013-10-19 00:35:14 +00:00
|
|
|
return h.hexdigest() + h.hexdigest()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
global_image_num = [0]
|
2014-02-16 22:38:47 +00:00
|
|
|
def __create_subtree(repo, structure, creator_username, parent):
|
2013-10-10 04:40:07 +00:00
|
|
|
num_nodes, subtrees, last_node_tags = structure
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
# create the nodes
|
|
|
|
for i in range(num_nodes):
|
2013-10-18 22:28:37 +00:00
|
|
|
image_num = global_image_num[0]
|
|
|
|
global_image_num[0] += 1
|
|
|
|
docker_image_id = __gen_image_id(repo, image_num)
|
2013-10-18 20:36:11 +00:00
|
|
|
logger.debug('new docker id: %s' % docker_image_id)
|
|
|
|
checksum = __gen_checksum(docker_image_id)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2014-02-25 21:31:52 +00:00
|
|
|
new_image = model.find_create_or_link_image(docker_image_id, repo, None,
|
|
|
|
{})
|
2014-02-17 20:17:39 +00:00
|
|
|
new_image.storage.uuid = IMAGE_UUIDS[image_num % len(IMAGE_UUIDS)]
|
|
|
|
new_image.storage.save()
|
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
model.set_image_checksum(docker_image_id, repo, checksum)
|
|
|
|
|
2013-10-18 22:28:37 +00:00
|
|
|
creation_time = REFERENCE_DATE + timedelta(days=image_num)
|
2014-01-13 21:32:51 +00:00
|
|
|
command_list = SAMPLE_CMDS[image_num % len(SAMPLE_CMDS)]
|
|
|
|
command = json.dumps(command_list) if command_list else None
|
2013-10-10 03:52:28 +00:00
|
|
|
new_image = model.set_image_metadata(docker_image_id, repo.namespace,
|
2013-10-18 22:28:37 +00:00
|
|
|
repo.name, str(creation_time),
|
2014-01-13 21:32:51 +00:00
|
|
|
'no comment', command, parent)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2014-01-13 21:32:51 +00:00
|
|
|
model.set_image_size(docker_image_id, repo.namespace, repo.name,
|
|
|
|
random.randrange(1, 1024 * 1024 * 1024))
|
2014-01-03 21:32:00 +00:00
|
|
|
|
2013-10-18 20:36:11 +00:00
|
|
|
# Populate the diff file
|
|
|
|
diff_path = store.image_file_diffs_path(repo.namespace, repo.name,
|
2014-02-16 22:38:47 +00:00
|
|
|
docker_image_id,
|
|
|
|
new_image.storage.uuid)
|
2013-10-18 22:28:37 +00:00
|
|
|
source_diff = SAMPLE_DIFFS[image_num % len(SAMPLE_DIFFS)]
|
2013-10-18 20:36:11 +00:00
|
|
|
|
|
|
|
with open(source_diff, 'r') as source_file:
|
|
|
|
store.stream_write(diff_path, source_file)
|
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
parent = new_image
|
|
|
|
|
2013-10-10 04:40:07 +00:00
|
|
|
if last_node_tags:
|
|
|
|
if not isinstance(last_node_tags, list):
|
|
|
|
last_node_tags = [last_node_tags]
|
|
|
|
|
|
|
|
for tag_name in last_node_tags:
|
|
|
|
model.create_or_update_tag(repo.namespace, repo.name, tag_name,
|
|
|
|
new_image.docker_image_id)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
for subtree in subtrees:
|
2014-02-16 22:38:47 +00:00
|
|
|
__create_subtree(repo, subtree, creator_username, new_image)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
|
2013-10-17 02:37:29 +00:00
|
|
|
def __generate_repository(user, name, description, is_public, permissions,
|
|
|
|
structure):
|
2013-10-10 03:52:28 +00:00
|
|
|
repo = model.create_repository(user.username, name, user)
|
|
|
|
|
|
|
|
if is_public:
|
|
|
|
model.set_repository_visibility(repo, 'public')
|
|
|
|
|
2013-10-12 01:28:02 +00:00
|
|
|
if description:
|
|
|
|
repo.description = description
|
|
|
|
repo.save()
|
|
|
|
|
2013-10-10 03:52:28 +00:00
|
|
|
for delegate, role in permissions:
|
|
|
|
model.set_user_repo_permission(delegate.username, user.username, name,
|
|
|
|
role)
|
|
|
|
|
2014-01-20 22:38:33 +00:00
|
|
|
if isinstance(structure, list):
|
|
|
|
for s in structure:
|
2014-02-16 22:38:47 +00:00
|
|
|
__create_subtree(repo, s, user.username, None)
|
2014-01-20 22:38:33 +00:00
|
|
|
else:
|
2014-02-16 22:38:47 +00:00
|
|
|
__create_subtree(repo, structure, user.username, None)
|
2013-10-10 03:52:28 +00:00
|
|
|
|
2013-10-25 19:47:34 +00:00
|
|
|
return repo
|
|
|
|
|
2014-01-31 01:57:40 +00:00
|
|
|
|
|
|
|
db_initialized_for_testing = False
|
|
|
|
testcases = {}
|
|
|
|
|
|
|
|
def finished_database_for_testing(testcase):
|
|
|
|
""" Called when a testcase has finished using the database, indicating that
|
|
|
|
any changes should be discarded.
|
|
|
|
"""
|
|
|
|
global testcases
|
|
|
|
testcases[testcase]['savepoint'].__exit__(True, None, None)
|
|
|
|
|
|
|
|
def setup_database_for_testing(testcase):
|
|
|
|
""" Called when a testcase has started using the database, indicating that
|
|
|
|
the database should be setup (if not already) and a savepoint created.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Sanity check to make sure we're not killing our prod db
|
|
|
|
db = model.db
|
2014-04-10 19:20:16 +00:00
|
|
|
if not isinstance(model.db, SqliteDatabase):
|
2014-01-31 01:57:40 +00:00
|
|
|
raise RuntimeError('Attempted to wipe production database!')
|
|
|
|
|
|
|
|
global db_initialized_for_testing
|
|
|
|
if not db_initialized_for_testing:
|
|
|
|
logger.debug('Setting up DB for testing.')
|
|
|
|
|
|
|
|
# Setup the database.
|
|
|
|
wipe_database()
|
|
|
|
initialize_database()
|
|
|
|
populate_database()
|
|
|
|
|
|
|
|
db_initialized_for_testing = True
|
|
|
|
|
|
|
|
# Create a savepoint for the testcase.
|
|
|
|
global testcases
|
|
|
|
testcases[testcase] = {}
|
|
|
|
testcases[testcase]['savepoint'] = savepoint_sqlite(db)
|
|
|
|
testcases[testcase]['savepoint'].__enter__()
|
2013-10-01 18:14:39 +00:00
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
def initialize_database():
|
|
|
|
create_model_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='github')
|
2013-11-20 21:13:03 +00:00
|
|
|
LoginService.create(name='quayrobot')
|
2014-02-18 20:50:15 +00:00
|
|
|
|
|
|
|
BuildTriggerService.create(name='github')
|
2013-11-27 07:29:31 +00:00
|
|
|
|
|
|
|
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')
|
2014-02-28 05:12:09 +00:00
|
|
|
LogEntryKind.create(name='create_tag')
|
|
|
|
LogEntryKind.create(name='move_tag')
|
2014-01-06 20:20:58 +00:00
|
|
|
LogEntryKind.create(name='delete_tag')
|
2013-11-27 07:29:31 +00:00
|
|
|
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='add_repo_accesstoken')
|
|
|
|
LogEntryKind.create(name='delete_repo_accesstoken')
|
|
|
|
LogEntryKind.create(name='add_repo_webhook')
|
|
|
|
LogEntryKind.create(name='delete_repo_webhook')
|
|
|
|
LogEntryKind.create(name='set_repo_description')
|
2014-02-25 19:11:20 +00:00
|
|
|
|
2013-11-27 07:29:31 +00:00
|
|
|
LogEntryKind.create(name='build_dockerfile')
|
|
|
|
|
|
|
|
LogEntryKind.create(name='org_create_team')
|
|
|
|
LogEntryKind.create(name='org_delete_team')
|
|
|
|
LogEntryKind.create(name='org_add_team_member')
|
|
|
|
LogEntryKind.create(name='org_remove_team_member')
|
|
|
|
LogEntryKind.create(name='org_set_team_description')
|
|
|
|
LogEntryKind.create(name='org_set_team_role')
|
2014-01-21 19:18:20 +00:00
|
|
|
|
2014-01-21 22:04:00 +00:00
|
|
|
LogEntryKind.create(name='create_prototype_permission')
|
|
|
|
LogEntryKind.create(name='modify_prototype_permission')
|
|
|
|
LogEntryKind.create(name='delete_prototype_permission')
|
2013-11-27 07:29:31 +00:00
|
|
|
|
2014-02-25 19:11:20 +00:00
|
|
|
LogEntryKind.create(name='setup_repo_trigger')
|
2014-02-18 20:50:15 +00:00
|
|
|
LogEntryKind.create(name='delete_repo_trigger')
|
|
|
|
|
2014-03-20 19:46:13 +00:00
|
|
|
LogEntryKind.create(name='create_application')
|
|
|
|
LogEntryKind.create(name='update_application')
|
|
|
|
LogEntryKind.create(name='delete_application')
|
|
|
|
LogEntryKind.create(name='reset_application_client_secret')
|
|
|
|
|
2014-03-12 04:49:03 +00:00
|
|
|
NotificationKind.create(name='password_required')
|
|
|
|
NotificationKind.create(name='over_private_usage')
|
|
|
|
|
|
|
|
NotificationKind.create(name='test_notification')
|
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
def wipe_database():
|
|
|
|
logger.debug('Wiping all data from the DB.')
|
|
|
|
|
|
|
|
# Sanity check to make sure we're not killing our prod db
|
|
|
|
db = model.db
|
2014-04-10 19:20:16 +00:00
|
|
|
if not isinstance(model.db, SqliteDatabase):
|
2013-11-06 22:09:22 +00:00
|
|
|
raise RuntimeError('Attempted to wipe production database!')
|
|
|
|
|
|
|
|
drop_model_tables(all_models, fail_silently=True)
|
|
|
|
|
|
|
|
|
|
|
|
def populate_database():
|
|
|
|
logger.debug('Populating the DB with test data.')
|
|
|
|
|
|
|
|
new_user_1 = model.create_user('devtable', 'password',
|
|
|
|
'jschorr@devtable.com')
|
|
|
|
new_user_1.verified = True
|
2014-01-10 17:39:23 +00:00
|
|
|
new_user_1.stripe_id = TEST_STRIPE_ID
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_1.save()
|
|
|
|
|
2014-03-27 22:33:13 +00:00
|
|
|
dtrobot = model.create_robot('dtrobot', new_user_1)
|
2013-11-20 23:23:59 +00:00
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_2 = model.create_user('public', 'password',
|
|
|
|
'jacob.moshenko@gmail.com')
|
|
|
|
new_user_2.verified = True
|
|
|
|
new_user_2.save()
|
|
|
|
|
|
|
|
new_user_3 = model.create_user('freshuser', 'password', 'no@thanks.com')
|
|
|
|
new_user_3.verified = True
|
|
|
|
new_user_3.save()
|
|
|
|
|
2014-03-27 22:33:13 +00:00
|
|
|
model.create_robot('anotherrobot', new_user_3)
|
|
|
|
|
2014-02-18 21:46:10 +00:00
|
|
|
new_user_4 = model.create_user('randomuser', 'password', 'no4@thanks.com')
|
|
|
|
new_user_4.verified = True
|
|
|
|
new_user_4.save()
|
|
|
|
|
2014-03-12 20:05:32 +00:00
|
|
|
new_user_5 = model.create_user('unverified', 'password', 'no5@thanks.com')
|
|
|
|
new_user_5.save()
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
reader = model.create_user('reader', 'password', 'no1@thanks.com')
|
|
|
|
reader.verified = True
|
|
|
|
reader.save()
|
|
|
|
|
2013-11-08 04:29:58 +00:00
|
|
|
outside_org = model.create_user('outsideorg', 'password', 'no2@thanks.com')
|
|
|
|
outside_org.verified = True
|
|
|
|
outside_org.save()
|
|
|
|
|
2014-03-12 04:49:03 +00:00
|
|
|
model.create_notification('test_notification', new_user_1, metadata={'some': 'value'})
|
|
|
|
|
2014-02-18 21:46:10 +00:00
|
|
|
__generate_repository(new_user_4, 'randomrepo', 'Random repo repository.', False,
|
|
|
|
[], (4, [], ['latest', 'prod']))
|
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
__generate_repository(new_user_1, 'simple', 'Simple repository.', False,
|
|
|
|
[], (4, [], ['latest', 'prod']))
|
|
|
|
|
|
|
|
__generate_repository(new_user_1, 'complex',
|
|
|
|
'Complex repository with many branches and tags.',
|
2014-04-03 03:33:58 +00:00
|
|
|
False, [(new_user_2, 'read'), (dtrobot[0], 'read')],
|
2013-11-06 22:09:22 +00:00
|
|
|
(2, [(3, [], 'v2.0'),
|
|
|
|
(1, [(1, [(1, [], ['prod'])],
|
|
|
|
'staging'),
|
|
|
|
(1, [], None)], None)], None))
|
|
|
|
|
|
|
|
__generate_repository(new_user_1, 'gargantuan', None, False, [],
|
|
|
|
(2, [(3, [], 'v2.0'),
|
|
|
|
(1, [(1, [(1, [], ['latest', 'prod'])],
|
|
|
|
'staging'),
|
|
|
|
(1, [], None)], None),
|
|
|
|
(20, [], 'v3.0'),
|
|
|
|
(5, [], 'v4.0'),
|
|
|
|
(1, [(1, [], 'v5.0'), (1, [], 'v6.0')], None)],
|
|
|
|
None))
|
2014-01-20 22:38:33 +00:00
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
__generate_repository(new_user_2, 'publicrepo',
|
|
|
|
'Public repository pullable by the world.', True,
|
|
|
|
[], (10, [], 'latest'))
|
|
|
|
|
2014-02-18 21:46:10 +00:00
|
|
|
__generate_repository(outside_org, 'coolrepo',
|
|
|
|
'Some cool repo.', False,
|
|
|
|
[],
|
|
|
|
(5, [], 'latest'))
|
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
__generate_repository(new_user_1, 'shared',
|
|
|
|
'Shared repository, another user can write.', False,
|
2013-11-07 04:21:12 +00:00
|
|
|
[(new_user_2, 'write'), (reader, 'read')],
|
|
|
|
(5, [], 'latest'))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
building = __generate_repository(new_user_1, 'building',
|
|
|
|
'Empty repository which is building.',
|
|
|
|
False, [], (0, [], None))
|
|
|
|
|
2014-02-06 01:01:23 +00:00
|
|
|
token = model.create_access_token(building, 'write')
|
2014-02-19 21:08:33 +00:00
|
|
|
|
|
|
|
trigger = model.create_build_trigger(building, 'github', '123authtoken',
|
2014-04-02 01:49:06 +00:00
|
|
|
new_user_1, pull_robot=dtrobot[0])
|
2014-02-19 21:08:33 +00:00
|
|
|
trigger.config = json.dumps({
|
|
|
|
'build_source': 'jakedt/testconnect',
|
2014-02-24 21:18:14 +00:00
|
|
|
'subdir': '',
|
2014-02-19 21:08:33 +00:00
|
|
|
})
|
|
|
|
trigger.save()
|
|
|
|
|
2014-02-24 21:11:23 +00:00
|
|
|
repo = 'ci.devtable.com:5000/%s/%s' % (building.namespace, building.name)
|
|
|
|
job_config = {
|
|
|
|
'repository': repo,
|
|
|
|
'docker_tags': ['latest'],
|
|
|
|
'build_subdir': '',
|
|
|
|
}
|
|
|
|
build = model.create_repository_build(building, token, job_config,
|
2014-03-05 20:50:32 +00:00
|
|
|
'701dcc3724fb4f2ea6c31400528343cd',
|
2014-02-24 21:11:23 +00:00
|
|
|
'build-name', trigger)
|
2014-02-06 01:01:23 +00:00
|
|
|
build.uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
|
|
|
build.save()
|
|
|
|
|
2014-04-01 04:23:53 +00:00
|
|
|
build2 = model.create_repository_build(building, token, job_config,
|
|
|
|
'68daeebd-a5b9-457f-80a0-4363b882f8ea',
|
|
|
|
'build-name', trigger)
|
|
|
|
build2.uuid = 'deadpork-dead-pork-dead-porkdeadpork'
|
|
|
|
build2.save()
|
|
|
|
|
2014-04-01 17:00:26 +00:00
|
|
|
build3 = model.create_repository_build(building, token, job_config,
|
|
|
|
'f49d07f9-93da-474d-ad5f-c852107c3892',
|
|
|
|
'build-name', trigger)
|
|
|
|
build3.uuid = 'deadduck-dead-duck-dead-duckdeadduck'
|
|
|
|
build3.save()
|
|
|
|
|
2013-11-08 03:43:43 +00:00
|
|
|
org = model.create_organization('buynlarge', 'quay@devtable.com',
|
2013-11-06 22:09:22 +00:00
|
|
|
new_user_1)
|
2013-11-08 03:43:43 +00:00
|
|
|
org.stripe_id = TEST_STRIPE_ID
|
|
|
|
org.save()
|
|
|
|
|
2014-03-27 22:33:13 +00:00
|
|
|
model.create_robot('coolrobot', org)
|
|
|
|
|
2014-03-14 22:57:28 +00:00
|
|
|
oauth.create_application(org, 'Some Test App', 'http://localhost:8000', 'http://localhost:8000/o2c.html',
|
|
|
|
client_id='deadbeef')
|
|
|
|
|
|
|
|
oauth.create_application(org, 'Some Other Test App', 'http://quay.io', 'http://localhost:8000/o2c.html',
|
|
|
|
client_id='deadpork',
|
|
|
|
description = 'This is another test application')
|
2014-03-12 16:37:06 +00:00
|
|
|
|
2014-03-25 00:57:02 +00:00
|
|
|
model.oauth.create_access_token_for_testing(new_user_1, 'deadbeef', 'repo:admin')
|
|
|
|
|
2013-11-20 23:23:59 +00:00
|
|
|
model.create_robot('neworgrobot', org)
|
|
|
|
|
2013-11-08 03:43:43 +00:00
|
|
|
owners = model.get_organization_team('buynlarge', 'owners')
|
|
|
|
owners.description = 'Owners have unfetterd access across the entire org.'
|
|
|
|
owners.save()
|
2013-11-06 22:09:22 +00:00
|
|
|
|
|
|
|
org_repo = __generate_repository(org, 'orgrepo',
|
|
|
|
'Repository owned by an org.', False,
|
2013-11-08 04:29:58 +00:00
|
|
|
[(outside_org, 'read')],
|
|
|
|
(4, [], ['latest', 'prod']))
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2014-02-18 21:46:10 +00:00
|
|
|
org_repo2 = __generate_repository(org, 'anotherorgrepo',
|
|
|
|
'Another repository owned by an org.', False,
|
|
|
|
[],
|
|
|
|
(4, [], ['latest', 'prod']))
|
|
|
|
|
2013-11-06 22:09:22 +00:00
|
|
|
reader_team = model.create_team('readers', org, 'member',
|
|
|
|
'Readers of orgrepo.')
|
|
|
|
model.set_team_repo_permission(reader_team.name, org_repo.namespace,
|
|
|
|
org_repo.name, 'read')
|
|
|
|
model.add_user_to_team(new_user_2, reader_team)
|
2013-11-07 04:21:12 +00:00
|
|
|
model.add_user_to_team(reader, reader_team)
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2014-01-20 22:48:25 +00:00
|
|
|
__generate_repository(new_user_1, 'superwide', None, False, [],
|
|
|
|
[(10, [], 'latest2'),
|
|
|
|
(2, [], 'latest3'),
|
2014-02-06 01:01:23 +00:00
|
|
|
(2, [(1, [], 'latest11'), (2, [], 'latest12')],
|
|
|
|
'latest4'),
|
2014-01-20 22:48:25 +00:00
|
|
|
(2, [], 'latest5'),
|
|
|
|
(2, [], 'latest6'),
|
|
|
|
(2, [], 'latest7'),
|
|
|
|
(2, [], 'latest8'),
|
|
|
|
(2, [], 'latest9'),
|
|
|
|
(2, [], 'latest10'),
|
|
|
|
(2, [], 'latest13'),
|
|
|
|
(2, [], 'latest14'),
|
|
|
|
(2, [], 'latest15'),
|
|
|
|
(2, [], 'latest16'),
|
|
|
|
(2, [], 'latest17'),
|
|
|
|
(2, [], 'latest18'),])
|
|
|
|
|
2014-01-21 22:13:11 +00:00
|
|
|
model.add_prototype_permission(org, 'read', activating_user=new_user_1,
|
|
|
|
delegate_user=new_user_2)
|
|
|
|
model.add_prototype_permission(org, 'read', activating_user=new_user_1,
|
|
|
|
delegate_team=reader_team)
|
|
|
|
model.add_prototype_permission(org, 'write', activating_user=new_user_2,
|
|
|
|
delegate_user=new_user_1)
|
2014-01-21 19:18:20 +00:00
|
|
|
|
2013-12-03 00:07:14 +00:00
|
|
|
today = datetime.today()
|
|
|
|
week_ago = today - timedelta(6)
|
|
|
|
six_ago = today - timedelta(5)
|
|
|
|
four_ago = today - timedelta(4)
|
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('org_create_team', org.username, performer=new_user_1,
|
|
|
|
timestamp=week_ago, metadata={'team': 'readers'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('org_set_team_role', org.username, performer=new_user_1,
|
|
|
|
timestamp=week_ago,
|
2013-12-03 00:07:14 +00:00
|
|
|
metadata={'team': 'readers', 'role': 'read'})
|
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('create_repo', org.username, performer=new_user_1,
|
|
|
|
repository=org_repo, timestamp=week_ago,
|
2013-12-03 03:29:54 +00:00
|
|
|
metadata={'namespace': org.username, 'repo': 'orgrepo'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('change_repo_permission', org.username,
|
|
|
|
performer=new_user_2, repository=org_repo,
|
|
|
|
timestamp=six_ago,
|
|
|
|
metadata={'username': new_user_1.username,
|
|
|
|
'repo': 'orgrepo', 'role': 'admin'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('change_repo_permission', org.username,
|
|
|
|
performer=new_user_1, repository=org_repo,
|
|
|
|
timestamp=six_ago,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo', 'role': 'read'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('add_repo_accesstoken', org.username, performer=new_user_1,
|
|
|
|
repository=org_repo, timestamp=four_ago,
|
2013-12-03 00:07:14 +00:00
|
|
|
metadata={'repo': 'orgrepo', 'token': 'deploytoken'})
|
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('push_repo', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('pull_repo', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo'})
|
2013-12-03 00:07:14 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('pull_repo', org.username, repository=org_repo,
|
|
|
|
timestamp=today,
|
|
|
|
metadata={'token': 'sometoken', 'token_code': 'somecode',
|
|
|
|
'repo': 'orgrepo'})
|
2013-11-06 22:09:22 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('delete_tag', org.username, performer=new_user_2,
|
|
|
|
repository=org_repo, timestamp=today,
|
|
|
|
metadata={'username': new_user_2.username,
|
|
|
|
'repo': 'orgrepo', 'tag': 'sometag'})
|
2014-01-06 20:20:58 +00:00
|
|
|
|
2014-01-21 00:05:26 +00:00
|
|
|
model.log_action('pull_repo', org.username, repository=org_repo,
|
|
|
|
timestamp=today,
|
2014-01-08 23:44:50 +00:00
|
|
|
metadata={'token_code': 'somecode', 'repo': 'orgrepo'})
|
|
|
|
|
2014-02-25 23:22:55 +00:00
|
|
|
model.log_action('build_dockerfile', new_user_1.username, repository=building,
|
|
|
|
timestamp=today,
|
|
|
|
metadata={'repo': 'building', 'namespace': new_user_1.username,
|
|
|
|
'trigger_id': trigger.uuid, 'config': json.loads(trigger.config),
|
|
|
|
'service': trigger.service.name})
|
|
|
|
|
2013-10-01 18:14:39 +00:00
|
|
|
if __name__ == '__main__':
|
2014-05-01 23:44:28 +00:00
|
|
|
log_level = getattr(logging, app.config['LOGGING_LEVEL'])
|
|
|
|
logging.basicConfig(level=log_level)
|
2013-11-06 22:09:22 +00:00
|
|
|
initialize_database()
|
2013-10-10 03:52:28 +00:00
|
|
|
|
|
|
|
if app.config.get('POPULATE_DB_TEST_DATA', False):
|
2013-11-06 22:09:22 +00:00
|
|
|
populate_database()
|