pulpcore.plugin.util

All utils documented here should be imported directly from the pulpcore.plugin.util namespace.

pulpcore.plugin.util.assign_role(rolename, entity, obj=None)

Assign a role to a user or a group.

Parameters:
  • rolename (str) – Name of the role to assign.

  • entity (django.contrib.auth.User or pulpcore.app.models.Group) – Entity to gain the role.

  • obj (Optional[pulpcore.app.models.BaseModel]) – Object the role permisssions are to be asserted on.

pulpcore.plugin.util.get_artifact_url(artifact, headers=None, http_method=None)

Get artifact url.

Plugins can use this method to generate a pre-authenticated URL to the artifact in the configured storage backend. This can be used to facilitate external services for validation of the content.

This method will generate redirect links to the configured external object storage, or to the special “artifact redirect” distribution in the content-app top serve from the local filesystem or private cloud storage.

pulpcore.plugin.util.get_url(model)

Get a resource url for the specified model object. This returns the path component of the resource URI. This is used in our resource locking/reservation code to identify resources.

Parameters:

model (django.models.Model) – A model object.

Returns:

The path component of the resource url

Return type:

str

pulpcore.plugin.util.gpg_verify(public_keys, signature, detached_data=None)

Check whether the provided gnupg signature is valid for one of the provided public keys.

Parameters:
  • public_keys (str) – Ascii armored public key data

  • signature (str, file-like, Artifact) – The signature data as a path or as a file-like object

  • detached_data (str) – The filesystem path to signed data in case of a detached signature

Returns:

The result of the verification

Return type:

gnupg.Verify

Raises:

pulpcore.exceptions.validation.InvalidSignatureError – In case the signature is invalid.

pulpcore.plugin.util.remove_role(rolename, entity, obj=None)

Remove a role from a user or a group.

Parameters:
  • rolename (str) – Name of the role to assign.

  • entity (django.contrib.auth.User or pulpcore.app.models.Group) – Entity to lose the role.

  • obj (Optional[pulpcore.app.models.BaseModel]) – Object the role permisssions are to be asserted on.

pulpcore.plugin.util.verify_signature(filepath, public_key, detached_data=None)

Check whether the provided file can be verified with the particular public key.

When dealing with a detached signature (referenced by the ‘filepath’ argument), one have to pass the reference to a data file that was signed by that signature.