Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAT-1757] Replacing VSAC Username/Password with API Key in VSAC Calls #114

Merged
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
5 changes: 2 additions & 3 deletions lib/measure-loader/vsac_value_set_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ def initialize(options)
options.symbolize_keys!
@vsac_options = options[:options]
@vsac_ticket_granting_ticket = options[:ticket_granting_ticket]
@vsac_username = options[:username]
@vsac_password = options[:password]
@vsac_api_key = options[:api_key]
@vs_model_cache = {}
end

Expand Down Expand Up @@ -48,7 +47,7 @@ def retrieve_and_modelize_value_sets_from_vsac(value_sets)

def load_api
return @api if @api.present?
@api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: @vsac_ticket_granting_ticket, username: @vsac_username, password: @vsac_password)
@api = Util::VSAC::VSACAPI.new(config: APP_CONFIG['vsac'], ticket_granting_ticket: @vsac_ticket_granting_ticket, api_key: @vsac_api_key)
return @api
end

Expand Down
26 changes: 12 additions & 14 deletions lib/util/vsac_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module VSAC
class VSACError < StandardError
end

# Error represnting a not found response from the API. Includes OID for reporting to user.
# Error representing a not found response from the API. Includes OID for reporting to user.
class VSNotFoundError < VSACError
attr_reader :oid
def initialize(oid)
Expand All @@ -23,15 +23,15 @@ def initialize
end
end

# Error represnting a program not found response from the API.
# Error representing a program not found response from the API.
class VSACProgramNotFoundError < VSACError
attr_reader :oid
def initialize(program)
super("VSAC Program #{program} does not exist.")
end
end

# Error represnting a response from the API that had no concepts.
# Error representing a response from the API that had no concepts.
class VSEmptyError < VSACError
attr_reader :oid
def initialize(oid)
Expand All @@ -50,14 +50,14 @@ def initialize
# Raised when the user credentials were invalid.
class VSACInvalidCredentialsError < VSACError
def initialize
super('VSAC ULMS credentials are invalid.')
super('VSAC UMLS credentials are invalid.')
end
end

# Raised when a call requiring auth is attempted when no ticket_granting_ticket or credentials were provided.
class VSACNoCredentialsError < VSACError
def initialize
super('VSAC ULMS credentials were not provided.')
super('VSAC UMLS credentials were not provided.')
end
end

Expand Down Expand Up @@ -93,7 +93,7 @@ def initialize(options)
end

# if a ticket_granting_ticket was passed in, check it and raise errors if found
# username and password will be ignored
# VSAC API Key will be ignored
if !options[:ticket_granting_ticket].nil?
provided_ticket_granting_ticket = options[:ticket_granting_ticket]
if provided_ticket_granting_ticket[:ticket].nil? || provided_ticket_granting_ticket[:expires].nil?
Expand All @@ -105,9 +105,9 @@ def initialize(options)
@ticket_granting_ticket = { ticket: provided_ticket_granting_ticket[:ticket],
expires: provided_ticket_granting_ticket[:expires] }

# if username and password were provided use them to get a ticket granting ticket
elsif !options[:username].nil? && !options[:password].nil?
@ticket_granting_ticket = get_ticket_granting_ticket(options[:username], options[:password])
# if api key was provided use it to get a ticket granting ticket
elsif !options[:api_key].nil?
@ticket_granting_ticket = get_ticket_granting_ticket(options[:api_key])
end
end

Expand Down Expand Up @@ -304,13 +304,11 @@ def create_service_ticket_request
params: { service: TICKET_SERVICE_PARAM})
end

# Use your username and password to retrive a ticket granting ticket from VSAC
def get_ticket_granting_ticket(username, password)
# Use your API Key to retrive a ticket granting ticket from VSAC
def get_ticket_granting_ticket(api_key)
response = Typhoeus.post(
"#{@config[:auth_url]}/Ticket",
# looks like typheous sometimes switches the order of username/password when encoding
# which vsac cant handle (!?), so encode first
body: URI.encode_www_form(username: username, password: password)
body: URI.encode_www_form(apikey: api_key)
)
raise VSACInvalidCredentialsError.new if response.response_code == 401
validate_http_status(response.response_code)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_interactions:
uri: https://vsac.nlm.nih.gov/vsac/ws/Ticket
body:
encoding: US-ASCII
string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>
string: apikey=<VSAC_API_KEY>
headers:
User-Agent:
- Typhoeus - https://github.com/typhoeus/typhoeus
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/measure__population_titles.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/measure__test_cms_id.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/measure__test_measure.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_interactions:
uri: https://vsac.nlm.nih.gov/vsac/ws/Ticket
body:
encoding: US-ASCII
string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>
string: apikey=<VSAC_API_KEY>
headers:
User-Agent:
- Typhoeus - https://github.com/typhoeus/typhoeus
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vs_loading_draft_profile.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vs_loading_draft_verion.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vs_loading_profile.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vs_loading_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_interactions:
uri: https://vsac.nlm.nih.gov/vsac/ws/Ticket
body:
encoding: US-ASCII
string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>
string: apikey=<VSAC_API_KEY>
headers:
User-Agent:
- Typhoeus - https://github.com/typhoeus/typhoeus
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vs_loading_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_interactions:
uri: https://vsac.nlm.nih.gov/vsac/ws/Ticket
body:
encoding: US-ASCII
string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>
string: apikey=<VSAC_API_KEY>
headers:
User-Agent:
- Typhoeus - https://github.com/typhoeus/typhoeus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ http_interactions:
uri: https://vsac.nlm.nih.gov/vsac/ws/Ticket
body:
encoding: US-ASCII
string: username=<VSAC_USERNAME>&password=<VSAC_PASSWORD>
string: apikey=<VSAC_API_KEY>
headers:
User-Agent:
- Typhoeus - https://github.com/typhoeus/typhoeus
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vsac_auth_bad_credentials.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/fixtures/vcr_cassettes/vsac_auth_good_credentials.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading