From 474e9b92734342e377d4e97150fda5725559cb57 Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Thu, 31 Aug 2023 12:36:32 -0500 Subject: [PATCH 1/2] add failing spec --- lib/deploy/activate.rb | 73 ++++++++++++++++++-------------- spec/lib/deploy/activate_spec.rb | 29 +++++++++++++ 2 files changed, 70 insertions(+), 32 deletions(-) diff --git a/lib/deploy/activate.rb b/lib/deploy/activate.rb index 537d93fbb93..a78d6317829 100644 --- a/lib/deploy/activate.rb +++ b/lib/deploy/activate.rb @@ -6,6 +6,10 @@ module Deploy class Activate + FILES_TO_LINK = + %w[agencies iaa_gtcs iaa_orders iaa_statuses integration_statuses integrations + partner_account_statuses partner_accounts service_providers] + attr_reader :logger, :s3_client def initialize( @@ -32,34 +36,11 @@ def run ) end - private - - # Clone the private-but-not-secret git repo - def clone_idp_config - private_git_repo_url = ENV.fetch( - 'IDP_private_config_repo', - 'git@github.com:18F/identity-idp-config.git', - ) - checkout_dir = File.join(root, idp_config_checkout_name) - - cmd = ['git', 'clone', '--depth', '1', '--branch', 'main', private_git_repo_url, checkout_dir] - logger.info('+ ' + cmd.join(' ')) - Subprocess.check_call(cmd) - end - - def idp_config_checkout_name - 'identity-idp-config' - end - # Set up symlinks into identity-idp-config needed for the idp to make use # of relevant config and assets. # def setup_idp_config_symlinks - files_to_link = - %w[agencies iaa_gtcs iaa_orders iaa_statuses integration_statuses integrations - partner_account_statuses partner_accounts service_providers] - - files_to_link.each do |file| + FILES_TO_LINK.each do |file| symlink_verbose( File.join(root, idp_config_checkout_name, "#{file}.yml"), File.join(root, "config/#{file}.yml"), @@ -73,7 +54,6 @@ def setup_idp_config_symlinks File.join(root, 'certs/sp'), ) - idp_logos_dir = File.join(root, 'public/assets/sp-logos') FileUtils.mkdir_p(idp_logos_dir) # Invalid symlinks can cause issues in the build process, so this step iterates through the @@ -87,10 +67,9 @@ def setup_idp_config_symlinks # Inject the logo files into the app's asset folder. deploy/activate is # run before deploy/build-post-config, so these will be picked up by the # rails asset pipeline. - logos_dir = File.join(root, idp_config_checkout_name, 'public/assets/images/sp-logos') - Dir.entries(logos_dir).each do |name| + Dir.entries(config_logos_dir).each do |name| next if name.start_with?('.') - target = File.join(logos_dir, name) + target = File.join(config_logos_dir, name) link = File.join(root, 'app/assets/images/sp-logos', name) symlink_verbose(target, link, force: true) link = File.join(root, 'public/assets/sp-logos', name) @@ -98,6 +77,40 @@ def setup_idp_config_symlinks end end + def root + @root || File.expand_path('../../../', __FILE__) + end + + def idp_logos_dir + File.join(root, 'public/assets/sp-logos') + end + + def config_logos_dir + File.join(checkout_dir, 'public/assets/images/sp-logos') + end + + def checkout_dir + File.join(root, idp_config_checkout_name) + end + + private + + # Clone the private-but-not-secret git repo + def clone_idp_config + private_git_repo_url = ENV.fetch( + 'IDP_private_config_repo', + 'git@github.com:18F/identity-idp-config.git', + ) + + cmd = ['git', 'clone', '--depth', '1', '--branch', 'main', private_git_repo_url, checkout_dir] + logger.info('+ ' + cmd.join(' ')) + Subprocess.check_call(cmd) + end + + def idp_config_checkout_name + 'identity-idp-config' + end + def symlink_verbose(dest, link, force: false) logger.info("symlink: #{link.inspect} => #{dest.inspect}") File.unlink(link) if force && File.exist?(link) @@ -124,10 +137,6 @@ def default_logger logger end - def root - @root || File.expand_path('../../../', __FILE__) - end - def geolocation_db_path File.join(root, 'geo_data/GeoLite2-City.mmdb') end diff --git a/spec/lib/deploy/activate_spec.rb b/spec/lib/deploy/activate_spec.rb index a857a4670f1..02b53c49247 100644 --- a/spec/lib/deploy/activate_spec.rb +++ b/spec/lib/deploy/activate_spec.rb @@ -127,4 +127,33 @@ expect { subject.run }.to raise_error(Net::OpenTimeout) end end + + describe '#setup_idp_config_symlinks' do + context 'with stale identity-idp-config symlinks' do + it 'deletes stale symlinks' do + setup_identity_idp_config(subject) + FileUtils.ln_s( + 'fake', + subject.idp_logos_dir, + force: true, + ) + + subject.setup_idp_config_symlinks + + expect(File.exist?('fake')).to eq false + end + end + end + + def setup_identity_idp_config(subject) + FileUtils.mkdir_p(subject.checkout_dir) + FileUtils.mkdir_p(subject.idp_logos_dir) + FileUtils.mkdir_p(subject.config_logos_dir) + # Cloned config is symlinked into the root config/ folder + FileUtils.mkdir_p(File.join(subject.root, 'config')) + + Deploy::Activate::FILES_TO_LINK.each do |file| + FileUtils.touch(File.join(subject.checkout_dir, "#{file}.yml")) + end + end end From 93abde3b7e172fe83564f49d3846fc65bc07137e Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Thu, 31 Aug 2023 12:37:19 -0500 Subject: [PATCH 2/2] Call correct method to delete symlink changelog: Bug Fixes, Service Provider Setup, Call correct method to delete symlink --- lib/deploy/activate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/deploy/activate.rb b/lib/deploy/activate.rb index a78d6317829..4bb9c1ad577 100644 --- a/lib/deploy/activate.rb +++ b/lib/deploy/activate.rb @@ -61,7 +61,7 @@ def setup_idp_config_symlinks Dir.entries(idp_logos_dir).each do |name| next if name.start_with?('.') target = File.join(idp_logos_dir, name) - File.rm(target) if File.symlink?(target) && !File.file?(target) + FileUtils.rm(target) if File.symlink?(target) && !File.file?(target) end # Public assets: sp-logos # Inject the logo files into the app's asset folder. deploy/activate is