Skip to content

Commit

Permalink
Merge pull request #97 from sanger/dpl-243-upgrade-to-https
Browse files Browse the repository at this point in the history
Prerelease for use_ssl: true
  • Loading branch information
harrietc52 authored Jan 25, 2022
2 parents 63f2b04 + 603cf06 commit 3ccf42d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ["2.5", "2.6", "2.7", "3.0"]
ruby: ["2.7", "3.0", "3.1"]
name: Ruby Test ${{ matrix.ruby }}

steps:
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: "3.0"
bundler-cache:
true # Runs bundle install and caches gems. See the ruby_test.yml
# example if you need more control over bundler.
Expand Down
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ inherit_from: .rubocop_todo.yml
#
# See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: "2.7"
Style/ClassAndModuleChildren:
Enabled: false
Layout/LineLength:
Max: 120
AutoCorrect: true
Naming/FileName:
Exclude:
- 'lib/sequencescape-api.rb'
- "lib/sequencescape-api.rb"

# Pending Cops
Lint/DuplicateBranch: # (new in 1.3)
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.5.8
2.7.4
6 changes: 4 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Documentation can be found [on the wiki](https://github.com/sanger/sequencescape
- 0.6.x Removes usage of WTSISignOn cookie. Replaces with user specific api key,
can be provided to Sequencescape::Api.new as user_api_key: or via
`api_connection_options` in the controller.
- 1.0.x Enables HTTPS
- 2.0.x Drops support for versions less than Ruby 2.7

- master currently corresponds to 0.6.x
- master currently corresponds to 2.x

Rails 6 appears to be supported judging by Specs, but haven't used it in anger
yet.
Expand All @@ -22,7 +24,7 @@ yet.

1. Update the version number in `lib/sequencescape-api/version.rb`
2. For pre-releases the version number should be in the format:
major.minor.point-rcx
major.minor.point-rcx (increment x to prevent burning though version numbers when testing release candidates)
3. For release version the version number should be in the format:
major.minor.point
4. Ensure everything is committed, and for non-pre-releases, make sure you are
Expand Down
8 changes: 4 additions & 4 deletions lib/sequencescape-api/connection_factory/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
Net::HTTP.module_eval do
alias_method '__initialize__', 'initialize'

def initialize(*args, &block)
__initialize__(*args, &block)
def initialize(...)
__initialize__(...)
ensure
@debug_output = $stderr if ENV['HTTP_DEBUG']
end
Expand Down Expand Up @@ -105,7 +105,7 @@ def perform(http_verb, url, body = nil, accepts = nil) # rubocop:todo Metrics/Me
rescue URI::InvalidURIError => e
raise URI::InvalidURIError, "#{http_verb} failed: #{url.inspect} is not a valid uri"
end
Net::HTTP.start(uri.host, uri.port) do |connection|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |connection|
connection.read_timeout = read_timeout
request_headers = headers
request_headers.merge!('Accept' => accepts) unless accepts.nil?
Expand All @@ -122,7 +122,7 @@ def perform(http_verb, url, body = nil, accepts = nil) # rubocop:todo Metrics/Me

def perform_for_file(http_verb, url, file, filename, content_type)
uri = URI.parse(url)
Net::HTTP.start(uri.host, uri.port) do |connection|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |connection|
connection.read_timeout = read_timeout
file_headers = headers.merge!({ 'Content-Disposition' => "form-data; filename=\"#{filename}\"" })
request = Net::HTTP.const_get(http_verb.to_s.classify).new(uri.request_uri, file_headers)
Expand Down
1 change: 1 addition & 0 deletions lib/sequencescape-api/error_handling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'active_model/errors'

# Uh, ok, so why do I have to include these when I've kind of said I want everything!?!!
require 'active_support/core_ext/module/deprecation'
require 'active_model/validator'
require 'active_model/validations'
require 'active_model/callbacks'
Expand Down
20 changes: 9 additions & 11 deletions lib/sequencescape-api/resource/attribute_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ def eager_loaded_attribute?(name)
end

module Json
def as_json_for_update(options) # rubocop:todo Metrics/MethodLength
def as_json_for_update(options)
super.tap do |json|
begin
if options[:root]
json.fetch(json_root).merge!(attribute_group_json(options))
else
json.merge!(attribute_group_json(options))
end
rescue KeyError => e
# If we get a key error, append the json to out exception to assist diagnosing issues
e.message << " in #{json.to_json}"
raise e
if options[:root]
json.fetch(json_root).merge!(attribute_group_json(options))
else
json.merge!(attribute_group_json(options))
end
rescue KeyError => e
# If we get a key error, append the json to out exception to assist diagnosing issues
e.message << " in #{json.to_json}"
raise e
end
end
private :as_json_for_update
Expand Down
2 changes: 1 addition & 1 deletion lib/sequencescape-api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sequencescape
class Api
VERSION = '0.7.1'.freeze
VERSION = '2.0.0'.freeze
end
end
2 changes: 1 addition & 1 deletion sequencescape-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.homepage = ''
s.summary = 'Gem for the client side of the Sequencescape API'
s.description = 'Provides all of the necessary code for interacting with the Sequencescape API'
s.required_ruby_version = '> 2.4'
s.required_ruby_version = '>= 2.7'

s.rubyforge_project = 'sequencescape-client-api'

Expand Down
16 changes: 6 additions & 10 deletions spec/sequencescape-api/modifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
end

it 'includes the error on the field' do
begin
target.__send__(action, attribute_validated_at_client: 'please error')
rescue Sequencescape::Api::ResourceInvalid => e
e.resource.errors[:attribute_validated_at_client].should == ['cannot be set']
end
target.__send__(action, attribute_validated_at_client: 'please error')
rescue Sequencescape::Api::ResourceInvalid => e
e.resource.errors[:attribute_validated_at_client].should == ['cannot be set']
end
end

Expand All @@ -29,11 +27,9 @@
end

it 'includes the error on the field' do
begin
target.__send__(action, attribute_validated_at_server: 'please error')
rescue Sequencescape::Api::ResourceInvalid => e
e.resource.errors[:attribute_validated_at_server].should == ['cannot be set']
end
target.__send__(action, attribute_validated_at_server: 'please error')
rescue Sequencescape::Api::ResourceInvalid => e
e.resource.errors[:attribute_validated_at_server].should == ['cannot be set']
end
end
end
Expand Down

0 comments on commit 3ccf42d

Please sign in to comment.