debian-mirror-gitlab/app/serializers/projects/serverless/service_entity.rb

97 lines
2.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# 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
2019-03-02 22:35:43 +05:30
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
2019-07-07 11:18:12 +05:30
expose :metrics_url do |service|
project_serverless_metrics_path(
request.project,
service.dig('environment_scope'),
service.dig('metadata', 'name')) + ".json"
end
2019-02-15 15:39:39 +05:30
expose :created_at do |service|
service.dig('metadata', 'creationTimestamp')
end
expose :url do |service|
2019-12-26 22:10:19 +05:30
knative_06_07_url(service) || knative_05_url(service)
2019-02-15 15:39:39 +05:30
end
expose :description do |service|
2019-12-26 22:10:19 +05:30
knative_07_description(service) || knative_05_06_description(service)
end
expose :image do |service|
2019-03-02 22:35:43 +05:30
service.dig(
'spec',
'runLatest',
'configuration',
2019-12-26 22:10:19 +05:30
'build',
'template',
'name')
end
private
def knative_07_description(service)
service.dig(
'spec',
'template',
2019-03-02 22:35:43 +05:30
'metadata',
'annotations',
2019-12-26 22:10:19 +05:30
'Description'
)
2019-02-15 15:39:39 +05:30
end
2019-12-26 22:10:19 +05:30
def knative_05_url(service)
"http://#{service.dig('status', 'domain')}"
end
def knative_06_07_url(service)
service.dig('status', 'url')
end
def knative_05_06_description(service)
2019-03-02 22:35:43 +05:30
service.dig(
'spec',
'runLatest',
'configuration',
2019-12-26 22:10:19 +05:30
'revisionTemplate',
'metadata',
'annotations',
'Description')
2019-02-15 15:39:39 +05:30
end
end
end
end