2020-02-13 16:08:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class Environment < Entities::EnvironmentBasic
|
2021-05-03 08:09:49 -04:00
|
|
|
include RequestAwareEntity
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2022-05-02 23:10:17 -04:00
|
|
|
expose :tier
|
2020-02-13 16:08:59 -05:00
|
|
|
expose :project, using: Entities::BasicProjectDetails
|
|
|
|
expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true }
|
|
|
|
expose :state
|
2021-05-03 08:09:49 -04:00
|
|
|
|
|
|
|
expose :enable_advanced_logs_querying, if: -> (*) { can_read_pod_logs? } do |environment|
|
|
|
|
environment.elastic_stack_available?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :logs_api_path, if: -> (*) { can_read_pod_logs? } do |environment|
|
|
|
|
if environment.elastic_stack_available?
|
|
|
|
elasticsearch_project_logs_path(environment.project, environment_name: environment.name, format: :json)
|
|
|
|
else
|
|
|
|
k8s_project_logs_path(environment.project, environment_name: environment.name, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :gitlab_managed_apps_logs_path, if: -> (*) { can_read_pod_logs? && cluster } do |environment|
|
|
|
|
::Clusters::ClusterPresenter.new(cluster, current_user: current_user).gitlab_managed_apps_logs_path # rubocop: disable CodeReuse/Presenter
|
|
|
|
end
|
2021-04-23 08:09:52 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
alias_method :environment, :object
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
def can_read_pod_logs?
|
|
|
|
strong_memoize(:can_read_pod_logs) do
|
|
|
|
current_user&.can?(:read_pod_logs, environment.project)
|
|
|
|
end
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
|
2021-05-03 08:09:49 -04:00
|
|
|
def cluster
|
|
|
|
strong_memoize(:cluster) do
|
|
|
|
environment&.last_deployment&.cluster
|
|
|
|
end
|
2021-04-23 08:09:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
options[:current_user]
|
|
|
|
end
|
2020-02-13 16:08:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|