app/controllers/katello/api/v2/repositories_controller.rb in katello-3.1.0.1 vs app/controllers/katello/api/v2/repositories_controller.rb in katello-3.2.0.rc1
- old
+ new
@@ -1,26 +1,26 @@
module Katello
class Api::V2::RepositoriesController < Api::V2::ApiController
include Katello::Concerns::FilteredAutoCompleteSearch
- before_filter :find_optional_organization, :only => [:index, :auto_complete_search]
- before_filter :find_product, :only => [:index, :auto_complete_search]
- before_filter :find_product_for_create, :only => [:create]
- before_filter :find_organization_from_product, :only => [:create]
- before_filter :find_repository, :only => [:show, :update, :destroy, :sync, :export,
+ before_action :find_optional_organization, :only => [:index, :auto_complete_search]
+ before_action :find_product, :only => [:index, :auto_complete_search]
+ before_action :find_product_for_create, :only => [:create]
+ before_action :find_organization_from_product, :only => [:create]
+ before_action :find_repository, :only => [:show, :update, :destroy, :sync, :export,
:remove_content, :upload_content,
:import_uploads, :gpg_key_content]
- before_filter :find_content, :only => :remove_content
- before_filter :find_organization_from_repo, :only => [:update]
- before_filter :find_gpg_key, :only => [:create, :update]
- before_filter :error_on_rh_product, :only => [:create]
- before_filter :error_on_rh_repo, :only => [:destroy]
+ before_action :find_content, :only => :remove_content
+ before_action :find_organization_from_repo, :only => [:update]
+ before_action :find_gpg_key, :only => [:create, :update]
+ before_action :error_on_rh_product, :only => [:create]
+ before_action :error_on_rh_repo, :only => [:destroy]
- skip_before_filter :authorize, :only => [:sync_complete, :gpg_key_content]
- skip_before_filter :require_org, :only => [:sync_complete]
- skip_before_filter :require_user, :only => [:sync_complete]
- skip_before_filter :check_content_type, :only => [:upload_content]
+ skip_before_action :authorize, :only => [:sync_complete, :gpg_key_content]
+ skip_before_action :require_org, :only => [:sync_complete]
+ skip_before_action :require_user, :only => [:sync_complete]
+ skip_before_action :check_content_type, :only => [:upload_content]
def_param_group :repo do
param :name, String, :required => true
param :label, String, :required => false
param :product_id, :number, :required => true, :desc => N_("Product the repository belongs to")
@@ -30,24 +30,27 @@
param :content_type, RepositoryTypeManager.creatable_repository_types.keys, :required => true, :desc => N_("type of repo (either 'yum', 'puppet', 'docker', or 'ostree')")
param :checksum_type, String, :desc => N_("checksum of the repository, currently 'sha1' & 'sha256' are supported.")
param :docker_upstream_name, String, :desc => N_("name of the upstream docker repository")
param :download_policy, ["immediate", "on_demand", "background"], :desc => N_("download policy for yum repos (either 'immediate', 'on_demand', or 'background')")
param :mirror_on_sync, :bool, :desc => N_("true if this repository when synced has to be mirrored from the source and stale rpms removed.")
+ param :verify_ssl_on_sync, :bool, :desc => N_("if true, Katello will verify the upstream url's SSL certifcates are signed by a trusted CA.")
end
api :GET, "/repositories", N_("List of enabled repositories")
api :GET, "/content_views/:id/repositories", N_("List of repositories for a content view")
+ api :GET, "/organizations/:organization_id/repositories", N_("List of repositories in an organization")
api :GET, "/organizations/:organization_id/environments/:environment_id/repositories", _("List repositories in the environment")
api :GET, "/products/:product_id/repositories", N_("List of repositories for a product")
api :GET, "/environments/:environment_id/products/:product_id/repositories", N_("List of repositories belonging to a product in an environment")
param :organization_id, :number, :desc => N_("ID of an organization to show repositories in")
param :product_id, :number, :desc => N_("ID of a product to show repositories of")
param :environment_id, :number, :desc => N_("ID of an environment to show repositories in")
param :content_view_id, :number, :desc => N_("ID of a content view to show repositories in")
param :content_view_version_id, :number, :desc => N_("ID of a content view version to show repositories in")
param :erratum_id, String, :desc => N_("Id of an erratum to find repositories that contain the erratum")
param :rpm_id, String, :desc => N_("Id of a package to find repositories that contain the rpm")
+ param :ostree_branch_id, String, :desc => N_("Id of an ostree branch to find repositories that contain that branch")
param :library, :bool, :desc => N_("show repositories in Library and the default content view")
param :content_type, RepositoryTypeManager.repository_types.keys, :desc => N_("limit to only repositories of this type")
param :name, String, :desc => N_("name of the repository"), :required => false
param :available_for, String, :desc => N_("interpret specified object to return only Repositories that can be associated with specified object. Only 'content_view' is supported."),
:required => false
@@ -69,10 +72,14 @@
if params[:rpm_id]
query = query.joins(:rpms).where("#{Rpm.table_name}.id" => Rpm.with_identifiers(params[:rpm_id]))
end
+ if params[:ostree_branch_id]
+ query = query.joins(:ostree_branches).where("#{OstreeBranch.table_name}.id" => OstreeBranch.with_identifiers(params[:ostree_branch_id]))
+ end
+
if params[:puppet_module_id]
query = query
.joins(:puppet_modules)
.where("#{PuppetModule.table_name}.id" => PuppetModule.with_identifiers(params[:puppet_module_id]))
end
@@ -137,10 +144,12 @@
repository = @product.add_repo(repo_params[:label], repo_params[:name], repo_params[:url],
repo_params[:content_type], unprotected,
gpg_key, repository_params[:checksum_type], repo_params[:download_policy])
repository.docker_upstream_name = repo_params[:docker_upstream_name] if repo_params[:docker_upstream_name]
repository.mirror_on_sync = ::Foreman::Cast.to_bool(repo_params[:mirror_on_sync]) if repo_params.key?(:mirror_on_sync)
+ repository.verify_ssl_on_sync = ::Foreman::Cast.to_bool(repo_params[:verify_ssl_on_sync]) if repo_params.key?(:verify_ssl_on_sync)
+
sync_task(::Actions::Katello::Repository::Create, repository, false, true)
repository = Repository.find(repository.id)
respond_for_show(:resource => repository)
end
@@ -210,10 +219,11 @@
param :checksum_type, String, :desc => N_("checksum of the repository, currently 'sha1' & 'sha256' are supported.'")
param :url, String, :desc => N_("the feed url of the original repository ")
param :docker_upstream_name, String, :desc => N_("name of the upstream docker repository")
param :download_policy, ["immediate", "on_demand", "background"], :desc => N_("download policy for yum repos (either 'immediate', 'on_demand', or 'background')")
param :mirror_on_sync, :bool, :desc => N_("true if this repository when synced has to be mirrored from the source and stale rpms removed.")
+ param :verify_ssl_on_sync, :bool, :desc => N_("if true, Katello will verify the upstream url's SSL certifcates are signed by a trusted CA.")
def update
repo_params = repository_params
sync_task(::Actions::Katello::Repository::Update, @repository, repo_params)
respond_for_show(:resource => @repository)
end
@@ -292,20 +302,49 @@
)
end
api :PUT, "/repositories/:id/import_uploads", N_("Import uploads into a repository")
param :id, :identifier, :required => true, :desc => N_("Repository id")
- param :upload_ids, Array, :required => true, :desc => N_("Array of upload ids to import")
+ param :upload_ids, Array, :desc => N_("Array of upload ids to import"), :deprecated => true
+ param :uploads, Array, :desc => N_("Array of uploads to import") do
+ param 'id', String, :required => true
+ param 'size', String
+ param 'checksum', String
+ param 'name', String
+ end
def import_uploads
- params[:upload_ids].each do |upload_id|
- begin
- sync_task(::Actions::Katello::Repository::ImportUpload, @repository, upload_id)
- rescue => e
- raise HttpErrors::BadRequest, e.message
+ if params['upload_ids'].empty? && params['uploads'].empty?
+ fail HttpErrors::BadRequest, _('No upload param specified. Either uploads or upload_ids (deprecated) is required.')
+ end
+
+ if params.key?(:upload_ids)
+ Foreman::Deprecation.api_deprecation_warning("The parameter upload_ids will be removed in Katello 3.3. Please update to use the uploads parameter.")
+
+ params[:upload_ids].each do |upload_id|
+ begin
+ sync_task(::Actions::Katello::Repository::ImportUpload, @repository, upload_id)
+ rescue => e
+ raise HttpErrors::BadRequest, e.message
+ end
end
end
+ if params.key?(:uploads)
+ params[:uploads].each do |upload|
+ begin
+ sync_task(
+ ::Actions::Katello::Repository::ImportUpload,
+ @repository,
+ upload['id'],
+ upload.except('id')
+ )
+ rescue => e
+ raise HttpErrors::BadRequest, e.message
+ end
+ end
+ end
+
render :nothing => true
end
# returns the content of a repo gpg key, used directly by yum
# we don't want to authenticate, authorize etc, trying to distinguish between a yum request and normal api request
@@ -341,10 +380,10 @@
fail HttpErrors::NotFound, _("Couldn't find gpg key '%s'") % params[:gpg_key_id] if @gpg_key.nil?
end
end
def repository_params
- keys = [:download_policy, :mirror_on_sync]
+ keys = [:download_policy, :mirror_on_sync, :verify_ssl_on_sync]
keys += [:label, :content_type] if params[:action] == "create"
if params[:action] == 'create' || @repository.custom?
keys += [:url, :gpg_key_id, :unprotected, :name, :checksum_type, :docker_upstream_name]
end
params.require(:repository).permit(*keys)