diff options
author | Ashish Dixit <tundal45@gmail.com> | 2013-12-09 20:34:08 -0600 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2013-12-18 22:30:12 -0800 |
commit | 53dc2e239a539c07ade5a197564076c6513a3684 (patch) | |
tree | e4fe7d80a672fad36d4ad23dcdc9a561bb80e5b3 /lib/bundler/ssl_certs | |
parent | 51374c98da6d7137fec13dd4bc85fc9f443cd83a (diff) | |
download | bundler-53dc2e239a539c07ade5a197564076c6513a3684.tar.gz |
Add a rake task to update SSL Certificates.
Added a rake task under rubygems namespace that updates the SSL
certificates in bundler if they meet either of the following criteria:
a) The filenames do not match that of the certificates in Rubygems
master
b) Rubygems contains an updated certificate
Diffstat (limited to 'lib/bundler/ssl_certs')
-rw-r--r-- | lib/bundler/ssl_certs/certificate_manager.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/bundler/ssl_certs/certificate_manager.rb b/lib/bundler/ssl_certs/certificate_manager.rb new file mode 100644 index 00000000..74850722 --- /dev/null +++ b/lib/bundler/ssl_certs/certificate_manager.rb @@ -0,0 +1,41 @@ +class CertificateManager + BUNDLER_CERTIFICATES_PATH = "lib/bundler/ssl_certs/" + LOCAL_RUBYGEMS_PATH = "tmp/rubygems" + RUBYGEMS_CERTIFICATES_PATH = "#{File.join(LOCAL_RUBYGEMS_PATH, 'lib/rubygems/ssl_certs/')}" + CERTIFICATE_FILE_EXTENSION = ".pem" + + attr_reader :bundler_certificates, :rubygems_certificates + + def initialize + @bundler_certificates = certificate_files(BUNDLER_CERTIFICATES_PATH) + @rubygems_certificates = certificate_files(RUBYGEMS_CERTIFICATES_PATH) + end + + def up_to_date? + same_filenames = (bundler_certificates == rubygems_certificates) + same_certificates = false + + if same_filenames + same_certificates = bundler_certificates.all? do |filename| + FileUtils.compare_file(File.join(BUNDLER_CERTIFICATES_PATH, filename), File.join(RUBYGEMS_CERTIFICATES_PATH, filename)) + end + end + + same_filenames && same_certificates + end + + def update! + unless up_to_date? + FileUtils.rm Dir.glob(File.join(BUNDLER_CERTIFICATES_PATH, "*#{CERTIFICATE_FILE_EXTENSION}")) + FileUtils.cp_r Dir.glob(File.join(RUBYGEMS_CERTIFICATES_PATH, "*#{CERTIFICATE_FILE_EXTENSION}")), BUNDLER_CERTIFICATES_PATH + end + end + + private + + def certificate_files(path) + Dir.entries(path).select do |filename| + filename.end_with?(CERTIFICATE_FILE_EXTENSION) + end.sort + end +end |