Class: Katello::Api::V2::ContentCredentialsController

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

#contentObject



84
85
86
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 84

def content
  render(:plain => @content_credential.content, :layout => false)
end

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 47

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

  content = nil
  if filepath
    content = File.read(filepath, mode: 'rb')
  else
    content = params[:content]
  end

  content_credential = @organization.gpg_keys.create!(content_credential_params.merge(:content => content))
  respond_for_create(:resource => content_credential)
end

#destroyObject



77
78
79
80
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 77

def destroy
  @content_credential.destroy
  respond_for_destroy
end

#indexObject



33
34
35
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 33

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

#index_relationObject



37
38
39
40
41
42
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 37

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

#resource_classObject



8
9
10
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 8

def resource_class
  Katello::ContentCredential
end

#set_contentObject



91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/katello/api/v2/content_credentials_controller.rb', line 91

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

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

#showObject



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

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

#updateObject



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

def update
  sync_task(::Actions::Katello::ContentCredential::Update, @content_credential, content_credential_params.to_h)
  respond_for_show(:resource => @content_credential)
end