Project

Profile

Help

Story #4072

As a plugin writer I can have digest and size information validated and populated easily via a staticmethod

Added by bmbouter about 1 year ago. Updated 8 months ago.

Status:
MODIFIED
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
% Done:

100%

Platform Release:
Blocks Release:
Backwards Incompatible:
No
Groomed:
No
Sprint Candidate:
No
Tags:
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:

Description

Problem

While making an upload API for pulp_ansible, I receive only a sha256 from the user to validate the uploaded data. To save an Artifact I need the other digests and the size. This causes me to manually compute all the digest info and perform any validation.

This is going to be a common problem for plugin writers receiving Artifact data and not using the downloaders, e.g. upload.

Solution

Add a static method to Artifact named create_and_validate that can create an in-memory Artifact from an on-disk asset with the following signature:

def create_and_validate(file, expected_digests=None, expected_size=None):

These params are the same type/names as the ones used by BaseDownloader here

Usage

For example I can call it with:

my_artifact = Artifact.create_and_validate('/path/to/file', expected_digests={'sha256': 'long_digest_value_goes_here'})

Exception Raising

If the sha256 doesn't match, I expect it to raise a DigestValidationError or a SizeValidationError, just like the downloaders. See this docstring:

            :class:`~pulpcore.plugin.download.DigestValidationError`: When any of the
                ``expected_digest`` values don't match the digest of the data passed to
                :meth:`~pulpcore.plugin.download.BaseDownloader.handle_data`.
            :class:`~pulpcore.plugin.download.SizeValidationError`: When the
                ``expected_size`` value doesn't match the size of the data passed to
                :meth:`~pulpcore.plugin.download.BaseDownloader.handle_data`.

^ is from here

Associated revisions

Revision 50251ae5 View on GitHub
Added by bmbouter about 1 year ago

Make an Artifact from a PulpTemporaryUploadedFile

Adds the Artifact.create_and_validate staticmethod that creates an
in-memory, unsaved Artifact from a PulpTemporaryUploadedFile. Uploaded
files to Pulp show up with that type so that is convenient for plugin
writers. Also as the file is received by Django it auto-computes all of
the digest types.

This PR also moves SizeValidationError and DigestValidation error to
pulpcore.exceptions instead of living in pulpcore.plugin.downloads.

The ArtifactSerializer is also exposed via the plugin API with this
change also.

https://pulp.plan.io/issues/4072
closes #4072

Revision 50251ae5 View on GitHub
Added by bmbouter about 1 year ago

Make an Artifact from a PulpTemporaryUploadedFile

Adds the Artifact.create_and_validate staticmethod that creates an
in-memory, unsaved Artifact from a PulpTemporaryUploadedFile. Uploaded
files to Pulp show up with that type so that is convenient for plugin
writers. Also as the file is received by Django it auto-computes all of
the digest types.

This PR also moves SizeValidationError and DigestValidation error to
pulpcore.exceptions instead of living in pulpcore.plugin.downloads.

The ArtifactSerializer is also exposed via the plugin API with this
change also.

https://pulp.plan.io/issues/4072
closes #4072

Revision bfe5efbc View on GitHub
Added by bmbouter about 1 year ago

Allow Artifact init and validation from a file

There wasn't a way to have the upload handler involved so I had to open
and compute the hashes manually.

https://pulp.plan.io/issues/4072
re #4072

Revision bfe5efbc View on GitHub
Added by bmbouter about 1 year ago

Allow Artifact init and validation from a file

There wasn't a way to have the upload handler involved so I had to open
and compute the hashes manually.

https://pulp.plan.io/issues/4072
re #4072

History

#1 Updated by bmbouter about 1 year ago

  • Description updated (diff)

Renaming to create_and_validate

#2 Updated by bmbouter about 1 year ago

  • Description updated (diff)

The Artifact needs to read from somewhere, so I added a 'file'.

#3 Updated by bmbouter about 1 year ago

  • Status changed from NEW to POST
  • Assignee set to bmbouter

#4 Updated by bmbouter about 1 year ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100

#5 Updated by bmbouter about 1 year ago

  • Status changed from MODIFIED to POST

#6 Updated by bmbouter about 1 year ago

  • Status changed from POST to MODIFIED

#7 Updated by daviddavis 8 months ago

  • Sprint/Milestone set to 3.0

#8 Updated by bmbouter 8 months ago

  • Tags deleted (Pulp 3)

Please register to edit this issue

Also available in: Atom PDF