pulp.app.serializers¶
All serializers documented here should be imported directly from the pulp.app.serializers
namespace.
pulp.app.serializers.base¶
-
class
pulpcore.app.serializers.base.
AsyncOperationResponseSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Serializer for asynchronous operations.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.base.
DetailIdentityField
(view_name=None, **kwargs)¶ IdentityField for use in the pulp_href field of Master/Detail Serializers
When using this field on a Serializer, it will automatically cast objects to their Detail type base on the Serializer’s Model before generating URLs for them.
Subclasses must indicate the Master model they represent by declaring a queryset in their class body, usually <MasterModelImplementation>.objects.all().
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.base.
DetailRelatedField
(view_name=None, **kwargs)¶ RelatedField for use when relating to Master/Detail models
When using this field on a Serializer, relate it to the Master model in a Master/Detail relationship, and it will automatically cast objects to their Detail type before generating URLs for them.
Subclasses must indicate the Master model they represent by declaring a queryset in their class body, usually <MasterModelImplementation>.objects.all().
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_object
(*args, **kwargs)¶ Return the object corresponding to a matched URL.
Takes the matched URL conf arguments, and should return an object instance, or raise an ObjectDoesNotExist exception.
-
use_pk_only_optimization
()¶ If the lookup field is pk, DRF substitutes a PKOnlyObject as an optimization. This optimization breaks with Detail fields like this one which need access to their Meta class to get the relevant view_name.
-
-
class
pulpcore.app.serializers.base.
IdentityField
(view_name=None, **kwargs)¶ IdentityField for use in the pulp_href field of non-Master/Detail Serializers.
The get_url method is overriden so relative URLs are returned.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.app.serializers.base.
MatchingNullViewName
¶ Object that can be used as the default view name for detail fields
This is needed to bypass a view name check done in DRF’s to_internal_value method that checks that the view name for the incoming data matches the view name it expects for the object being represented. Since we don’t know the view name for that object until it’s been cast, and it doesn’t get cast until get_object is called, and this check happens immediately before get_object is called, this check is probitive to our implementation. Setting the default view_name attr of a Detail related or identity field to an instance of this class should ensure the the view_name attribute of one of these related fields is equal to any view name it’s compared to, bypassing DRF’s view_name matching check.
-
class
pulpcore.app.serializers.base.
ModelSerializer
(*args, **kwargs)¶ Base serializer for use with
pulpcore.app.models.Model
This ensures that all Serializers provide values for the ‘pulp_href` field.
The class provides a default for the
ref_name
attribute in the ModelSerializers’sMeta
class. This ensures that the OpenAPI definitions of plugins are namespaced properly.When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
validate
(data)¶
-
exclude_arg_name
= 'exclude_fields'¶
-
-
class
pulpcore.app.serializers.base.
NestedIdentityField
(view_name=None, **kwargs)¶ NestedIdentityField for use with nested resources.
When using this field in a serializer, it serializes the resource as a relative URL.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.app.serializers.base.
NestedRelatedField
(*args, **kwargs)¶ NestedRelatedField for use when relating to nested resources.
When using this field in a serializer, it serializes the related resource as a relative URL.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
class
pulpcore.app.serializers.base.
RelatedField
(view_name=None, **kwargs)¶ RelatedField when relating to non-Master/Detail models
When using this field on a serializer, it will serialize the related resource as a relative URL.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
-
pulpcore.app.serializers.base.
validate_unknown_fields
(initial_data, defined_fields)¶ This will raise a ValidationError if a serializer is passed fields that are unknown. The csrfmiddlewaretoken field is silently ignored.
pulp.app.serializers.fields¶
-
class
pulpcore.app.serializers.fields.
BaseURLField
(**kwargs)¶ Serializer Field for the base_url field of the Distribution.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
to_representation
(value)¶ Transform the outgoing native value into primitive data.
-
-
class
pulpcore.app.serializers.fields.
ContentArtifactChecksumField
(*args, **kwargs)¶ A serializer field for the artifact checksum Content model (single-artifact).
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_attribute
(instance)¶ Returns the field from the instance that should be serialized using this serializer field.
This serializer looks up the checksum for single artifact content
- Parameters
instance (
pulpcore.app.models.Content
) – An instance of Content being serialized.- Returns
A string of the checksum or None.
- Raises
rest_framework.exceptions.ValidationError – When more than one Artifacts exist.
-
-
class
pulpcore.app.serializers.fields.
ContentArtifactsField
(*args, **kwargs)¶ A serializer field for the ‘_artifacts’ ManyToManyField on the Content model.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_attribute
(instance)¶ Returns the field from the instance that should be serialized using this serializer field.
This serializer field serializes a ManyToManyField that is actually stored as a ContentArtifact model. Instead of returning the field, this method returns all the ContentArtifact models related to this Content.
- Parameters
instance (
pulpcore.app.models.Content
) – An instance of Content being serialized.- Returns
A list of ContentArtifact models related to the instance of Content.
-
run_validation
(data)¶ Validates ‘data’ dict.
Validates that all keys of ‘data’ are relative paths. Validates that all values of ‘data’ are URLs for an existing Artifact.
- Parameters
data (dict) – A dict mapping relative paths inside the Content to the corresponding Artifact URLs.
- Returns
- A dict mapping relative paths inside the Content to the corresponding Artifact
instances.
- Raises
rest_framework.exceptions.ValidationError – When one of the Artifacts does not exist or one of the paths is not a relative path or the field is missing.
-
to_representation
(value)¶ Serializes list of ContentArtifacts.
Returns a dict mapping relative paths inside the Content to the corresponding Artifact URLs.
- Parameters
value (list of
pulpcore.app.models.ContentArtifact
) – A list of all the ContentArtifacts related to the Content model being serialized.- Returns
- A dict where keys are relative path of the artifact inside the Content and values are
Artifact URLs.
-
-
class
pulpcore.app.serializers.fields.
LatestVersionField
(*args, **kwargs)¶ Unfortunately you can’t just set read_only=True on the class. It has to be done explicitly in the kwargs to __init__, or else DRF complains.
-
get_attribute
(instance)¶ - Parameters
instance (pulpcore.app.models.Repository) – a repository that has been matched by the current ViewSet.
- Returns
-
get_url
(obj, view_name, request, format)¶ Returns the URL for the appropriate object. Overrides the DRF method to change how the object is found.
- Parameters
obj (list of
pulpcore.app.models.RepositoryVersion
) – The versions of the current viewset’s repository.view_name (str) – The name of the view that should be used.
request (rest_framework.request.Request) – the current HTTP request being handled
format – undocumented by DRF. ???
- Returns
- the URL corresponding to the latest version of the current repository. If there
are no versions, returns None
- Return type
str
-
queryset
= None¶
-
-
class
pulpcore.app.serializers.fields.
RepositoryVersionFieldGetURLMixin
(view_name=None, **kwargs)¶ -
get_url
(obj, view_name, request, *args, **kwargs)¶
-
use_pk_only_optimization
()¶
-
view_name
= 'versions-detail'¶
-
-
class
pulpcore.app.serializers.fields.
RepositoryVersionIdentityField
(view_name=None, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.fields.
RepositoryVersionRelatedField
(view_name=None, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_object
(view_name, view_args, view_kwargs)¶ Return the object corresponding to a matched URL.
Takes the matched URL conf arguments, and should return an object instance, or raise an ObjectDoesNotExist exception.
-
queryset
¶
-
-
class
pulpcore.app.serializers.fields.
RepositoryVersionsIdentityFromRepositoryField
(view_name=None, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_url
(obj, view_name, request, *args, **kwargs)¶ Given an object, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
view_name
= 'repositories-detail'¶
-
-
class
pulpcore.app.serializers.fields.
SecretCharField
(**kwargs)¶ Serializer field for secrets.
This field accepts text as input and it returns a sha256 digest of the text stored.
Initialize a class and do not trim leading and trailing whitespace characters by default.
-
to_representation
(value)¶ Transform the outgoing native value into primitive data.
-
-
class
pulpcore.app.serializers.fields.
SingleContentArtifactField
(view_name=None, **kwargs)¶ A serializer field for the ‘_artifacts’ ManyToManyField on the Content model (single-artifact).
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
get_attribute
(instance)¶ Returns the field from the instance that should be serialized using this serializer field.
This serializer looks up the list of artifacts and returns only one, if any exist. If more than one exist, it throws and exception because this serializer is being used in an improper context.
- Parameters
instance (
pulpcore.app.models.Content
) – An instance of Content being serialized.- Returns
A single Artifact model related to the instance of Content.
-
allow_null
= True¶
-
lookup_field
= 'pk'¶
-
queryset
¶
-
view_name
= 'artifacts-detail'¶
-
-
pulpcore.app.serializers.fields.
relative_path_validator
(relative_path)¶
pulp.app.serializers.content¶
-
class
pulpcore.app.serializers.content.
ArtifactSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Artifact
-
fields
= ('pulp_href', 'pulp_created', 'file', 'size', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')¶
-
-
validate
(data)¶ Validate file by size and by all checksums provided.
- Parameters
data (
django.http.QueryDict
) – QueryDict mapping Artifact model fields to their values- Raises
rest_framework.exceptions.ValidationError – When the expected file size or any of the checksums don’t match their actual values.
-
class
-
class
pulpcore.app.serializers.content.
BaseContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.content.
ContentChecksumSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Provide a serializer with artifact checksum fields for single artifact content.
If you use this serializer, it’s recommended that you prefetch artifacts:
Content.objects.prefetch_related(“_artifacts”).all()
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.content.
MultipleArtifactContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Content
-
fields
= ('pulp_href', 'pulp_created', 'artifacts')¶
-
-
create
(validated_data)¶ Create the content and associate it with all its Artifacts.
- Parameters
validated_data (dict) – Data to save to the database
-
class
-
class
pulpcore.app.serializers.content.
NoArtifactContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.content.
SigningServiceSerializer
(*args, **kwargs)¶ A serializer for the model declaring a signing service.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.content.
SingleArtifactContentSerializer
(*args, **kwargs)¶ Initializer for SingleArtifactContentSerializer
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.content.Content
-
fields
= ('pulp_href', 'pulp_created', 'artifact', 'relative_path')¶
-
-
create
(validated_data)¶ Create the content and associate it with its Artifact.
- Parameters
validated_data (dict) – Data to save to the database
-
class
pulp.app.serializers.repository¶
-
class
pulpcore.app.serializers.repository.
ContentSummarySerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ Serializer for the RepositoryVersion content summary
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
to_internal_value
(data)¶ Setting the internal value.
-
to_representation
(obj)¶ The summary of contained content.
- Returns
The dictionary has the following format.:
{ 'added': {<pulp_type>: {'count': <count>, 'href': <href>}, 'removed': {<pulp_type>: {'count': <count>, 'href': <href>}, 'present': {<pulp_type>: {'count': <count>, 'href': <href>}, }
- Return type
dict
-
-
class
pulpcore.app.serializers.repository.
RemoteSerializer
(*args, **kwargs)¶ Every remote defined by a plugin should have a Remote serializer that inherits from this class. Please import from pulpcore.plugin.serializers rather than from this module directly.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.repository.Remote
-
abstract
= True¶
-
fields
= ('pulp_href', 'pulp_created', 'name', 'url', 'ca_cert', 'client_cert', 'client_key', 'tls_validation', 'proxy_url', 'username', 'password', 'pulp_last_updated', 'download_concurrency', 'policy')¶
-
-
validate_url
(value)¶ Check if the ‘url’ is a
file://
path, and if so, ensure it’s an ALLOWED_IMPORT_PATH.The ALLOWED_IMPORT_PATH is specified as a Pulp setting.
- Parameters
value – The user-provided value for ‘url’ to be validated.
- Raises
ValidationError – When the url starts with file://, but is not a subfolder of a path in the ALLOWED_IMPORT_PATH setting.
- Returns
The validated value.
-
class
-
class
pulpcore.app.serializers.repository.
RepositoryAddRemoveContentSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
Meta
¶ -
model
¶ alias of
pulpcore.app.models.repository.RepositoryVersion
-
fields
= ['add_content_units', 'remove_content_units', 'base_version']¶
-
-
validate_remove_content_units
(value)¶
-
class
-
class
pulpcore.app.serializers.repository.
RepositorySerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.repository.
RepositorySyncURLSerializer
(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
-
class
pulpcore.app.serializers.repository.
RepositoryVersionSerializer
(*args, **kwargs)¶ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.