Skip to content
This repository was archived by the owner on Jul 30, 2019. It is now read-only.
Open
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
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
micropurchase
25 changes: 0 additions & 25 deletions app/credentials/c2_credentials.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/credentials/concerns/user_provided_service.rb

This file was deleted.

13 changes: 0 additions & 13 deletions app/credentials/data_dot_gov_credentials.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/credentials/github_credentials.rb

This file was deleted.

21 changes: 0 additions & 21 deletions app/credentials/new_relic_credentials.rb

This file was deleted.

13 changes: 0 additions & 13 deletions app/credentials/secrets.rb

This file was deleted.

37 changes: 0 additions & 37 deletions app/credentials/smtp_credentials.rb

This file was deleted.

13 changes: 0 additions & 13 deletions app/credentials/tock_credentials.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def vendor_started_work(auction:)
to: ADMIN_EMAIL_ADDRESS,
subject: I18n.t('mailers.admin_mailer.vendor_started_work.subject',
auction_name: @auction.title),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -27,7 +27,7 @@ def vendor_finished_work(auction:)
subject: I18n.t('mailers.admin_mailer.vendor_finished_work.subject',
winner_name: @winner_name,
auction_name: @auction.title),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/auction_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def losing_bidder_notification(bidder:, auction:)
mail(
to: bidder.email,
subject: I18n.t('mailers.auction_mailer.losing_bidder_notification.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -17,7 +17,7 @@ def auction_accepted_customer_notification(auction:)
mail(
to: customer.email,
subject: I18n.t('mailers.auction_mailer.auction_accepted_customer_notification.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand Down
14 changes: 7 additions & 7 deletions app/mailers/winning_bidder_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def auction_ended(bidder:, auction:)
mail(
to: bidder.email,
subject: I18n.t('mailers.winning_bidder_mailer.auction_ended.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -17,7 +17,7 @@ def auction_accepted(auction:)
mail(
to: @winning_bid.bidder.email,
subject: I18n.t('mailers.winning_bidder_mailer.auction_accepted.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -29,7 +29,7 @@ def auction_accepted_missing_payment_method(auction:)
mail(
to: @winning_bid.bidder.email,
subject: I18n.t('mailers.winning_bidder_mailer.auction_accepted_missing_payment_method.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -42,7 +42,7 @@ def auction_rejected(auction:)
mail(
to: @winning_bid.bidder.email,
subject: I18n.t('mailers.winning_bidder_mailer.auction_rejected.subject'),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -56,7 +56,7 @@ def auction_not_delivered(auction:)
to: @winning_bid.bidder.email,
subject: I18n.t('mailers.winning_bidder_mailer.auction_not_delivered.subject',
auction_title: @auction.title),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -71,7 +71,7 @@ def auction_paid_default_pcard(auction:)
'mailers.winning_bidder_mailer.auction_paid_default_pcard.subject',
auction_title: @auction.title
),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand All @@ -86,7 +86,7 @@ def auction_paid_other_pcard(auction:)
'mailers.winning_bidder_mailer.auction_paid_other_pcard.subject',
auction_title: @auction.title
),
from: SMTPCredentials.default_from,
from: Credentials.smtp_default_from,
reply_to: 'micropurchase@gsa.gov'
)
end
Expand Down
25 changes: 25 additions & 0 deletions app/models/credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Credentials
def get(*name)
type_delegate.get(*name)
end

def self.get(*name)
new.get(*name)
end

def self.map(method_name, options)
define_singleton_method(method_name) do
new.get(options[:to])
end
end

private

def type_delegate
@credentials_delegate ||= local? ? Local.new : CloudFoundry.new
end

def local?
Rails.env == 'development' || Rails.env == 'test'
end
end
19 changes: 19 additions & 0 deletions app/models/credentials/cloud_foundry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Credentials::CloudFoundry
attr_reader :data

def get(namespace, key = nil)
service(namespace)[key] || local(namespace, key)
end

def service(namespace)
services.find { |service| service['name'] == namespace } || { }
end

def services
@services ||= JSON.parse(ENV['VCAP_SERVICES'])['user-provided']
end

def local(namespace, key)
key ? Local.new.get(namespace, key) : Credentials::Local.new.get(namespace)
end
end
11 changes: 11 additions & 0 deletions app/models/credentials/local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Credentials::Local
def get(*name)
ENV[normalize(*name)]
end

private

def normalize(*names)
names.join('_').underscore.upcase
end
end
2 changes: 1 addition & 1 deletion app/models/sam_account_reckoner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def sam_status
end

def client
@client ||= Samwise::Client.new(api_key: DataDotGovCredentials.api_key)
@client ||= Samwise::Client.new(api_key: Credentials.data_dot_gov_api_key)
end

def vendor_summary
Expand Down
2 changes: 1 addition & 1 deletion app/models/winning_bidder_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ def winning_bid
end

def client
@client ||= Samwise::Client.new(api_key: DataDotGovCredentials.api_key)
@client ||= Samwise::Client.new(api_key: Credentials.data_dot_gov_api_key)
end
end
10 changes: 5 additions & 5 deletions app/services/c2_api_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def proposal_json(auction)
end

def c2_proposal_path(auction)
auction.c2_proposal_url.gsub("#{C2Credentials.host}/", "")
auction.c2_proposal_url.gsub("#{Credentials.c2_host}/", "")
end

def configure_c2_client
C2::Client.new(
oauth_key: C2Credentials.oauth_key,
oauth_secret: C2Credentials.oauth_secret,
host: C2Credentials.host,
debug: ENV.fetch('C2_DEBUG', false)
oauth_key: Credentials.get('micropurchase-c2', 'oauth_key'),
oauth_secret: Credentials.get('micropurchase-c2', 'oauth_secret'),
host: Credentials.c2_host,
debug: ENV.fetch('C2_DEBUG', false)
)
end
end
2 changes: 1 addition & 1 deletion app/services/create_c2_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def perform
attr_reader :auction

def proposal_url
"#{C2Credentials.host}/proposals/#{proposal.id}"
"#{Credentials.c2_host}/proposals/#{proposal.id}"
end

def proposal
Expand Down
8 changes: 6 additions & 2 deletions app/services/tock_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ def data

def request
RestClient.get(
TOCK_PROJECTS,
'Authorization' => "Token #{TockCredentials.api_token}"
TOCK_PROJECTS, 'Authorization' => "Token #{token}"
)
end

def token
Credentials.get('micropurchase-tock', 'api_token') ||
Credentials.get('micropurchase-tock', 'api_key')
end
end
Loading