diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-14 03:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-14 03:08:59 +0300 |
commit | 13d294a8d8be05421e7d5e34577033ba5b34059c (patch) | |
tree | f9aab2c3930cb85e9afbb111063930a1bdd1c156 /app/serializers | |
parent | a269fb8e7cca24b826dd3f53485641ffce93bbee (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/serializers')
6 files changed, 160 insertions, 0 deletions
diff --git a/app/serializers/integrations/harbor_serializers/artifact_entity.rb b/app/serializers/integrations/harbor_serializers/artifact_entity.rb new file mode 100644 index 00000000000..010380561eb --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/artifact_entity.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class ArtifactEntity < Grape::Entity + include ActionView::Helpers::SanitizeHelper + + expose :harbor_id do |item| + item['id'] + end + + expose :digest do |item| + strip_tags(item['digest']) + end + + expose :size do |item| + item['size'] + end + + expose :push_time do |item| + item['push_time']&.to_datetime&.utc + end + + expose :tags do |item| + item['tags'].map { |tag| strip_tags(tag['name']) } + end + end + end +end diff --git a/app/serializers/integrations/harbor_serializers/artifact_serializer.rb b/app/serializers/integrations/harbor_serializers/artifact_serializer.rb new file mode 100644 index 00000000000..aaf78a72330 --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/artifact_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class ArtifactSerializer < BaseSerializer + include WithPagination + + entity ::Integrations::HarborSerializers::ArtifactEntity + end + end +end diff --git a/app/serializers/integrations/harbor_serializers/repository_entity.rb b/app/serializers/integrations/harbor_serializers/repository_entity.rb new file mode 100644 index 00000000000..f03465fe8e2 --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/repository_entity.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class RepositoryEntity < Grape::Entity + include ActionView::Helpers::SanitizeHelper + + expose :harbor_id do |item| + item['id'] + end + + expose :name do |item| + strip_tags(item['name']) + end + + expose :artifact_count do |item| + item['artifact_count'] + end + + expose :creation_time do |item| + item['creation_time']&.to_datetime&.utc + end + + expose :update_time do |item| + item['update_time']&.to_datetime&.utc + end + + expose :harbor_project_id do |item| + item['project_id'] + end + + expose :pull_count do |item| + item['pull_count'] + end + + expose :location do |item| + path = [ + 'harbor/projects', + item['project_id'].to_s, + 'repositories', + item['name'].remove("#{options[:project_name]}/") + ].join('/') + path = validate_path(path) + strip_tags(Gitlab::Utils.append_path(options[:url], path)) + end + + private + + def validate_path(path) + Gitlab::Utils.check_path_traversal!(path) + rescue ::Gitlab::Utils::PathTraversalAttackError + Gitlab::AppLogger.error("Path traversal attack detected #{path}") + '' + end + end + end +end diff --git a/app/serializers/integrations/harbor_serializers/repository_serializer.rb b/app/serializers/integrations/harbor_serializers/repository_serializer.rb new file mode 100644 index 00000000000..9b9e089eab8 --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/repository_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class RepositorySerializer < BaseSerializer + include WithPagination + + entity ::Integrations::HarborSerializers::RepositoryEntity + end + end +end diff --git a/app/serializers/integrations/harbor_serializers/tag_entity.rb b/app/serializers/integrations/harbor_serializers/tag_entity.rb new file mode 100644 index 00000000000..8c26bc1ecbd --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/tag_entity.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class TagEntity < Grape::Entity + include ActionView::Helpers::SanitizeHelper + + expose :harbor_repository_id do |item| + item['repository_id'] + end + + expose :harbor_artifact_id do |item| + item['artifact_id'] + end + + expose :harbor_id do |item| + item['id'] + end + + expose :name do |item| + strip_tags(item['name']) + end + + expose :pull_time do |item| + item['pull_time']&.to_datetime&.utc + end + + expose :push_time do |item| + item['push_time']&.to_datetime&.utc + end + + expose :signed do |item| + item['signed'] + end + + expose :immutable do |item| + item['immutable'] + end + end + end +end diff --git a/app/serializers/integrations/harbor_serializers/tag_serializer.rb b/app/serializers/integrations/harbor_serializers/tag_serializer.rb new file mode 100644 index 00000000000..7111e65e3e6 --- /dev/null +++ b/app/serializers/integrations/harbor_serializers/tag_serializer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Integrations + module HarborSerializers + class TagSerializer < BaseSerializer + include WithPagination + + entity ::Integrations::HarborSerializers::TagEntity + end + end +end |