pulp-ansible 0.28.2__py3-none-any.whl → 0.28.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,6 @@ class PulpAnsiblePluginAppConfig(PulpPluginAppConfig):
8
8
 
9
9
  name = "pulp_ansible.app"
10
10
  label = "ansible"
11
- version = "0.28.2"
11
+ version = "0.28.4"
12
12
  python_package_name = "pulp-ansible"
13
13
  domain_compatible = True
@@ -2,6 +2,7 @@ from datetime import datetime
2
2
  from gettext import gettext as _
3
3
  import semantic_version
4
4
  import base64
5
+ import re
5
6
 
6
7
  from django.db import DatabaseError, IntegrityError
7
8
  from django.db.models import F, OuterRef, Exists, Subquery, Prefetch
@@ -633,7 +634,7 @@ class CollectionArtifactDownloadView(GalaxyAuthMixin, views.APIView, AnsibleDist
633
634
  DEFAULT_ACCESS_POLICY = _PERMISSIVE_ACCESS_POLICY
634
635
 
635
636
  @staticmethod
636
- def log_download(request, filename, distro_base_path):
637
+ def log_download(request, namespace, name, version, distro_base_path):
637
638
  """Log the download of the collection version."""
638
639
 
639
640
  def _get_org_id(request):
@@ -651,7 +652,7 @@ class CollectionArtifactDownloadView(GalaxyAuthMixin, views.APIView, AnsibleDist
651
652
 
652
653
  return identity["internal"]["org_id"]
653
654
 
654
- # Gettung user IP
655
+ # Get user IP
655
656
  x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
656
657
  ip = x_forwarded_for.split(",")[0] if x_forwarded_for else request.META.get("REMOTE_ADDR")
657
658
 
@@ -662,13 +663,9 @@ class CollectionArtifactDownloadView(GalaxyAuthMixin, views.APIView, AnsibleDist
662
663
  distribution.repository_version or distribution.repository.latest_version()
663
664
  )
664
665
 
665
- # Getting collection version
666
- ns, name, version = filename.split("-", maxsplit=2)
667
- # Get off the ending .tar.gz
668
- version = ".".join(version.split(".")[:3])
669
666
  collection_version = get_object_or_404(
670
667
  CollectionVersion.objects.filter(pk__in=repository_version.content),
671
- namespace=ns,
668
+ namespace=namespace,
672
669
  name=name,
673
670
  version=version,
674
671
  )
@@ -693,11 +690,10 @@ class CollectionArtifactDownloadView(GalaxyAuthMixin, views.APIView, AnsibleDist
693
690
  return
694
691
  raise
695
692
 
696
- def count_download(filename):
697
- ns, name, _ = filename.split("-", maxsplit=2)
693
+ def count_download(namespace, name):
698
694
  try:
699
695
  collection, created = CollectionDownloadCount.objects.get_or_create(
700
- namespace=ns, name=name, defaults={"download_count": 1}
696
+ namespace=namespace, name=name, defaults={"download_count": 1}
701
697
  )
702
698
  if not created:
703
699
  collection.download_count = F("download_count") + 1
@@ -728,13 +724,23 @@ class CollectionArtifactDownloadView(GalaxyAuthMixin, views.APIView, AnsibleDist
728
724
  filename=self.kwargs["filename"],
729
725
  )
730
726
 
727
+ match = re.fullmatch(
728
+ r"(?P<namespace>\w+)-(?P<name>\w+)-(?P<version>[\w.-]+)\.tar\.gz",
729
+ self.kwargs["filename"],
730
+ )
731
+ if not match:
732
+ raise NotFound()
733
+ namespace = match.group("namespace")
734
+ name = match.group("name")
735
+ version = match.group("version")
736
+
731
737
  if settings.ANSIBLE_COLLECT_DOWNLOAD_LOG:
732
738
  CollectionArtifactDownloadView.log_download(
733
- request, self.kwargs["filename"], distro_base_path
739
+ request, namespace, name, version, distro_base_path
734
740
  )
735
741
 
736
742
  if settings.ANSIBLE_COLLECT_DOWNLOAD_COUNT:
737
- CollectionArtifactDownloadView.count_download(self.kwargs["filename"])
743
+ CollectionArtifactDownloadView.count_download(namespace, name)
738
744
 
739
745
  if (
740
746
  distribution.content_guard
@@ -665,6 +665,22 @@ class CollectionVersionSerializer(ContentChecksumSerializer, CollectionVersionUp
665
665
 
666
666
  creating = True
667
667
 
668
+ def __init__(self, *args, **kwargs):
669
+ super().__init__(*args, **kwargs)
670
+ try:
671
+ request = self.context["request"]
672
+ if request.method != "GET":
673
+ return
674
+ except (AttributeError, TypeError, KeyError):
675
+ # The serializer was not initialized with request context.
676
+ return
677
+ query_params = request.query_params
678
+ if self.include_arg_name in query_params or self.exclude_arg_name in query_params:
679
+ return
680
+ for fieldname in ["files", "manifest", "docs_blob", "contents"]:
681
+ # Redact these fields by default as they have no size limit.
682
+ self.fields.pop(fieldname)
683
+
668
684
  def validate(self, data):
669
685
  """Run super() validate if creating, else return data."""
670
686
  # This validation is for creating CollectionVersions
@@ -125,6 +125,13 @@ def collection_detail(http_session, collection_upload, pulp_dist, collection_art
125
125
  return response.json()
126
126
 
127
127
 
128
+ @pytest.fixture(scope="class")
129
+ def collection_highest_version(http_session, collection_detail):
130
+ response = http_session.get(collection_detail["highest_version"]["href"])
131
+ response.raise_for_status()
132
+ return response.json()
133
+
134
+
128
135
  @pytest.fixture(scope="class")
129
136
  def pulp_dist(ansible_repository_factory, ansible_distribution_factory):
130
137
  """Create an Ansible Distribution to simulate the automation hub environment for testing."""
@@ -298,34 +305,52 @@ class TestCollection:
298
305
  # # 'repository': 'http://github.example.com/orionuser1/skeleton',
299
306
  # # 'tags': ['collectiontest']},
300
307
 
301
- def test_collection_download(
308
+ def test_collection_download_metadata_unauthorized_fails(
302
309
  self,
303
310
  http_session,
304
311
  collection_detail,
305
- collection_artifact,
306
312
  ):
307
- """Test collection download URL.
308
-
309
- Should require authentication and redirect to a download location.
310
- """
311
313
  response = http_session.get(collection_detail["highest_version"]["href"], auth=NullAuth())
312
314
  assert response.status_code == 401
313
- response = http_session.get(collection_detail["highest_version"]["href"])
314
- response.raise_for_status()
315
- version = response.json()
316
315
 
316
+ def test_collection_download_redirects(
317
+ self,
318
+ http_session,
319
+ collection_highest_version,
320
+ collection_artifact,
321
+ ):
317
322
  # Artifact Download Endoint
318
- url = version["download_url"]
323
+ url = collection_highest_version["download_url"]
319
324
 
320
325
  with open(collection_artifact.filename, "rb") as fp:
321
326
  tarball = fp.read()
322
327
 
323
- response = http_session.get(url, auth=NullAuth())
324
- assert response.status_code == 401
325
328
  response = http_session.get(url)
326
329
  assert response.status_code == 200, (url, response.request.headers)
327
330
  assert response.content == tarball
328
331
 
332
+ def test_collection_download_redirect_fails_unauthorized(
333
+ self,
334
+ http_session,
335
+ collection_highest_version,
336
+ ):
337
+ # Artifact Download Endoint
338
+ url = collection_highest_version["download_url"]
339
+
340
+ response = http_session.get(url, auth=NullAuth())
341
+ assert response.status_code == 401
342
+
343
+ def test_downloading_collection_with_bad_name_returns_not_found(
344
+ self,
345
+ http_session,
346
+ collection_highest_version,
347
+ ):
348
+ # Artifact Download Endoint, but we mess up the address.
349
+ url = collection_highest_version["download_url"].replace("-", "_")
350
+
351
+ response = http_session.get(url)
352
+ assert response.status_code == 404
353
+
329
354
  def test_collection_upload_repeat(
330
355
  self, http_session, ansible_collection_factory, pulp_dist, collection_upload
331
356
  ):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pulp-ansible
3
- Version: 0.28.2
3
+ Version: 0.28.4
4
4
  Summary: Pulp plugin to manage Ansible content, e.g. roles
5
5
  Author-email: Pulp Ansible Plugin Project Developers <pulp-dev@redhat.com>
6
6
  Project-URL: Homepage, https://pulpproject.org
@@ -1,6 +1,6 @@
1
1
  pulp_ansible/__init__.py,sha256=WXL3JyOZzh4tALN4OBNgqj412O2LXVr8iYSn14Av0_o,67
2
2
  pulp_ansible/pytest_plugin.py,sha256=hi9crI7QGghXCItNx27pW6KoXMzZqhAqAUstpJrsmlA,9105
3
- pulp_ansible/app/__init__.py,sha256=ACi_3Kos2rCKIQ3FaqkfO5_Cu6w5zqIf7xpNyTChCWg,308
3
+ pulp_ansible/app/__init__.py,sha256=K5wFSReWtPOzzbQaGKoXIOm8lWK1XYqJZcyKm1KEg2Y,308
4
4
  pulp_ansible/app/constants.py,sha256=cRrWMbJU-v1nCY2CjmGTOFGzz5aggn4ZKIs4-zeYADQ,78
5
5
  pulp_ansible/app/downloaders.py,sha256=0xrAXzhTMJ6ywvs6XyYNAKvRzYb_UZR6A5_WgaHvuiE,8331
6
6
  pulp_ansible/app/fields.py,sha256=yV3FL-47K-nxbiBxgzWi1hk3tfLsRdgic59LiwT2Fvs,624
@@ -8,7 +8,7 @@ pulp_ansible/app/global_access_conditions.py,sha256=ayV_LbQIa4ReuDYQycdDY7WysfGk
8
8
  pulp_ansible/app/logutils.py,sha256=My4XivZMYLKeJqPHFwk3pIZSGlspALhI93vZxwWzlSY,846
9
9
  pulp_ansible/app/modelresource.py,sha256=fJ_njrSWdftFQpA54e6mdoIWG_zqBjpp2TkkyU8Y7D4,7181
10
10
  pulp_ansible/app/models.py,sha256=CrEcVxQUlb6V_d9l7_as7_Gi6TrBuJ_xJLhFCR_5jew,22709
11
- pulp_ansible/app/serializers.py,sha256=5_NM1tpMLrZ2QsNCWanaHhscGCS_QDLubXCTh5xwm8E,35981
11
+ pulp_ansible/app/serializers.py,sha256=28lwMvLa3D-i4cekaIx50ffHUU78OfoDBlwdcTSTWyI,36670
12
12
  pulp_ansible/app/settings.py,sha256=ArDsI7VezOpKM9iFqxXb6VmEDOtRUS5lfB_oklkcxds,1244
13
13
  pulp_ansible/app/urls.py,sha256=gpMqsYPgHfc_6-EySR9ezUnI1F5yklzOVlSz9nlppmY,8697
14
14
  pulp_ansible/app/utils.py,sha256=ClI_WvVy73kOZQB2mS8Gftf80Vye7pOxrbodTmPQgmk,1686
@@ -22,7 +22,7 @@ pulp_ansible/app/galaxy/v3/exceptions.py,sha256=uKTj_LteLusc9Wu0iSYO-U8Gq9UK1eVR
22
22
  pulp_ansible/app/galaxy/v3/filters.py,sha256=XW39dC4N531Rlkhof5a-MDqxU2gFAkKWG3eeuIe02FY,8047
23
23
  pulp_ansible/app/galaxy/v3/pagination.py,sha256=FhFKtPfljjmKrnB_EWz7FxAhKPX9gkuvbOx-2KU9V4Y,4042
24
24
  pulp_ansible/app/galaxy/v3/serializers.py,sha256=VV2p-gLHKy0EnRBsblPga2Lcn9fLp5qp_7rhlaAlDmY,13364
25
- pulp_ansible/app/galaxy/v3/views.py,sha256=PJyK85cqLPRXVXY8B-shKGIh93mpnWONH1PplAD6MWM,47750
25
+ pulp_ansible/app/galaxy/v3/views.py,sha256=-ogkpNIZaZkubIJSqEAsg1dppVdJ6WDtFn5C4hsNqWk,47876
26
26
  pulp_ansible/app/galaxy/v3/viewsets.py,sha256=6mLK81oUZvvVmrEJ2BzIUzFvPoHeEBHOnwqROkPcNTs,3918
27
27
  pulp_ansible/app/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
28
  pulp_ansible/app/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -128,7 +128,7 @@ pulp_ansible/tests/functional/api/collection/test_signatures.py,sha256=Oos2kyUMz
128
128
  pulp_ansible/tests/functional/api/collection/test_sync.py,sha256=ITeATktxSpXbV4emJ8xXl4EGuebBRmrBdDRarVmSgJ8,14818
129
129
  pulp_ansible/tests/functional/api/collection/v3/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
130
130
  pulp_ansible/tests/functional/api/collection/v3/test_client_configuration.py,sha256=Tk8PdvG2Y1mZs5pUm2z91Tlpxaw0_8TvhshNbioMkKg,648
131
- pulp_ansible/tests/functional/api/collection/v3/test_collection.py,sha256=zO9CzNko3Cl0X0m5bf3cWQj6xu7iOkLLoZVBxAclwgA,12983
131
+ pulp_ansible/tests/functional/api/collection/v3/test_collection.py,sha256=B9Nczrsr7AB_dT3IAVs4pJvCTcbQSxpoviCJUBMsRok,13717
132
132
  pulp_ansible/tests/functional/api/collection/v3/test_collection_naming_edgecases.py,sha256=qPYFf-lWg2-i8xRvRGMKmGHbg00Cyd0EqGjzXF4ET-8,5492
133
133
  pulp_ansible/tests/functional/api/collection/v3/test_collection_version_search.py,sha256=uQGWs5ny0R-dP9YjZcspFRPDQTA-_OSuy6Dm4TLPrT8,48422
134
134
  pulp_ansible/tests/functional/api/collection/v3/test_content_guard.py,sha256=lid_TY4ANaU1fmoDAn6xuApOcP8UnrBuXlYfaqGXyvA,3311
@@ -167,9 +167,9 @@ pulp_ansible/tests/unit/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
167
167
  pulp_ansible/tests/unit/migrations/conftest.py,sha256=61n56aJuwEuAcUS27xnmnEDx6Ie7M5zxh851doWm7Ok,438
168
168
  pulp_ansible/tests/unit/migrations/test_0057_collection_version_sha256_migrate.py,sha256=NmU-frZNO1qHvhdxfw-bwPTEkqN4Wdc3dEs9dWME47o,2174
169
169
  pulp_ansible/tests/unit/migrations/test_x_repo_search_migration.py,sha256=IrC_V_Gss4nqhkdL-60upcEzGcz8IsiI2d-MfUtFY-g,657
170
- pulp_ansible-0.28.2.dist-info/licenses/LICENSE,sha256=2ylvL381vKOhdO-w6zkrOxe9lLNBhRQpo9_0EbHC_HM,18046
171
- pulp_ansible-0.28.2.dist-info/METADATA,sha256=px7YGxFFEZea1rBPvo_mIkOvt7pHhLqIqJ08U13EapY,3125
172
- pulp_ansible-0.28.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
173
- pulp_ansible-0.28.2.dist-info/entry_points.txt,sha256=6PFqCdT7Yn7U5MlioYRsyyWbJDcZI2aAJuzc7yXHqGk,119
174
- pulp_ansible-0.28.2.dist-info/top_level.txt,sha256=5Rrg5DSM_F9wH8vu8Fxjb5EmroC-I8RVKp05fhXH6kQ,13
175
- pulp_ansible-0.28.2.dist-info/RECORD,,
170
+ pulp_ansible-0.28.4.dist-info/licenses/LICENSE,sha256=2ylvL381vKOhdO-w6zkrOxe9lLNBhRQpo9_0EbHC_HM,18046
171
+ pulp_ansible-0.28.4.dist-info/METADATA,sha256=wTh94QDoJmLY0tSk95LM6vh8VGv15Lb70fePPsDdNz8,3125
172
+ pulp_ansible-0.28.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
173
+ pulp_ansible-0.28.4.dist-info/entry_points.txt,sha256=6PFqCdT7Yn7U5MlioYRsyyWbJDcZI2aAJuzc7yXHqGk,119
174
+ pulp_ansible-0.28.4.dist-info/top_level.txt,sha256=5Rrg5DSM_F9wH8vu8Fxjb5EmroC-I8RVKp05fhXH6kQ,13
175
+ pulp_ansible-0.28.4.dist-info/RECORD,,