2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-28 08:32:07 -04:00
|
|
|
class EnvironmentEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :name
|
2016-11-03 07:54:10 -04:00
|
|
|
expose :state
|
|
|
|
expose :external_url
|
|
|
|
expose :environment_type
|
2019-02-26 14:13:09 -05:00
|
|
|
expose :name_without_type
|
2016-11-03 07:54:10 -04:00
|
|
|
expose :last_deployment, using: DeploymentEntity
|
2018-07-12 06:22:11 -04:00
|
|
|
expose :stop_action_available?, as: :has_stop_action
|
2016-10-28 08:32:07 -04:00
|
|
|
|
2017-03-31 05:20:11 -04:00
|
|
|
expose :metrics_path, if: -> (environment, _) { environment.has_metrics? } do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
metrics_project_environment_path(environment.project, environment)
|
2017-03-31 05:20:11 -04:00
|
|
|
end
|
|
|
|
|
2016-11-17 10:08:05 -05:00
|
|
|
expose :environment_path do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
project_environment_path(environment.project, environment)
|
2016-11-02 09:36:21 -04:00
|
|
|
end
|
|
|
|
|
2016-11-18 16:31:53 -05:00
|
|
|
expose :stop_path do |environment|
|
2017-06-29 13:06:35 -04:00
|
|
|
stop_project_environment_path(environment.project, environment)
|
2016-11-18 16:31:53 -05:00
|
|
|
end
|
|
|
|
|
2018-12-20 04:39:09 -05:00
|
|
|
expose :cluster_type, if: ->(environment, _) { cluster_platform_kubernetes? } do |environment|
|
|
|
|
cluster.cluster_type
|
|
|
|
end
|
|
|
|
|
2018-08-10 09:45:14 -04:00
|
|
|
expose :terminal_path, if: ->(*) { environment.has_terminals? && can_access_terminal? } do |environment|
|
|
|
|
terminal_project_environment_path(environment.project, environment)
|
2016-11-22 14:55:56 -05:00
|
|
|
end
|
|
|
|
|
2017-08-21 11:46:45 -04:00
|
|
|
expose :folder_path do |environment|
|
|
|
|
folder_project_environments_path(environment.project, environment.folder_name)
|
|
|
|
end
|
|
|
|
|
2016-11-03 07:54:10 -04:00
|
|
|
expose :created_at, :updated_at
|
2018-07-10 04:11:04 -04:00
|
|
|
|
|
|
|
expose :can_stop do |environment|
|
|
|
|
environment.available? && can?(current_user, :stop_environment, environment)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-08-10 09:45:14 -04:00
|
|
|
alias_method :environment, :object
|
|
|
|
|
2018-07-10 04:11:04 -04:00
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
2018-08-10 09:45:14 -04:00
|
|
|
|
|
|
|
def can_access_terminal?
|
|
|
|
can?(request.current_user, :create_environment_terminal, environment)
|
|
|
|
end
|
2018-12-20 04:39:09 -05:00
|
|
|
|
|
|
|
def cluster_platform_kubernetes?
|
|
|
|
deployment_platform && deployment_platform.is_a?(Clusters::Platforms::Kubernetes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def deployment_platform
|
|
|
|
environment.deployment_platform
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster
|
|
|
|
deployment_platform.cluster
|
|
|
|
end
|
2016-10-28 08:32:07 -04:00
|
|
|
end
|