Class: Katello::Api::V2::EnvironmentsController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/environments_controller.rb

Constant Summary

Constants included from Concerns::FilteredAutoCompleteSearch

Concerns::FilteredAutoCompleteSearch::PAGE_SIZE

Instance Method Summary collapse

Methods included from Concerns::FilteredAutoCompleteSearch

#auto_complete_search

Methods inherited from ApiController

#check_katello_agent_not_disabled, #deprecate_katello_agent, #empty_search_query?, #full_result_response, #katello_agent_removal_release, #scoped_search, #skip_session

Methods included from Rendering

#respond_for_async, #respond_for_bulk_async, #respond_for_create, #respond_for_destroy, #respond_for_index, #respond_for_show, #respond_for_status, #respond_for_update, #respond_with_template, #respond_with_template_collection, #respond_with_template_resource, #try_specific_collection_template, #try_specific_resource_template

Methods included from Katello::Api::Version2

#api_version

Instance Method Details

#createObject



87
88
89
90
91
92
93
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 87

def create
  create_params = environment_params
  create_params[:label] = labelize_params(create_params)
  create_params[:organization] = @organization
  @environment = @prior.insert_successor(create_params, @path)
  respond
end

#destroyObject



126
127
128
129
130
131
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 126

def destroy
  sync_task(::Actions::Katello::Environment::Destroy, @environment)
  respond_for_destroy
rescue RuntimeError => e
  raise HttpErrors::BadRequest, e.message
end

#indexObject



54
55
56
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 54

def index
  respond(:collection => scoped_search(index_relation.distinct, :name, :asc, :resource_class => KTEnvironment))
end

#index_relationObject



58
59
60
61
62
63
64
65
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 58

def index_relation
  query = KTEnvironment.readable
  query = query.where(organization: @organization) if @organization
  query = query.where(:name => params[:name]) if params[:name]
  query = query.where(:label => params[:label]) if params[:label]
  query = query.where(:library => params[:library]) if params[:library]
  query
end

#pathsObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 139

def paths
  env_paths = if params[:permission_type] == "promotable"
                @organization.promotable_promotion_paths
              else
                @organization.readable_promotion_paths
              end

  paths = env_paths.inject([]) do |result, path|
    result << { :environments => [@organization.library] + path.select(&:readable?) }
  end
  paths = [{ :environments => [@organization.library] }] if paths.empty?

  collection = {
    :results => paths,
    :total => paths.size,
    :subtotal => paths.size
  }
  respond_for_index(:collection => collection, :template => :paths)
end

#resource_classObject



163
164
165
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 163

def resource_class
  Katello::KTEnvironment
end

#resource_nameObject



159
160
161
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 159

def resource_name
  'environment'
end

#showObject



71
72
73
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 71

def show
  respond(resource: @environment)
end

#updateObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/controllers/katello/api/v2/environments_controller.rb', line 104

def update
  async = ::Foreman::Cast.to_bool(params.fetch(:async, true))
  update_params = environment_params
  fail HttpErrors::BadRequest, _("Can't update the '%s' environment") % "Library" if @environment.library? && update_params.empty?
  update_params[:name] = params[:environment][:new_name] if params[:environment][:new_name]
  @environment.update!(update_params)
  if update_params[:registry_name_pattern] || update_params[:registry_unauthenticated_pull]
    task = send(async ? :async_task : :sync_task, ::Actions::Katello::Environment::PublishRepositories,
                @environment, content_type: Katello::Repository::DOCKER_TYPE)
  end

  if params.include?(:async) && async && task
    respond_for_async(resource: task)
  else
    respond
  end
end