Skip to content

Commit

Permalink
feat: upgrade ruby, bundler, rubocop support (#42)
Browse files Browse the repository at this point in the history
This commit resolves the rubocop warnings mentioned in PR #41
- Test with ruby 2.7, 3.0, 3.1. 2.7 is end of life and all prior are also but we can possibly keep 2.7 supportable for now. See: https://www.ruby-lang.org/en/downloads/branches/
- Upgrade to bundler 2 and rubocop 1.40+
- Fix some obvious rubocop violations
- Remove all non-required .rubocop.yml settings to simplify the configuration

Signed-off-by: Joe Rafaniello <[email protected]>
  • Loading branch information
jrafanie authored Nov 6, 2023
1 parent 966ca86 commit ac50850
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 1,606 deletions.
1,543 changes: 7 additions & 1,536 deletions .rubocop.yml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ language: ruby
cache: bundler

rvm:
- 2.3.7
- 2.4.5
- 2.5.3
- 2.7
- 3.0
- 3.1

before_install:
- sudo apt-get update
- sudo apt-get install python
- nvm install node
- nvm use node
- gem install bundler:1.16.3
- gem install bundler

install:
- pip install --user bumpversion
Expand All @@ -20,7 +20,7 @@ install:
- npm install -g @semantic-release/git
- npm install @semantic-release/github
- npm install -g @semantic-release/commit-analyzer
- bundle _1.16.3_ install
- bundle install

script:
- bundle exec rake
Expand All @@ -30,14 +30,14 @@ deploy:
script: npx semantic-release
on:
branch: main
rvm: 2.5.3
rvm: 2.7

- provider: rubygems
api_key: $RUBYGEMS_API_KEY
gem: ibm_cloud_sdk_core
on:
branch: main
rvm: 2.5.3
rvm: 2.7

matrix:
fast_finish: true
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ If you want to contribute to the repository, here's a quick guide:
2. Clone the repository into a local directory.

3. Install `Ruby`. Supported versions in the core are:
- 2.3.7
- 2.4.5
- 2.5.3
- 2.7
- 3.0
- 3.1
4. Run
```sh
gem install bundler
Expand Down
8 changes: 5 additions & 3 deletions ibm_cloud_sdk_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
spec.summary = "Official IBM Cloud SDK core library"
spec.homepage = "https://www.github.com/IBM"
spec.licenses = ["Apache-2.0"]
spec.required_ruby_version = ">= 2.3"
spec.required_ruby_version = ">= 2.7"

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
Expand All @@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "http", "~> 5.1.1"
spec.add_runtime_dependency "jwt", "~> 2.2.1"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "bundler", "~> 2"
spec.add_development_dependency "codecov", "~> 0.1"
spec.add_development_dependency "dotenv", "~> 2.4"
spec.add_development_dependency "httplog", "~> 1.0"
Expand All @@ -45,7 +45,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest-reporters", "~> 1.3"
spec.add_development_dependency "minitest-retry", "~> 0.1"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rubocop", "0.62"
spec.add_development_dependency "rubocop", ">=1.40"
spec.add_development_dependency "rubocop-performance"
spec.add_development_dependency "rubocop-rails"
spec.add_development_dependency "simplecov", "~> 0.16"
spec.add_development_dependency "webmock", "~> 3.4"
end
2 changes: 1 addition & 1 deletion lib/ibm_cloud_sdk_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Module for the IBM Cloud SDK Core
module IBMCloudSdkCore
require_relative("./ibm_cloud_sdk_core/base_service.rb")
require_relative("./ibm_cloud_sdk_core/base_service")
end
1 change: 1 addition & 0 deletions lib/ibm_cloud_sdk_core/api_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module IBMCloudSdkCore
# Custom exception class for errors returned from the APIs
class ApiException < StandardError
attr_reader :code, :error, :info, :transaction_id, :global_transaction_id

# :param HTTP::Response response: The response object from the API
def initialize(code: nil, error: nil, info: nil, transaction_id: nil, global_transaction_id: nil, response: nil)
if code.nil? || error.nil?
Expand Down
5 changes: 3 additions & 2 deletions lib/ibm_cloud_sdk_core/authenticators/basic_authenticator.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("../utils.rb")
require_relative("./authenticator")
require_relative("../utils")

module IBMCloudSdkCore
# Basic Authenticator
class BasicAuthenticator < Authenticator
attr_accessor :username, :password, :authentication_type

def initialize(vars)
defaults = {
username: nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("../utils.rb")
require_relative("./authenticator")
require_relative("../utils")

module IBMCloudSdkCore
# Basic Authenticator
class BearerTokenAuthenticator < Authenticator
attr_accessor :authentication_type

def initialize(vars)
defaults = {
bearer_token: nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("./basic_authenticator.rb")
require_relative("./bearer_token_authenticator.rb")
require_relative("./cp4d_authenticator.rb")
require_relative("./iam_authenticator.rb")
require_relative("./no_auth_authenticator.rb")
require_relative("../utils.rb")
require_relative("./authenticator")
require_relative("./basic_authenticator")
require_relative("./bearer_token_authenticator")
require_relative("./cp4d_authenticator")
require_relative("./iam_authenticator")
require_relative("./no_auth_authenticator")
require_relative("../utils")

module IBMCloudSdkCore
# Authenticator
Expand All @@ -17,7 +17,7 @@ class ConfigBasedAuthenticatorFactory < Authenticator
# :return: the authenticator
def get_authenticator(service_name:)
config = get_service_properties(service_name)
return construct_authenticator(config) unless config.nil? || config.empty?
construct_authenticator(config) unless config.nil? || config.empty?
end

def construct_authenticator(config)
Expand All @@ -32,7 +32,8 @@ def construct_authenticator(config)
return BearerTokenAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_BEARER_TOKEN).zero?
return CloudPakForDataAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_CP4D).zero?
return IamAuthenticator.new(config) if auth_type.casecmp(AUTH_TYPE_IAM).zero?
return NoAuthAuthenticator.new if auth_type.casecmp(AUTH_TYPE_NO_AUTH).zero?

NoAuthAuthenticator.new if auth_type.casecmp(AUTH_TYPE_NO_AUTH).zero?
end
end
end
7 changes: 4 additions & 3 deletions lib/ibm_cloud_sdk_core/authenticators/cp4d_authenticator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("../token_managers/cp4d_token_manager.rb")
require_relative("../utils.rb")
require_relative("./authenticator")
require_relative("../token_managers/cp4d_token_manager")
require_relative("../utils")

module IBMCloudSdkCore
# Basic Authenticator
class CloudPakForDataAuthenticator < Authenticator
attr_accessor :authentication_type, :disable_ssl_verification

def initialize(vars)
defaults = {
username: nil,
Expand Down
7 changes: 4 additions & 3 deletions lib/ibm_cloud_sdk_core/authenticators/iam_authenticator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("../token_managers/iam_token_manager.rb")
require_relative("../utils.rb")
require_relative("./authenticator")
require_relative("../token_managers/iam_token_manager")
require_relative("../utils")

module IBMCloudSdkCore
# Basic Authenticator
class IamAuthenticator < Authenticator
attr_accessor :authentication_type, :disable_ssl_verification, :client_id, :client_secret

def initialize(vars)
defaults = {
url: nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require("json")
require_relative("./authenticator.rb")
require_relative("./authenticator")

module IBMCloudSdkCore
# Authenticator
Expand Down
11 changes: 6 additions & 5 deletions lib/ibm_cloud_sdk_core/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
require("rbconfig")
require("stringio")
require("json")
require_relative("./version.rb")
require_relative("./detailed_response.rb")
require_relative("./api_exception.rb")
require_relative("./utils.rb")
require_relative("./version")
require_relative("./detailed_response")
require_relative("./api_exception")
require_relative("./utils")
require_relative("./authenticators/authenticator")
require_relative("./authenticators/basic_authenticator")
require_relative("./authenticators/bearer_token_authenticator")
Expand All @@ -25,6 +25,7 @@ module IBMCloudSdkCore
class BaseService
attr_accessor :service_name, :service_url
attr_reader :conn, :authenticator, :disable_ssl_verification

def initialize(vars)
defaults = {
authenticator: nil,
Expand Down Expand Up @@ -148,7 +149,7 @@ def configure_http_client(proxy: {}, timeout: {}, disable_ssl_verification: fals
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
@conn.default_options = { ssl_context: ssl_context }
end
add_proxy(proxy) unless proxy.empty? || !proxy.dig(:address).is_a?(String) || !proxy.dig(:port).is_a?(Integer)
add_proxy(proxy) unless proxy.empty? || !proxy[:address].is_a?(String) || !proxy[:port].is_a?(Integer)
add_timeout(timeout) unless timeout.empty? || (!timeout.key?(:per_operation) && !timeout.key?(:global))
end

Expand Down
1 change: 1 addition & 0 deletions lib/ibm_cloud_sdk_core/detailed_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module IBMCloudSdkCore
# Custom class for objects returned from API calls
class DetailedResponse
attr_reader :status, :headers, :result

def initialize(status: nil, headers: nil, body: nil, response: nil)
if status.nil? || headers.nil? || body.nil?
@status = response.code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require("http")
require("json")
require("rbconfig")
require_relative("./../version.rb")
require_relative("./../version")
require_relative("./jwt_token_manager")

module IBMCloudSdkCore
Expand Down
6 changes: 3 additions & 3 deletions lib/ibm_cloud_sdk_core/token_managers/iam_token_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require("http")
require("json")
require("rbconfig")
require_relative("./../version.rb")
require_relative("./../version")
require_relative("./jwt_token_manager")

module IBMCloudSdkCore
Expand All @@ -17,6 +17,7 @@ class IAMTokenManager < JWTTokenManager
TOKEN_NAME = "access_token"

attr_accessor :token_info, :token_name, :client_id, :client_secret

def initialize(
apikey: nil,
url: nil,
Expand Down Expand Up @@ -51,15 +52,14 @@ def request_token
"response_type" => REQUEST_TOKEN_RESPONSE_TYPE
}
# @headers.add
response = request(
request(
method: "POST",
url: @url,
headers: headers,
data: HTTP::URI.form_encode(data),
username: @client_id,
password: @client_secret
)
response
end
end
end
4 changes: 2 additions & 2 deletions lib/ibm_cloud_sdk_core/token_managers/jwt_token_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require("json")
require("jwt")
require("rbconfig")
require_relative("./../version.rb")
require_relative("./../version")

module IBMCloudSdkCore
# Class to manage JWT Token Authentication
Expand Down Expand Up @@ -84,7 +84,7 @@ def request(method:, url:, headers: nil, params: nil, data: nil, username: nil,
end
return JSON.parse(response.body.to_s) if (200..299).cover?(response.code)

require_relative("./../api_exception.rb")
require_relative("./../api_exception")
raise ApiException.new(response: response)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ibm_cloud_sdk_core/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_service_properties(service_name)
end

def check_bad_first_or_last_char(str)
return str.start_with?("{", "\"") || str.end_with?("}", "\"") unless str.nil?
str.start_with?("{", "\"") || str.end_with?("}", "\"") unless str.nil?
end

# checks if the provided value is truthy
Expand All @@ -29,13 +29,13 @@ def load_from_credential_file(service_name, separator = "=")

# Top-level directory of the project
if credential_file_path.nil?
file_path = File.join(File.dirname(__FILE__), "/../../" + DEFAULT_CREDENTIALS_FILE_NAME)
file_path = File.join(File.dirname(__FILE__), "/../../#{DEFAULT_CREDENTIALS_FILE_NAME}")
credential_file_path = file_path if File.exist?(file_path)
end

# Home directory
if credential_file_path.nil?
file_path = ENV["HOME"] + "/" + DEFAULT_CREDENTIALS_FILE_NAME
file_path = "#{ENV["HOME"]}/#{DEFAULT_CREDENTIALS_FILE_NAME}"
credential_file_path = file_path if File.exist?(file_path)
end

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
end

require("minitest/autorun")
require_relative("./../lib/ibm_cloud_sdk_core.rb")
require_relative("./../lib/ibm_cloud_sdk_core")
require("minitest/retry")

Minitest::Retry.use!
Expand Down
Loading

0 comments on commit ac50850

Please sign in to comment.