Class: Katello::Api::V2::GpgKeysController

Inherits:
ApiController
  • Object
show all
Includes:
Concerns::FilteredAutoCompleteSearch
Defined in:
app/controllers/katello/api/v2/gpg_keys_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

#full_result_response, #resource_class, #scoped_search

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

#contentObject



77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 77

def content
  filepath = params.try(:[], :content).try(:path)

  if filepath
    content = File.open(filepath, "rb") { |file| file.read }
    @gpg_key.update_attributes!(:content => content)
    render :json => {:status => "success"}
  else
    fail HttpErrors::BadRequest, _("No file uploaded")
  end
end

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 39

def create
  filepath = params.try(:[], :file_path).try(:path)

  content = nil
  if filepath
    content = File.open(filepath, "rb") { |file| file.read }
  else
    content = params[:content]
  end

  gpg_key = @organization.gpg_keys.create!(gpg_key_params.merge(:content => content))
  respond_for_show(:resource => gpg_key)
end

#destroyObject



69
70
71
72
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 69

def destroy
  @gpg_key.destroy
  respond_for_destroy
end

#indexObject



26
27
28
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 26

def index
  respond(:collection => scoped_search(index_relation.uniq, :name, :desc))
end

#index_relationObject



30
31
32
33
34
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 30

def index_relation
  query = GpgKey.readable.where(:organization_id => @organization.id)
  query = query.where(:name => params[:name]) if params[:name]
  query
end

#showObject



55
56
57
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 55

def show
  respond_for_show(:resource => @gpg_key)
end

#updateObject



62
63
64
65
# File 'app/controllers/katello/api/v2/gpg_keys_controller.rb', line 62

def update
  @gpg_key.update_attributes!(gpg_key_params)
  respond_for_show(:resource => @gpg_key)
end