Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Community cleanup #2308

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 0 additions & 145 deletions galaxy_ng/app/api/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
import tempfile
import uuid

from django.db import transaction

from ansible.module_utils.compat.version import LooseVersion

from galaxy_importer.config import Config
from galaxy_importer.legacy_role import import_legacy_role

from galaxy_ng.app.models.auth import User
from galaxy_ng.app.models import Namespace
from galaxy_ng.app.utils.galaxy import upstream_role_iterator
from galaxy_ng.app.utils.legacy import process_namespace
from galaxy_ng.app.utils.namespaces import generate_v3_namespace_from_attributes
from galaxy_ng.app.utils.rbac import get_v3_namespace_owners

from galaxy_ng.app.api.v1.models import LegacyNamespace
from galaxy_ng.app.api.v1.models import LegacyRole
from galaxy_ng.app.api.v1.models import LegacyRoleDownloadCount
from galaxy_ng.app.api.v1.models import LegacyRoleImport
from galaxy_ng.app.api.v1.utils import sort_versions
from galaxy_ng.app.api.v1.utils import parse_version_tag
Expand Down Expand Up @@ -557,143 +552,3 @@ def legacy_role_import(
logger.info('')
logger.info('Import completed')
return this_role


def legacy_sync_from_upstream(
baseurl=None,
github_user=None,
role_name=None,
role_version=None,
limit=None,
start_page=None,
):
"""
Sync legacy roles from a remote v1 api.

:param baseurl:
Allow the client to override the upstream v1 url this task will sync from.
:param github_user:
Allow the client to reduce the set of synced roles by the username.
:param role_name:
Allow the client to reduce the set of synced roles by the role name.
:param limit:
Allow the client to reduce the total number of synced roles.

This is conceptually similar to the pulp_ansible/app/tasks/roles.py:synchronize
function but has more robust handling and better schema matching. Although
not considered something we'd be normally running on a production hosted
galaxy instance, it is necessary for mirroring the roles into that future
system until it is ready to deprecate the old instance.
"""

logger.debug(
'STARTING LEGACY SYNC!'
+ f' {baseurl} {github_user} {role_name} {role_version} {limit}'
)

logger.debug('SYNC INDEX EXISTING NAMESPACES')
nsmap = {}

# allow the user to specify how many roles to sync
if limit is not None:
limit = int(limit)

# index of all roles
rmap = {}

iterator_kwargs = {
'baseurl': baseurl,
'github_user': github_user,
'role_name': role_name,
'limit': limit,
'start_page': start_page,
}
for ns_data, rdata, rversions in upstream_role_iterator(**iterator_kwargs):

# processing a namespace should make owners and set rbac as needed ...
if ns_data['name'] not in nsmap:
namespace, v3_namespace = process_namespace(ns_data['name'], ns_data)
nsmap[ns_data['name']] = (namespace, v3_namespace)
else:
namespace, v3_namespace = nsmap[ns_data['name']]

github_user = rdata.get('github_user')
role_name = rdata.get('name')

logger.info(f'POPULATE {github_user}.{role_name}')

rkey = (github_user, role_name)
remote_id = rdata['id']
role_versions = rversions[:]
github_repo = rdata['github_repo']
github_branch = rdata['github_branch']
clone_url = f'https://github.com/{github_user}/{github_repo}'
sfields = rdata.get('summary_fields', {})
role_tags = sfields.get('tags', [])
commit_hash = rdata.get('commit')
commit_msg = rdata.get('commit_message')
commit_url = rdata.get('commit_url')
issue_tracker = rdata.get('issue_tracker_url', clone_url + '/issues')
role_description = rdata.get('description')
role_license = rdata.get('license')
role_readme = rdata.get('readme')
role_html = rdata.get('readme_html')
role_dependencies = sfields.get('dependencies', [])
role_min_ansible = rdata.get('min_ansible_version')
role_company = rdata.get('company')
role_imported = rdata.get('imported', datetime.datetime.now().isoformat())
role_created = rdata.get('created', datetime.datetime.now().isoformat())
role_modified = rdata.get('modified', datetime.datetime.now().isoformat())
role_type = rdata.get('role_type', 'ANS')
role_download_count = rdata.get('download_count', 0)

if rkey not in rmap:
logger.debug(f'SYNC create initial role for {rkey}')
this_role, _ = LegacyRole.objects.get_or_create(
namespace=namespace,
name=role_name
)
rmap[rkey] = this_role
else:
this_role = rmap[rkey]

new_full_metadata = {
'upstream_id': remote_id,
'role_type': role_type,
'imported': role_imported,
'created': role_created,
'modified': role_modified,
'clone_url': clone_url,
'tags': role_tags,
'commit': commit_hash,
'commit_message': commit_msg,
'commit_url': commit_url,
'github_user': github_user,
'github_repo': github_repo,
'github_branch': github_branch,
# 'github_reference': github_reference,
'issue_tracker_url': issue_tracker,
'dependencies': role_dependencies,
'versions': role_versions,
'description': role_description,
'license': role_license,
'readme': role_readme,
'readme_html': role_html,
'min_ansible_version': role_min_ansible,
'company': role_company,
}

new_full_metadata['versions'] = normalize_versions(new_full_metadata['versions'])
new_full_metadata['versions'] = sort_versions(new_full_metadata['versions'])

if dict(this_role.full_metadata) != new_full_metadata:
with transaction.atomic():
this_role.full_metadata = new_full_metadata
this_role.save()

with transaction.atomic():
counter, _ = LegacyRoleDownloadCount.objects.get_or_create(legacyrole=this_role)
counter.count = role_download_count
counter.save()

logger.debug('STOP LEGACY SYNC!')
14 changes: 0 additions & 14 deletions galaxy_ng/app/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from galaxy_ng.app.api.v1.views import LegacyRootView
from galaxy_ng.app.api.v1.viewsets import (
# LegacyRoleViewSet,
LegacyRoleImportsViewSet,
LegacyRoleContentViewSet,
LegacyRoleVersionsViewSet,
LegacyRolesViewSet,
LegacyRolesSyncViewSet,
LegacyNamespacesViewSet,
LegacyNamespaceOwnersViewSet,
LegacyNamespaceProvidersViewSet,
Expand Down Expand Up @@ -67,18 +65,6 @@
name='legacy_role-search'
),

path(
'sync/',
LegacyRolesSyncViewSet.as_view({"post": "create"}),
name='legacy_role-sync'
),

path(
'sync/<int:id>/',
LegacyRolesSyncViewSet.as_view({"get": "get_task"}),
name='legacy_role-sync-task'
),

path(
'tasks/<int:id>/',
LegacyRoleImportsViewSet.as_view({"get": "get_task"}),
Expand Down
5 changes: 0 additions & 5 deletions galaxy_ng/app/api/v1/viewsets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
LegacyRoleImportsViewSet
)

from .sync import (
LegacyRolesSyncViewSet,
)


__all__ = (
"LegacyNamespacesViewSet",
"LegacyNamespaceOwnersViewSet",
"LegacyNamespaceProvidersViewSet",
"LegacyUsersViewSet",
"LegacyRolesViewSet",
"LegacyRolesSyncViewSet",
"LegacyRoleContentViewSet",
"LegacyRoleVersionsViewSet",
"LegacyRoleImportsViewSet",
Expand Down
47 changes: 0 additions & 47 deletions galaxy_ng/app/api/v1/viewsets/sync.py

This file was deleted.

46 changes: 0 additions & 46 deletions galaxy_ng/app/management/commands/import-galaxy-role.py

This file was deleted.

Loading
Loading