Skip to content

Commit

Permalink
Add version_sign_state to version detail, expose signature data
Browse files Browse the repository at this point in the history
Requested by: @brumik

Issue: AAH-1181
env:LOCK_REQUIREMENTS=0
env:PULP_ANSIBLE_REVISION=master
  • Loading branch information
rochacbruno committed Jan 27, 2022
1 parent 8688259 commit 187dd13
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
File renamed without changes.
11 changes: 9 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ run_service() {

process_init_files /entrypoints.d/*

setup_signing_service
# run setup signing service only if DEV_SOURCE_PATH is set
if [[ -n "$DEV_SOURCE_PATH" ]]; then
setup_signing_service
fi

exec "${service_path}" "$@"
}
Expand All @@ -118,7 +121,11 @@ run_manage() {
install_local_deps
fi

setup_signing_service
# run setup signing service only if DEV_SOURCE_PATH is set
if [[ -n "$DEV_SOURCE_PATH" ]]; then
setup_signing_service
fi

exec django-admin "$@"
}

Expand Down
32 changes: 28 additions & 4 deletions galaxy_ng/app/api/ui/serializers/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ class CollectionMetadataSerializer(Serializer):
tags = serializers.SerializerMethodField()
signatures = serializers.SerializerMethodField()

@extend_schema_field(serializers.ListField(child=serializers.CharField()))
@extend_schema_field(serializers.ListField(child=serializers.DictField()))
def get_signatures(self, obj):
"""Returns signature pubkey_fingerprint for each signature."""
return obj.signatures.values_list("pubkey_fingerprint", flat=True)
data = []
for signature in obj.signatures.all():
sig = {}
sig["signature"] = bytes(signature.data).decode("utf-8")
sig["pubkey_fingerprint"] = signature.pubkey_fingerprint
sig["signing_service"] = signature.signing_service.name
data.append(sig)
return data

@extend_schema_field(serializers.ListField)
def get_tags(self, collection_version):
Expand All @@ -73,14 +80,26 @@ def get_tags(self, collection_version):
return [tag.name for tag in collection_version.tags.all()]


class CollectionVersionBaseSerializer(Serializer):
class CollectionVersionSignStateMixin:

@extend_schema_field(serializers.CharField())
def get_version_sign_state(self, obj):
"""Returns the state of the signature."""
if obj.signatures.count() == 0:
return "unsigned"
else:
return "signed"


class CollectionVersionBaseSerializer(CollectionVersionSignStateMixin, Serializer):
namespace = serializers.CharField()
name = serializers.CharField()
version = serializers.CharField()
requires_ansible = serializers.CharField()
created_at = serializers.DateTimeField(source='pulp_created')
metadata = CollectionMetadataSerializer(source='*')
contents = serializers.ListField(child=ContentSerializer())
version_sign_state = serializers.SerializerMethodField()


class CollectionVersionSerializer(CollectionVersionBaseSerializer):
Expand All @@ -107,9 +126,10 @@ class CollectionVersionDetailSerializer(CollectionVersionBaseSerializer):
docs_blob = serializers.JSONField()


class CollectionVersionSummarySerializer(Serializer):
class CollectionVersionSummarySerializer(CollectionVersionSignStateMixin, Serializer):
version = serializers.CharField()
created = serializers.CharField(source='pulp_created')
version_sign_state = serializers.SerializerMethodField()


class _CollectionSerializer(Serializer):
Expand Down Expand Up @@ -143,6 +163,10 @@ def get_latest_version(self, obj):

class CollectionDetailSerializer(_CollectionSerializer):
all_versions = serializers.SerializerMethodField()
sign_state = serializers.CharField()
total_versions = serializers.IntegerField(default=0)
signed_versions = serializers.IntegerField(default=0)
unsigned_versions = serializers.IntegerField(default=0)

# TODO: rename field to "version_details" since with
# "version" query param this won't always be the latest version
Expand Down
11 changes: 11 additions & 0 deletions galaxy_ng/app/dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def post(settings: Dynaconf) -> Dict[str, Any]:
data.update(configure_logging(settings))
data.update(configure_keycloak(settings))
data.update(configure_cors(settings))
data.update(configure_feature_flags(settings))

return data

Expand Down Expand Up @@ -268,3 +269,13 @@ def configure_cors(settings: Dynaconf) -> Dict[str, Any]:
corsmiddleware = ["galaxy_ng.app.common.openapi.AllowCorsMiddleware"]
data["MIDDLEWARE"] = corsmiddleware + settings.get("MIDDLEWARE", [])
return data


def configure_feature_flags(settings: Dynaconf) -> Dict[str, Any]:
"""Adds conditional feature flags"""
data = {}
data["GALAXY_FEATURE_FLAGS__collection_signing"] = settings.get(
"GALAXY_COLLECTION_SIGNING_SERVICE") is not None
data["GALAXY_FEATURE_FLAGS__collection_auto_sign"] = settings.get(
"GALAXY_AUTO_SIGN_COLLECTIONS") is True
return data

0 comments on commit 187dd13

Please sign in to comment.