Ejemplo n.º 1
0
def delete_inbound_repo(name):
    """Deletes inbound repo and distro in case of namespace deletion."""
    inbound_name = INBOUND_REPO_NAME_FORMAT.format(namespace_name=name)
    with contextlib.suppress(AnsibleRepository.DoesNotExist):
        AnsibleRepository.objects.get(name=inbound_name).delete()
    with contextlib.suppress(AnsibleDistribution.DoesNotExist):
        AnsibleDistribution.objects.get(name=inbound_name).delete()
Ejemplo n.º 2
0
 def _get_path(kwargs, filename_ns):
     """Use path from '/content/<path>/v3/' or
        if user does not specify distribution base path
        then use an inbound distribution based on filename namespace.
     """
     path = kwargs['path']
     if kwargs.get('no_path_specified', None):
         path = INBOUND_REPO_NAME_FORMAT.format(namespace_name=filename_ns)
     return path
Ejemplo n.º 3
0
def create_inbound_repo(name):
    """Creates inbound repo and inbound distribution for namespace publication."""
    inbound_name = INBOUND_REPO_NAME_FORMAT.format(namespace_name=name)
    with contextlib.suppress(IntegrityError):
        # IntegrityError is suppressed for when the named repo/distro already exists
        # In that cases the error handling is performed on the caller.
        repo = AnsibleRepository.objects.create(name=inbound_name)
        AnsibleDistribution.objects.create(
            name=inbound_name,
            base_path=inbound_name,
            repository=repo
        )
Ejemplo n.º 4
0
 def test_new_namespace_creates_inbound_repo(self):
     """When creating a new Namespace the manager should create inbound instances."""
     self.assertFalse(Namespace.objects.filter(name=self.namespace_name))
     Namespace.objects.create(name=self.namespace_name)
     self.assertTrue(
         Namespace.objects.filter(name=self.namespace_name).exists())
     inbound_name = INBOUND_REPO_NAME_FORMAT.format(
         namespace_name=self.namespace_name)
     self.assertTrue(
         AnsibleRepository.objects.filter(name=inbound_name).exists())
     self.assertTrue(
         AnsibleDistribution.objects.filter(name=inbound_name).exists())
Ejemplo n.º 5
0
    def test_delete_namespace_deletes_inbound_repo(self):
        """When deleting a Namespace the manager should delete inbound instances."""
        Namespace.objects.get_or_create(name=self.namespace_name)
        Namespace.objects.filter(name=self.namespace_name).delete()

        inbound_name = INBOUND_REPO_NAME_FORMAT.format(
            namespace_name=self.namespace_name)
        self.assertFalse(
            Namespace.objects.filter(name=self.namespace_name).exists())
        self.assertFalse(
            AnsibleRepository.objects.filter(name=inbound_name).exists())
        self.assertFalse(
            AnsibleDistribution.objects.filter(name=inbound_name).exists())
Ejemplo n.º 6
0
    def test_namespace_api_creates_deletes_inbound_repo(self):
        self.client.force_authenticate(user=self.admin_user)
        ns1_name = "unittestnamespace1"
        repo_name = INBOUND_REPO_NAME_FORMAT.format(namespace_name=ns1_name)

        with self.settings(GALAXY_DEPLOYMENT_MODE=self.deployment_mode):
            # Create namespace + repo
            response = self.client.post(
                self.ns_url,
                {
                    "name":
                    ns1_name,
                    "groups": [
                        {
                            "id":
                            self.pe_group.id,
                            "name":
                            self.pe_group.name,
                            "object_permissions": [
                                'galaxy.upload_to_namespace',
                                'galaxy.change_namespace'
                            ]
                        },
                    ],
                },
                format='json',
            )
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)
            self.assertEqual(
                1, len(AnsibleRepository.objects.filter(name=repo_name)))
            self.assertEqual(
                1, len(AnsibleDistribution.objects.filter(name=repo_name)))

            # List namespace
            response = self.client.get(self.ns_url)
            self.assertEqual(response.status_code, status.HTTP_200_OK)
            namespaces = [item['name'] for item in response.data['data']]
            self.assertIn(ns1_name, namespaces)
            self.assertEqual(1, len(Namespace.objects.filter(name=ns1_name)))

            # Delete namespace + repo
            ns_detail_url = reverse('galaxy:api:v3:namespaces-detail',
                                    kwargs={"name": ns1_name})
            response = self.client.delete(ns_detail_url)

            # Namespace deletion is currently disabled via access policy. If we re-enable it
            # we can re-enable these tests
            self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 7
0
    def _check_path_matches_expected_repo(path, filename_ns):
        """Reject if path does not match expected inbound format
           containing filename namespace.

        Examples:
        Reject if path is "staging".
        Reject if path does not start with "inbound-".
        Reject if path is "inbound-alice" but filename namepace is "bob".
        """

        distro = get_object_or_404(AnsibleDistribution, base_path=path)
        repo_name = distro.repository.name
        if INBOUND_REPO_NAME_FORMAT.format(namespace_name=filename_ns) == repo_name:
            return
        raise NotFound(
            f'Path does not match: "{INBOUND_REPO_NAME_FORMAT.format(namespace_name=filename_ns)}"')