Skip to content

Instantly share code, notes, and snippets.

@mccun934
Last active February 4, 2021 16:27
Show Gist options
  • Save mccun934/720e9e159cdc447d7f0cb8c476faf6ec to your computer and use it in GitHub Desktop.
Save mccun934/720e9e159cdc447d7f0cb8c476faf6ec to your computer and use it in GitHub Desktop.
namespace :katello do
desc "Export the stored x509 certificates from Pulp's configuration"
task :export_repo_certs => ["environment"] do
User.current = User.anonymous_api_admin
org_name = ENV['ORG_NAME']
org = Organization.find_by name: org_name
path = Dir.mktmpdir("pulp-certs")
Katello::Repository.yum_type.in_default_view.in_organization(org).each do |repo|
filename = File.join(path, "#{repo.product.label}-#{repo.label}")
importer = repo.pulp_repo_facts['importers'].find{|i| i['id'] == 'yum_importer'}
if importer && importer['config']['ssl_client_cert']
combined = importer['config']['ssl_client_cert'] + importer['config']['ssl_client_key']
File.open(filename, 'w'){|file| file.write(combined) }
puts "Wrote #{filename}"
end
end
puts "All repo certs written to #{path}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment