Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repository_entity.rb « harbor_serializers « integrations « serializers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f03465fe8e2c09742a4abaafac3727c007bb7d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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