File: environment.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (27 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download
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
# frozen_string_literal: true

module API
  module Entities
    class Environment < Entities::EnvironmentBasic
      include RequestAwareEntity

      expose :tier, documentation: { type: 'string', example: 'development' }
      expose :project, using: Entities::BasicProjectDetails
      expose :last_deployment, using: Entities::Deployment, if: { last_deployment: true }
      expose :state, documentation: { type: 'string', example: 'available' }
      expose :auto_stop_at, documentation: { type: 'dateTime', example: '2019-05-25T18:55:13.252Z' }
      expose :cluster_agent, using: Entities::Clusters::Agent, if: ->(_, _) { can_read_cluster_agent? }
      expose :kubernetes_namespace, if: ->(_, _) { can_read_cluster_agent? }
      expose :flux_resource_path, if: ->(_, _) { can_read_cluster_agent? }
      expose :description, documentation: { type: 'string', example: 'description' }

      private

      def can_read_cluster_agent?
        return unless object.cluster_agent.present?

        Ability.allowed?(options[:current_user], :read_cluster_agent, object.cluster_agent)
      end
    end
  end
end