Repository navigation
Fixed multiple issues with configuration of Legacy API on 0.x branch #96
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,19 +39,27 @@ def verify_peer=(verify) | |
| end | ||
|
|
||
| def ssl_ca_file=(path) | ||
| @configuration.ssl_ca_file = path | ||
| @configuration[:ssl_ca_file] = path | ||
| end | ||
|
|
||
| def ssl_client=(options) | ||
| if options[:passphrase].nil? | ||
| send(:ssl_client_key=, options[:path]) | ||
| else | ||
| send(:ssl_client_key=, options[:path], options[:passphrase]) | ||
| end | ||
| end | ||
|
|
||
| def ssl_client_key=(path,passphrase=nil) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this method... I'd prefer to keep the initialize a little cleaner, I think we have two options.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pedelman I like the second option better as going with first option would not be semantically correct, we would be expecting two parameters path and passphrase(optional) and always receive one(the hash) in Let me know what key name you prefer or if you have any suggestions. :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I like |
||
| if passphrase.nil? | ||
| @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path)) | ||
| @configuration[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(path)) | ||
| else | ||
| @configuration.ssl_client_key = OpenSSL::PKey::RSA.new(File.read(path), passphrase) | ||
| @configuration[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(path), passphrase) | ||
| end | ||
| end | ||
|
|
||
| def ssl_client_cert=(path) | ||
| @configuration.client_cert = OpenSSL::X509::Certificate.new(File.read(path)) | ||
| @configuration[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(path)) | ||
| end | ||
|
|
||
| def get(path, options = {}, headers = {}) | ||
|
|
@@ -125,6 +133,7 @@ def request_legacy(method, path, options, headers={}) | |
| resource_options = { | ||
| :user => @configuration[:username], | ||
| :password => @configuration[:api_key], | ||
| :verify_ssl => @configuration[:verify_ssl] || OpenSSL::SSL::VERIFY_PEER, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? The default for rest client is to enable peer, and if you want to disable it, you can just use the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I tested the code with only |
||
| :headers => headers | ||
| } | ||
|
|
||
|
|
@@ -133,7 +142,7 @@ def request_legacy(method, path, options, headers={}) | |
| if @configuration[:ssl_client_key] && @configuration[:ssl_client_cert] && @configuration[:ssl_ca_file] | ||
| rest_client = RestClient::Resource.new( | ||
| "#{@configuration[:store_url]}/api/v2#{path}.json", | ||
| :username => @configuration[:username], | ||
| :user => @configuration[:username], | ||
| :password => @configuration[:api_key], | ||
| :ssl_client_cert => @configuration[:ssl_client_cert], | ||
| :ssl_client_key => @configuration[:ssl_client_key], | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this example benefit from having the other SSL options passed in as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedelman That's certainly a good suggestion from production environment point of view where API user is explicitly specifying SSL options. But to connect to BigCommerce through Legacy API we have 2 ways one without supplying SSL options and other with SSL options (even though in both cases SSL is verified). To disable verification we just need
verify_peerand other options are not mandatory.Let me know what you would prefer to go with and we could work on the same.