Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #15068 - Provide a way to select SSL certs for a product
- Loading branch information
1 parent
6c6d2c8
commit 95594cf
Showing
56 changed files
with
983 additions
and
497 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
app/controllers/katello/api/v2/content_credentials_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
module Katello | ||
class Api::V2::ContentCredentialsController < Api::V2::ApiController | ||
include Katello::Concerns::FilteredAutoCompleteSearch | ||
before_action :authorize | ||
before_action :find_organization, :only => [:create, :index, :auto_complete_search] | ||
before_action :find_content_credential, :only => [:show, :update, :destroy, :content, :set_content] | ||
skip_before_action :check_content_type, :only => [:create, :content, :set_content] | ||
|
||
def resource_class | ||
Katello::GpgKey | ||
end | ||
|
||
def_param_group :content_credential do | ||
param :name, :identifier, :action_aware => true, :required => true, :desc => N_("identifier of the content credential") | ||
param :content_type, String, :action_aware => true, :required => true, :desc => N_("type of content") | ||
param :content, String, :action_aware => true, :required => true, :desc => N_("public key block in DER encoding / certificate content") | ||
end | ||
|
||
resource_description do | ||
description <<-DESC | ||
# Description | ||
Content Credentials are used to store credentials like GPG Keys and Certificates for the authentication | ||
to Products / Repositories. | ||
DESC | ||
api_version "v2" | ||
end | ||
|
||
api :GET, "/content_credentials", N_("List content credentials") | ||
param :organization_id, :number, :desc => N_("organization identifier"), :required => true | ||
param :name, String, :desc => N_("name of the Content Credential"), :required => false | ||
param :content_type, String, :desc => N_("type of content"), :required => false | ||
param_group :search, Api::V2::ApiController | ||
def index | ||
respond(:collection => scoped_search(index_relation.uniq, :name, :asc)) | ||
end | ||
|
||
def index_relation | ||
query = GpgKey.readable.where(:organization_id => @organization.id) | ||
query = query.where(:name => params[:name]) if params[:name] | ||
query | ||
end | ||
|
||
api :POST, "/content_credentials", N_("Create a content credential") | ||
param :organization_id, :number, :desc => N_("organization identifier"), :required => true | ||
param_group :content_credential, :as => :create | ||
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 | ||
|
||
content_credential = @organization.gpg_keys.create!(content_credential_params.merge(:content => content)) | ||
respond_for_show(:resource => content_credential) | ||
end | ||
|
||
api :GET, "/content_credentials/:id", N_("Show a content credential") | ||
param :id, :number, :desc => N_("content credential numeric identifier"), :required => true | ||
def show | ||
respond_for_show(:resource => @content_credential) | ||
end | ||
|
||
api :PUT, "/content_credentials/:id", N_("Update a content credential") | ||
param :id, :number, :desc => N_("content credential numeric identifier"), :required => true | ||
param_group :content_credential | ||
def update | ||
@content_credential.update_attributes!(content_credential_params) | ||
respond_for_show(:resource => @content_credential) | ||
end | ||
|
||
api :DELETE, "/content_credentials/:id", N_("Destroy a content credential") | ||
param :id, :number, :desc => N_("content credential numeric identifier"), :required => true | ||
def destroy | ||
@content_credential.destroy | ||
respond_for_destroy | ||
end | ||
|
||
api :GET, "/content_credentials/:id/content", N_("Return the content of a content credential, used directly by yum") | ||
param :id, :number, :required => true | ||
def content | ||
render(:plain => @content_credential.content, :layout => false) | ||
end | ||
|
||
api :POST, "/content_credentials/:id/content", N_("Upload content credential contents") | ||
param :id, :number, :desc => N_("content credential numeric identifier"), :required => true | ||
param :content, File, :desc => N_("file contents"), :required => true | ||
def set_content | ||
filepath = params.try(:[], :content).try(:path) | ||
|
||
if filepath | ||
content = File.open(filepath, "rb") { |file| file.read } | ||
@content_credential.update_attributes!(:content => content) | ||
render :json => {:status => "success"} | ||
else | ||
fail HttpErrors::BadRequest, _("No file uploaded") | ||
end | ||
end | ||
|
||
protected | ||
|
||
def find_content_credential | ||
@content_credential = GpgKey.find(params[:id]) | ||
rescue ActiveRecord::RecordNotFound | ||
raise HttpErrors::NotFound, _("Couldn't find Content Credential '%s'") % params[:id] | ||
end | ||
|
||
def content_credential_params | ||
params.permit(:name, :content_type, :content) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/lib/katello/validators/gpg_key_content_type_validator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Katello | ||
module Validators | ||
class GpgKeyContentTypeValidator < ActiveModel::Validator | ||
def validate(record) | ||
# need to verify, that gpg_key is of GpgKey.content type "gpg_key" and | ||
# ssl_ca_cert, ssl_client_cert, ssl_client_key of GpgKey.content type "cert" | ||
|
||
if !record.gpg_key.blank? && record.gpg_key.content_type != "gpg_key" | ||
record.errors[:gpg_key] << _("Wrong content type submitted.") | ||
end | ||
|
||
if record.instance_of?(Katello::Product) | ||
[:ssl_ca_cert, :ssl_client_cert, :ssl_client_key].each do |cert| | ||
if !record.send(cert).blank? && record.send(cert).content_type != "cert" | ||
record.errors[cert] << _("Wrong content type submitted.") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object false | ||
|
||
extends "katello/api/v2/common/index" |
70 changes: 70 additions & 0 deletions
70
app/views/katello/api/v2/content_credentials/show.json.rabl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
object @resource | ||
|
||
extends 'katello/api/v2/common/identifier' | ||
extends 'katello/api/v2/common/org_reference' | ||
extends 'katello/api/v2/common/timestamps' | ||
|
||
attributes :name | ||
attributes :content_type | ||
attributes :content | ||
|
||
child :products => :products do | ||
attributes :id, :cp_id, :name | ||
node :repository_count do |product| | ||
product.repositories.count | ||
end | ||
child :provider => :provider do | ||
attribute :name | ||
attribute :id | ||
end | ||
end | ||
|
||
child :repositories => :repositories do | ||
attribute :id | ||
attribute :name | ||
|
||
child :product do |_product| | ||
attributes :id, :cp_id, :name | ||
end | ||
end | ||
|
||
child :ssl_ca_products => :ssl_ca_products do | ||
attributes :id, :cp_id, :name | ||
node :repository_count do |product| | ||
product.repositories.count | ||
end | ||
child :provider => :provider do | ||
attribute :name | ||
attribute :id | ||
end | ||
end | ||
|
||
child :ssl_client_products => :ssl_client_products do | ||
attributes :id, :cp_id, :name | ||
node :repository_count do |product| | ||
product.repositories.count | ||
end | ||
child :provider => :provider do | ||
attribute :name | ||
attribute :id | ||
end | ||
end | ||
|
||
child :ssl_key_products => :ssl_key_products do | ||
attributes :id, :cp_id, :name | ||
node :repository_count do |product| | ||
product.repositories.count | ||
end | ||
child :provider => :provider do | ||
attribute :name | ||
attribute :id | ||
end | ||
end | ||
|
||
node :permissions do |content_credential| | ||
{ | ||
:view_content_credenials => content_credential.readable?, | ||
:edit_content_credenials => content_credential.editable?, | ||
:destroy_content_credenials => content_credential.deletable? | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.