From 98ce4c578f0435105944492451d5f9d376276e61 Mon Sep 17 00:00:00 2001 From: Andrew Gearhart Date: Fri, 25 Jan 2019 14:44:39 -0500 Subject: [PATCH] etda hostname construction for workflow or explore --- .gitignore | 2 +- .rubocop_todo.yml | 1 + lib/etda_utilities.rb | 1 + lib/etda_utilities/hosts.rb | 43 ++++++++++++++++++++++ spec/lib/etda_utilities_hosts_spec.rb | 53 +++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 lib/etda_utilities/hosts.rb create mode 100755 spec/lib/etda_utilities_hosts_spec.rb diff --git a/.gitignore b/.gitignore index b04a8c8..b213c5f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ /pkg/ /spec/reports/ /tmp/ - +.idea # rspec failure tracking .rspec_status diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 44acdbc..5861265 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -93,6 +93,7 @@ RSpec/MultipleExpectations: RSpec/NamedSubject: Exclude: - 'spec/lib/etda_utilities_etda_file_paths_spec.rb' + - 'spec/lib/etda_utilities_hosts_spec.rb' # Offense count: 9 # Configuration parameters: Strict, EnforcedStyle. diff --git a/lib/etda_utilities.rb b/lib/etda_utilities.rb index 2aa14ac..7121b9f 100755 --- a/lib/etda_utilities.rb +++ b/lib/etda_utilities.rb @@ -7,4 +7,5 @@ module EtdaUtilities require 'etda_utilities/partner' require 'etda_utilities/access_level' require 'etda_utilities/etda_file_paths' + require 'etda_utilities/hosts' end diff --git a/lib/etda_utilities/hosts.rb b/lib/etda_utilities/hosts.rb new file mode 100755 index 0000000..c75f3ef --- /dev/null +++ b/lib/etda_utilities/hosts.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module EtdaUtilities + class Hosts + def workflow_submit_host(partner, environment = 'prod') + host_builder(partner, environment, true) + end + + def explore_host(partner, environment = 'prod') + host_builder(partner, environment, false) + end + + private + + def host_builder(partner, environment, is_workflow) + return nil if partner.nil? + return 'localhost' if environment == 'development' + location_environment = "#{host_application(is_workflow)}-#{environment}" if environment != 'prod' + "#{host_prefix(is_workflow)}#{partner_host(partner)}#{location_environment}.libraries.psu.edu" + end + + def host_prefix(is_workflow = false) + return '' unless is_workflow + 'submit-' + end + + def host_application(is_workflow = false) + return '' if is_workflow + '-explore' + end + + def partner_host(partner) + case partner + when 'graduate' + "etda" + when 'honors' + "honors" + when 'milsch' + "millennium-scholars" + end + end + end +end diff --git a/spec/lib/etda_utilities_hosts_spec.rb b/spec/lib/etda_utilities_hosts_spec.rb new file mode 100755 index 0000000..19bb969 --- /dev/null +++ b/spec/lib/etda_utilities_hosts_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +RSpec.describe EtdaUtilities::Hosts, type: :model do + describe 'Hosts' do + describe '#workflow_submit_host' do + it 'returns the correct production host for workflow graduate' do + expect(subject.workflow_submit_host('graduate')).to eq('submit-etda.libraries.psu.edu') + end + it 'returns the correct production host for workflow honors' do + expect(subject.workflow_submit_host('honors')).to eq('submit-honors.libraries.psu.edu') + end + it 'returns the correct production host for workflow millennium scholars' do + expect(subject.workflow_submit_host('milsch')).to eq('submit-millennium-scholars.libraries.psu.edu') + end + it 'returns the correct QA host for workflow graduate' do + expect(subject.workflow_submit_host('graduate', 'qa')).to eq('submit-etda-qa.libraries.psu.edu') + end + it 'returns the correct QA host for workflow honors' do + expect(subject.workflow_submit_host('honors', 'qa')).to eq('submit-honors-qa.libraries.psu.edu') + end + it 'returns the correct QA host for workflow millennium scholars' do + expect(subject.workflow_submit_host('milsch', 'qa')).to eq('submit-millennium-scholars-qa.libraries.psu.edu') + end + it 'returns the correct host for workflow if environment is development' do + expect(subject.workflow_submit_host('graduate', 'development')).to eq('localhost') + end + end + + describe '#explore_host' do + it 'returns the correct production host for explore graduate' do + expect(subject.explore_host('graduate')).to eq('etda.libraries.psu.edu') + end + it 'returns the correct production host for explore honors' do + expect(subject.explore_host('honors')).to eq('honors.libraries.psu.edu') + end + it 'returns the correct production host for explore millennium scholars' do + expect(subject.explore_host('milsch')).to eq('millennium-scholars.libraries.psu.edu') + end + it 'returns the correct QA host for explore graduate' do + expect(subject.explore_host('graduate', 'qa')).to eq('etda-explore-qa.libraries.psu.edu') + end + it 'returns the correct QA host for explore honors' do + expect(subject.explore_host('honors', 'qa')).to eq('honors-explore-qa.libraries.psu.edu') + end + it 'returns the correct QA host for explore millennium scholars' do + expect(subject.explore_host('milsch', 'qa')).to eq('millennium-scholars-explore-qa.libraries.psu.edu') + end + it 'returns the correct host for explore if environment is development' do + expect(subject.explore_host('graduate', 'development')).to eq('localhost') + end + end + end +end