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, domain=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.
domain (Optional[pulpcore.app.models.Domain]) – Domain the role permissions are to be asserted on. Mutually exclusive with obj.
- pulpcore.plugin.util.extract_pk(uri)
Resolve a resource URI to a simple PK value.
Provides a means to resolve an href passed in a POST body to a primary key. Doesn’t assume anything about whether the resource corresponding to the URI passed in actually exists.
Note
Cannot be used with nested URIs where the PK of the final resource is not present. e.g. RepositoryVersion URI consists of repository PK and version number - no RepositoryVersion PK is present within the URI.
- Parameters:
uri (str) – A resource URI.
- Returns:
The primary key of the resource extracted from the URI.
- Return type:
primary_key (uuid.uuid4)
- Raises:
rest_framework.exceptions.ValidationError – on invalid URI.
- 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, domain=None)
Get a resource url for the specified model instance or class. 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 instance or class.
Optional (domain) – The domain the url should be in if DOMAIN_ENABLED is set and
'default'. (domain can not be gathered from the model. Defaults to) –
- 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.raise_for_unknown_content_units(existing_content_units, content_units_pks_hrefs)
Verify if all the specified content units were found in the database.
- Parameters:
existing_content_units (pulpcore.plugin.models.Content) – Content filtered by specified_content_units.
content_units_pks_hrefs (dict) – An original dictionary of pk-href pairs that are used for the verification.
- Raises:
ValidationError – If some of the referenced content units are not present in the database
- pulpcore.plugin.util.remove_role(rolename, entity, obj=None, domain=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.
domain (Optional[pulpcore.app.models.Domain]) – Domain the role permissions are to be asserted on. Mutually exclusive with obj.