summaryrefslogtreecommitdiff
path: root/app/serializers/projects/serverless/service_entity.rb
blob: c98dc1a1c4aa9af062339ca1894e80128a7a3364 (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
58
59
60
61
62
63
64
65
# frozen_string_literal: true

module Projects
  module Serverless
    class ServiceEntity < Grape::Entity
      include RequestAwareEntity

      expose :name do |service|
        service.dig('metadata', 'name')
      end

      expose :namespace do |service|
        service.dig('metadata', 'namespace')
      end

      expose :environment_scope do |service|
        service.dig('environment_scope')
      end

      expose :cluster_id do |service|
        service.dig('cluster_id')
      end

      expose :detail_url do |service|
        project_serverless_path(
          request.project,
          service.dig('environment_scope'),
          service.dig('metadata', 'name'))
      end

      expose :podcount do |service|
        service.dig('podcount')
      end

      expose :created_at do |service|
        service.dig('metadata', 'creationTimestamp')
      end

      expose :url do |service|
        "http://#{service.dig('status', 'domain')}"
      end

      expose :description do |service|
        service.dig(
          'spec',
          'runLatest',
          'configuration',
          'revisionTemplate',
          'metadata',
          'annotations',
          'Description')
      end

      expose :image do |service|
        service.dig(
          'spec',
          'runLatest',
          'configuration',
          'build',
          'template',
          'name')
      end
    end
  end
end