Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 42 additions & 33 deletions lib/deploy/activate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"),
Expand All @@ -73,31 +54,63 @@ 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
# sp-logos directory in the IDP to delete any broken 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
# 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)
symlink_verbose(target, link, force: true)
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)
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/deploy/activate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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