mauth-client 6.2.0 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be045713042cd9a25e7b0219d959c1208c66b700c8a113130d7865d91e17db7d
4
- data.tar.gz: 155e903f0fa2fafabf2167c9d908398259ec2c9336b7f953bda83efe13667559
3
+ metadata.gz: fc8cbe23e9d1c4aed81b5c3879945892303f21ce8617060f97d59bf4504bf266
4
+ data.tar.gz: eef092f242b51ca385b1aec1e10c57aed8195483da3a29f94e693cd2488473c3
5
5
  SHA512:
6
- metadata.gz: 8c97d131c0f9aef554ab5ebb7fd06193ec50a50f7a81fc93a184ba30b5b91bf870c560a06ce9c5dfeb19dab7cb7410c771b355fbbfb1055e56327147c32c5a6a
7
- data.tar.gz: 446f8d0a681376361e3b9eabd86b20f3bfe2d28bdb028edf0b78c6e21f9222a7eaed5de3ba4fecd5afa95059698a14f6f4aaeba083d31ff5c55f618b9cbcdb12
6
+ metadata.gz: 00d23785893fece78afcebbb52ca56f955e0f1018e050882fe7991b02cd7f118a27cde158c126018006fe93559806ac6268e8469b56cabfbb227c7210da60761
7
+ data.tar.gz: 7fc815dec75cdcf5663e03dec6896a155b1818504aa7f8716654ffbacfe27c2ba46be57906c3acefc093fb3a6c5f2449e9f2693c7bcb36b8e25a7ae4bfe69eae
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ inherit_gem:
2
+ rubocop-mdsol: rubocop.yml
3
+
4
+ require:
5
+ - rubocop-performance
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - gemfiles/**/*
10
+
11
+ Gemspec/RequireMFA:
12
+ Enabled: false
13
+
14
+ Layout/ArgumentAlignment:
15
+ EnforcedStyle: with_fixed_indentation
16
+
17
+ Layout/FirstHashElementIndentation:
18
+ EnforcedStyle: consistent
19
+
20
+ Layout/LineLength:
21
+ Exclude:
22
+ - spec/client/local_authenticator_spec.rb
23
+
24
+ Lint/MissingSuper:
25
+ Exclude:
26
+ - exe/mauth-client
27
+ - lib/mauth/faraday.rb
28
+ - lib/mauth/rack.rb
29
+
30
+ Metrics/AbcSize:
31
+ Exclude:
32
+ - lib/mauth/client.rb
33
+ - lib/mauth/client/local_authenticator.rb
34
+ - lib/mauth/proxy.rb
35
+
36
+ Metrics/MethodLength:
37
+ Exclude:
38
+ - lib/mauth/client.rb
39
+
40
+ Naming/FileName:
41
+ Exclude:
42
+ - lib/mauth-client.rb
43
+
44
+ Style/FrozenStringLiteralComment:
45
+ Enabled: true
46
+
47
+ Style/GlobalVars:
48
+ Exclude:
49
+ - exe/mauth-client
50
+
51
+ Style/StringLiterals:
52
+ Enabled: true
53
+ EnforcedStyle: single_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.9
data/.travis.yml CHANGED
@@ -1,41 +1,54 @@
1
+ dist: focal
1
2
  language: ruby
2
3
  cache: bundler
3
4
 
4
5
  rvm:
5
- - 2.3
6
- - 2.4
7
- - 2.5
8
6
  - 2.6
9
7
  - 2.7
8
+ - 3.0
9
+ - 3.1
10
+
11
+ env:
12
+ global:
13
+ - BUNDLE_JOBS=4
14
+
15
+ jobs:
16
+ exclude:
17
+ - rvm: 3.0
18
+ gemfile: gemfiles/faraday_0.x.gemfile # Faraday v0.x does not officially support Ruby 3.0 (see: https://github.com/lostisland/faraday/releases/tag/v1.3.0)
19
+ - rvm: 3.1
20
+ gemfile: gemfiles/faraday_0.x.gemfile # Faraday v0.x does not officially support Ruby 3.0 (see: https://github.com/lostisland/faraday/releases/tag/v1.3.0)
10
21
 
11
22
  gemfile:
12
23
  - gemfiles/faraday_0.x.gemfile
13
24
  - gemfiles/faraday_1.x.gemfile
25
+ - gemfiles/faraday_2.x.gemfile
14
26
 
15
27
  before_install:
16
- - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)"
17
- - gem install bundler --force -N -v=2.1.4 && bundle --version
28
+ - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)" && bundle --version
18
29
 
19
30
  install:
20
- - bundle install --jobs=3 --retry=3
31
+ - bundle install
21
32
  - >-
22
33
  curl -H 'Cache-Control: no-cache'
23
- https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/master/travis_ci/fossa_install.sh |
34
+ https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/main/travis_ci/fossa_install.sh |
24
35
  bash -s -- -b $TRAVIS_BUILD_DIR
25
36
 
26
37
  script:
27
38
  - bundle exec rspec
39
+ - bundle exec rubocop
40
+ - bundle exec rake benchmark
28
41
  - >-
29
42
  curl -H 'Cache-Control: no-cache'
30
- https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/master/travis_ci/fossa_run.sh |
43
+ https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/main/travis_ci/fossa_run.sh |
31
44
  bash -s -- -b $TRAVIS_BUILD_DIR
32
45
 
33
46
  deploy:
34
47
  provider: rubygems
35
48
  gem: mauth-client
36
49
  api_key:
37
- secure: J0aPDp4+Ev2L+ZDcgpF+hAG95S4IsD6pCiDRxDWnrk79P5hq1rXoD3S39ANyqtQEQqkoVjsgoSP5JLi420aL2lYj7mhvaEOty9fK+flwUhI4nw+Gztm7EKNDNX8WKvk4fl4Zc7noIeI0uyes867hDjRQfyYvUuma7aK5H9NWzNUV9Q+KrVAoneVDGnNydxwkuuIpOFdjbVQgNpxVhVBV7Q4OLsB1KtWB9lptMwhqnyqZKex7JZ+37sojaj3oVT5ijrnAm+bR1QO1hGIOwuBako2iz+MBZHPccM4BEFsZme/7olypxv0JfeCuhqDnH1VWIFh6IZRDeLnZuX3qOhkdx4HLwxB//5O5+iapK0wh1zbnLvXqkE1dalUHyaZzStKH9xchIWl5I77Ica232OJYrpj9hhroae0p3VARF0IoZceKaH8NnMpq+nBAW4REcWrqPpe9xkRLDTNibkpaAy08vGOF2kPZkWw4lfkVBM1+wjY2xDn6wJ7VgQ1BeosbeTXbmny2TUeI22beihn894tzpCPPHiTRvKu0lV3jBfeoOAXzE333PrGm3zF9MDhg+1/iBwXVhdoOwEwBPQ/3Hu37xJn0AfRneni4StYnIkZ1Ur9Vub03J/3C3Aw6it99rQSWvC+2PzHqQhsG22VprvxlozFe1jFzdqKgvDkbkn44ltI=
50
+ secure: QDp0P/lMGLYc4+A3M6VD9y551X6GrGwOSBE6xSG4lE6mPXoSISK5Yj18vNWQRQuQ4BsE6CdfZ/xsPjSRDda6b+yUQbgisjJ+Ry6jUVE1v9UKTZ0VHgHyXcsaJFC29tBKBeuGCj0AD5qhbTO1+ybeZSUfdSeVVoidD4W/bSnvzlT1Lht7IE8jbHbR57LsJKoEaDxKu33dg4CYV96xrlYGxHAS2UgEgi5Ve3ohzBWkX9RWF/wWoGCzIYhJBzXgCEEFw8iWkspjTePgv9yjD2HIMtF44aiSTHM5iqBBsYJ7A8+kUwoq7+srsashHZ1wZz1YulsCSkjwM9AXZ4E0f9AnERw/RQ5gG7bCuHZtSG9g/0SWBQeNfkAF3An6eTSS24KVfnarGdH2bk0G28k2oP26MWiDKz8nlQxNAY4rH+dITael18bgf45H4KccQqiooBEGnuYpUAuIPB+1l+BsIcRQnrU3LDtmtZn0KrCHHJ7EHOdogOG+/Pxof8ht1xF7V+HYhhzSRJs2JkvmZsp4q2T7W6b6kfi59Cz3LpqA1HHYcL5/OFZeLA/TlCNke0CRMxG8k3udDKj50jqFATXEa8lNyGLjmWh7tL9Bb/uy+CU47qUdx+V4K+kheAvNFtHfpxmyUGJSY0FH02H1VBPWm10DZ7kH+6jgCKyXuql+yWDw62s=
38
51
  on:
39
52
  tags: true
40
53
  repo: mdsol/mauth-client-ruby
41
- condition: $TRAVIS_RUBY_VERSION == 2.7 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
54
+ condition: $TRAVIS_RUBY_VERSION == 3.1 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
data/Appraisals CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  appraise 'faraday_0.x' do
2
4
  gem 'faraday', '0.9.0'
3
5
  end
@@ -5,3 +7,7 @@ end
5
7
  appraise 'faraday_1.x' do
6
8
  gem 'faraday', '~> 1.0'
7
9
  end
10
+
11
+ appraise 'faraday_2.x' do
12
+ gem 'faraday', '~> 2.0'
13
+ end
data/CHANGELOG.md CHANGED
@@ -1,11 +1,23 @@
1
+ ## v6.4.0
2
+ - Support Ruby 3.1.
3
+ - Drop support for Ruby < 2.6.0.
4
+ - Allow Faraday 2.x.
5
+
6
+ ## v6.3.0
7
+ - Support Ruby 3.0.
8
+ - Drop support for Ruby < 2.5.0.
9
+
10
+ ## v6.2.1
11
+ - Fix SecurityTokenCacher to not cache tokens forever.
12
+
1
13
  ## v6.2.0
2
- * Drop legacy security token expiry in favor of honoring server cache headers via Faraday HTTP Cache Middleware.
14
+ - Drop legacy security token expiry in favor of honoring server cache headers via Faraday HTTP Cache Middleware.
3
15
 
4
16
  ## v6.1.1
5
- * Replace `URI.escape` with `CGI.escape` in SecurityTokenCacher to suppress "URI.escape is obsolete" warning.
17
+ - Replace `URI.escape` with `CGI.escape` in SecurityTokenCacher to suppress "URI.escape is obsolete" warning.
6
18
 
7
19
  ## v6.1.0
8
- * Allow Faraday 1.x.
20
+ - Allow Faraday 1.x.
9
21
 
10
22
  ## v6.0.0
11
23
  - Added parsing code to test with mauth-protocol-test-suite.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mauth-client.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'mauth/request_and_response'
@@ -16,7 +18,7 @@ class TestSignableRequest < MAuth::Request
16
18
  attr_accessor :headers
17
19
 
18
20
  def merge_headers(headers)
19
- self.class.new(@attributes_for_signing).tap{|r| r.headers = (@headers || {}).merge(headers) }
21
+ self.class.new(@attributes_for_signing).tap { |r| r.headers = (@headers || {}).merge(headers) }
20
22
  end
21
23
 
22
24
  def x_mws_time
@@ -37,7 +39,7 @@ class TestSignableRequest < MAuth::Request
37
39
  end
38
40
 
39
41
  desc 'Runs benchmarks for the library.'
40
- task :benchmark do
42
+ task :benchmark do # rubocop:disable Metrics/BlockLength
41
43
  mc = MAuth::Client.new(
42
44
  private_key: OpenSSL::PKey::RSA.generate(2048),
43
45
  app_uuid: SecureRandom.uuid,
data/examples/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gem 'faraday', '~> 1.0'
@@ -1,39 +1,61 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- mauth-client (6.1.0)
4
+ mauth-client (6.4.0)
5
5
  addressable (~> 2.0)
6
6
  coderay (~> 1.0)
7
7
  dice_bag (>= 0.9, < 2.0)
8
- faraday (>= 0.9, < 2.0)
9
- faraday_middleware (>= 0.9, < 2.0)
8
+ faraday (>= 0.9, < 3.0)
9
+ faraday-http-cache (>= 2.0, < 3.0)
10
10
  rack
11
11
  term-ansicolor (~> 1.0)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- addressable (2.7.0)
16
+ addressable (2.8.0)
17
17
  public_suffix (>= 2.0.2, < 5.0)
18
18
  coderay (1.1.3)
19
- dice_bag (1.4.1)
19
+ dice_bag (1.6.1)
20
20
  diff-lcs (~> 1.0)
21
21
  rake
22
22
  thor (< 2.0)
23
- diff-lcs (1.4.4)
24
- faraday (1.0.1)
23
+ diff-lcs (1.5.0)
24
+ faraday (1.9.3)
25
+ faraday-em_http (~> 1.0)
26
+ faraday-em_synchrony (~> 1.0)
27
+ faraday-excon (~> 1.1)
28
+ faraday-httpclient (~> 1.0)
29
+ faraday-multipart (~> 1.0)
30
+ faraday-net_http (~> 1.0)
31
+ faraday-net_http_persistent (~> 1.0)
32
+ faraday-patron (~> 1.0)
33
+ faraday-rack (~> 1.0)
34
+ faraday-retry (~> 1.0)
35
+ ruby2_keywords (>= 0.0.4)
36
+ faraday-em_http (1.0.0)
37
+ faraday-em_synchrony (1.0.0)
38
+ faraday-excon (1.1.0)
39
+ faraday-http-cache (2.2.0)
40
+ faraday (>= 0.8)
41
+ faraday-httpclient (1.0.1)
42
+ faraday-multipart (1.0.3)
25
43
  multipart-post (>= 1.2, < 3)
26
- faraday_middleware (1.0.0)
27
- faraday (~> 1.0)
44
+ faraday-net_http (1.0.1)
45
+ faraday-net_http_persistent (1.2.0)
46
+ faraday-patron (1.0.0)
47
+ faraday-rack (1.0.0)
48
+ faraday-retry (1.0.3)
28
49
  multipart-post (2.1.1)
29
50
  public_suffix (4.0.6)
30
51
  rack (2.2.3)
31
- rake (13.0.1)
52
+ rake (13.0.6)
53
+ ruby2_keywords (0.0.5)
32
54
  sync (0.5.0)
33
55
  term-ansicolor (1.7.1)
34
56
  tins (~> 1.0)
35
- thor (1.0.1)
36
- tins (1.25.0)
57
+ thor (1.2.1)
58
+ tins (1.31.0)
37
59
  sync
38
60
 
39
61
  PLATFORMS
@@ -44,4 +66,4 @@ DEPENDENCIES
44
66
  mauth-client!
45
67
 
46
68
  BUNDLED WITH
47
- 2.1.4
69
+ 2.2.29
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  abort "USAGE: ./#{__FILE__} <USER UUID>" unless ARGV.size == 1
4
5
 
@@ -6,7 +7,7 @@ require 'bundler/setup'
6
7
  Bundler.require(:default)
7
8
 
8
9
  def config
9
- @conf ||= YAML.load(File.open("./config.yml"))
10
+ @config ||= YAML.safe_load(File.open('./config.yml'))
10
11
  end
11
12
 
12
13
  # get user information
@@ -18,8 +19,8 @@ end
18
19
  def get_data_from_imedidata(resource_name)
19
20
  puts "fetching #{resource_name}..."
20
21
  begin
21
- connection = Faraday::Connection.new(url: config["imedidata"]["host"]) do |builder|
22
- builder.use MAuth::Faraday::RequestSigner, config["mauth"]
22
+ connection = Faraday::Connection.new(url: config['imedidata']['host']) do |builder|
23
+ builder.use MAuth::Faraday::RequestSigner, config['mauth']
23
24
  builder.adapter Faraday.default_adapter
24
25
  end
25
26
 
@@ -44,15 +45,14 @@ end
44
45
 
45
46
  get_user_info_mauth(ARGV[0])
46
47
 
47
-
48
48
  ### OTHER EXAMPLES
49
49
 
50
50
  #### get study groups for an user
51
51
  def get_study_groups_mauth(user_uuid)
52
- get_data_from_imedidata "users/#{user_uuid}/study_groups.json"
52
+ get_data_from_imedidata "users/#{user_uuid}/study_groups.json"
53
53
  end
54
54
 
55
55
  #### get roles for a user in an application study
56
56
  def get_user_study_roles_mauth(user_uuid, study_uuid)
57
- get_data_from_imedidata "users/#{user_uuid}/studies/#{study_uuid}/apps/#{config["mauth"]["app_uuid"]}/roles.json"
57
+ get_data_from_imedidata "users/#{user_uuid}/studies/#{study_uuid}/apps/#{config["mauth"]["app_uuid"]}/roles.json"
58
58
  end
data/exe/mauth-client CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
4
5
 
5
- require 'rubygems'
6
6
  require 'faraday'
7
- require 'faraday_middleware'
8
7
  require 'logger'
9
8
  require 'mauth/client'
10
9
  require 'mauth/faraday'
@@ -17,41 +16,42 @@ require 'optparse'
17
16
 
18
17
  # $options default values
19
18
  $options = {
20
- :authenticate_response => true,
21
- :verbose => true,
22
- :color => nil,
23
- :no_ssl_verify => false,
19
+ authenticate_response: true,
20
+ verbose: true,
21
+ color: nil,
22
+ no_ssl_verify: false
24
23
  }
25
24
 
26
25
  additional_headers = []
27
26
  opt_parser = OptionParser.new do |opts|
28
- opts.banner = "Usage: mauth-client [options] <verb> <url> [body]"
27
+ opts.banner = 'Usage: mauth-client [options] <verb> <url> [body]'
29
28
 
30
- opts.on("-v", "--[no-]verbose", "Run verbosely - output is like curl -v (this is the default)") do |v|
29
+ opts.on('-v', '--[no-]verbose', 'Run verbosely - output is like curl -v (this is the default)') do |v|
31
30
  $options[:verbose] = v
32
31
  end
33
- opts.on("-q", "Run quietly - only outputs the response body (same as --no-verbose)") do |v|
32
+ opts.on('-q', 'Run quietly - only outputs the response body (same as --no-verbose)') do |v|
34
33
  $options[:verbose] = !v
35
34
  end
36
- opts.on("--[no-]authenticate", "Authenticate the response received") do |v|
35
+ opts.on('--[no-]authenticate', 'Authenticate the response received') do |v|
37
36
  $options[:authenticate_response] = v
38
37
  end
39
- opts.on("--[no-]color", "Color the output (defaults to color if the output device is a TTY)") do |v|
38
+ opts.on('--[no-]color', 'Color the output (defaults to color if the output device is a TTY)') do |v|
40
39
  $options[:color] = v
41
40
  end
42
- opts.on("-t", "--content-type CONTENT-TYPE", "Sets the Content-Type header of the request") do |v|
41
+ opts.on('-t', '--content-type CONTENT-TYPE', 'Sets the Content-Type header of the request') do |v|
43
42
  $options[:content_type] = v
44
43
  end
45
- opts.on("-H", "--header LINE", "accepts a json string of additional headers to included. IE 'cache-expirey: 10, other: value") do |v|
44
+ opts.on('-H', '--header LINE',
45
+ "accepts a json string of additional headers to included. IE 'cache-expirey: 10, other: value") do |v|
46
46
  additional_headers << v
47
47
  end
48
- opts.on("--no-ssl-verify", "Disables SSL verification - use cautiously!") do
48
+ opts.on('--no-ssl-verify', 'Disables SSL verification - use cautiously!') do
49
49
  $options[:no_ssl_verify] = true
50
50
  end
51
- $options[:additional_headers] =additional_headers
51
+ $options[:additional_headers] = additional_headers
52
52
  end
53
53
  opt_parser.parse!
54
- abort(opt_parser.help) unless (2..3).include?(ARGV.size)
54
+ abort(opt_parser.help) unless (2..3).cover?(ARGV.size)
55
55
 
56
56
  # FIND MAUTH CONFIG
57
57
 
@@ -61,32 +61,32 @@ possible_mauth_config_files = [
61
61
  ENV['MAUTH_CONFIG_YAML'],
62
62
  '~/.mauth_config.yml',
63
63
  './config/mauth.yml',
64
- './mauth.yml',
64
+ './mauth.yml'
65
65
  ].compact
66
66
 
67
67
  mauth_config_yml = possible_mauth_config_files.detect do |filename|
68
- File.exists?(File.expand_path(filename))
68
+ File.exist?(File.expand_path(filename))
69
69
  end
70
70
  unless mauth_config_yml
71
- message = "could not find mauth config. giving up. please place a mauth config in one of the standard places, " +
72
- "or point the MAUTH_CONFIG_YML environment variable at an existing one. standard places are:" +
73
- possible_mauth_config_files.map{|f| "\n\t#{f}" }.join
71
+ message = 'could not find mauth config. giving up. please place a mauth config in one of the standard places, ' \
72
+ 'or point the MAUTH_CONFIG_YML environment variable at an existing one. standard places are:' +
73
+ possible_mauth_config_files.map { |f| "\n\t#{f}" }.join
74
74
  abort message
75
75
  end
76
76
 
77
- mauth_config = MAuth::Client.default_config(:mauth_config_yml => File.expand_path(mauth_config_yml))
77
+ mauth_config = MAuth::Client.default_config(mauth_config_yml: File.expand_path(mauth_config_yml))
78
78
 
79
79
  # INSTANTIATE MAUTH CLIENT
80
80
 
81
- logger = Logger.new(STDERR)
81
+ logger = Logger.new($stderr)
82
82
  mauth_client = MAuth::Client.new(mauth_config.merge('logger' => logger))
83
83
 
84
84
  # OUTPUTTERS FOR FARADAY THAT SHOULD MOVE TO A LIB SOMEWHERE
85
85
 
86
86
  # outputs the response body to the given output device (defaulting to STDOUT)
87
87
  class FaradayOutputter < Faraday::Middleware
88
- def initialize(app, outdev=STDOUT)
89
- @app=app
88
+ def initialize(app, outdev = $stdout)
89
+ @app = app
90
90
  @outdev = outdev
91
91
  end
92
92
 
@@ -100,7 +100,6 @@ end
100
100
  # this is to approximate `curl -v`s output. but it's all faked, whereas curl gives you
101
101
  # the real text written and read for request and response. whatever, close enough.
102
102
  class FaradayCurlVOutputter < FaradayOutputter
103
-
104
103
  # defines a method with the given name, applying coloring defined by any additional arguments.
105
104
  # if $options[:color] is set, respects that; otherwise, applies color if the output device is a tty.
106
105
  def self.color(name, *color_args)
@@ -129,10 +128,11 @@ class FaradayCurlVOutputter < FaradayOutputter
129
128
  color :response_header
130
129
  color :response_blankline, :intense_green, :bold
131
130
 
132
- def call(request_env)
131
+ def call(request_env) # rubocop:disable Metrics/AbcSize
133
132
  @outdev.puts "#{info('*')} #{info_body("connect to #{request_env[:url].host} on port #{request_env[:url].port}")}"
134
- @outdev.puts "#{info('*')} #{info_body("getting our SSL on")}" if request_env[:url].scheme=='https'
135
- @outdev.puts "#{request('>')} #{request_verb(request_env[:method].to_s.upcase)} #{request_env[:url].path} #{protocol('HTTP/1.1' || 'or something - TODO')}"
133
+ @outdev.puts "#{info('*')} #{info_body("getting our SSL on")}" if request_env[:url].scheme == 'https'
134
+ @outdev.puts "#{request('>')} #{request_verb(request_env[:method].to_s.upcase)} #{request_env[:url].path}" \
135
+ "#{protocol('HTTP/1.1' || 'or something - TODO')}"
136
136
  request_env[:request_headers].each do |k, v|
137
137
  @outdev.puts "#{request('>')} #{request_header(k)}#{request(':')} #{v}"
138
138
  end
@@ -142,11 +142,12 @@ class FaradayCurlVOutputter < FaradayOutputter
142
142
  @outdev.puts "#{request('>')} #{line}"
143
143
  end
144
144
  @app.call(request_env).on_complete do |response_env|
145
- @outdev.puts "#{response('<')} #{protocol('HTTP/1.1' || 'or something - TODO')} #{response_status(response_env[:status].to_s)}"
145
+ @outdev.puts "#{response('<')} #{protocol('HTTP/1.1' || 'or something - TODO')} " \
146
+ "#{response_status(response_env[:status].to_s)}"
146
147
  request_env[:response_headers].each do |k, v|
147
148
  @outdev.puts "#{response('<')} #{response_header(k)}#{response(':')} #{v}"
148
149
  end
149
- @outdev.puts "#{response_blankline ('<')} "
150
+ @outdev.puts "#{response_blankline('<')} "
150
151
  response_body = color_body_by_content_type(response_env[:body], response_env[:response_headers]['Content-Type'])
151
152
  (response_body || '').split("\n", -1).each do |line|
152
153
  @outdev.puts "#{response('<')} #{line}"
@@ -161,62 +162,61 @@ class FaradayCurlVOutputter < FaradayOutputter
161
162
 
162
163
  # a mapping for each registered CodeRay scanner to the Media Types which represent
163
164
  # that language. extremely incomplete!
164
- CodeRayForMediaTypes = {
165
- :c => [],
166
- :cpp => [],
167
- :clojure => [],
168
- :css => ['text/css', 'application/css-stylesheet'],
169
- :delphi => [],
170
- :diff => [],
171
- :erb => [],
172
- :groovy => [],
173
- :haml => [],
174
- :html => ['text/html'],
175
- :java => [],
176
- :java_script => ['application/javascript', 'text/javascript', 'application/x-javascript'],
177
- :json => ['application/json', %r(\Aapplication/.*\+json\z)],
178
- :php => [],
179
- :python => ['text/x-python'],
180
- :ruby => [],
181
- :sql => [],
182
- :xml => ['text/xml', 'application/xml', %r(\Aapplication/.*\+xml\z)],
183
- :yaml => [],
184
- }
165
+ CODE_RAY_FOR_MEDIA_TYPES = {
166
+ c: [],
167
+ cpp: [],
168
+ clojure: [],
169
+ css: ['text/css', 'application/css-stylesheet'],
170
+ delphi: [],
171
+ diff: [],
172
+ erb: [],
173
+ groovy: [],
174
+ haml: [],
175
+ html: ['text/html'],
176
+ java: [],
177
+ java_script: ['application/javascript', 'text/javascript', 'application/x-javascript'],
178
+ json: ['application/json', %r{\Aapplication/.*\+json\z}],
179
+ php: [],
180
+ python: ['text/x-python'],
181
+ ruby: [],
182
+ sql: [],
183
+ xml: ['text/xml', 'application/xml', %r{\Aapplication/.*\+xml\z}],
184
+ yaml: []
185
+ }.freeze
185
186
 
186
187
  # takes a body and a content type; returns the body, with coloring (ansi colors for terminals)
187
188
  # possibly added, if it's a recognized content type and #color? is true
188
189
  def color_body_by_content_type(body, content_type)
189
- if body && color?
190
- # kinda hacky way to get the media_type. faraday should supply this ...
191
- require 'rack'
192
- media_type = ::Rack::Request.new({'CONTENT_TYPE' => content_type}).media_type
193
- coderay_scanner = CodeRayForMediaTypes.reject{|k,v| !v.any?{|type| type === media_type} }.keys.first
194
- if coderay_scanner
195
- require 'coderay'
196
- if coderay_scanner == :json
197
- body = begin
198
- JSON.pretty_generate(JSON.parse(body))
199
- rescue JSON::ParserError
200
- body
201
- end
202
- end
203
- body = CodeRay.scan(body, coderay_scanner).encode(:terminal)
190
+ return body unless body && color?
191
+
192
+ # kinda hacky way to get the media_type. faraday should supply this ...
193
+ require 'rack'
194
+ media_type = ::Rack::Request.new({ 'CONTENT_TYPE' => content_type }).media_type
195
+ coderay_scanner = CODE_RAY_FOR_MEDIA_TYPES.select { |_k, v| v.any?(media_type) }.keys.first
196
+ return body unless coderay_scanner
197
+
198
+ require 'coderay'
199
+ if coderay_scanner == :json
200
+ body = begin
201
+ JSON.pretty_generate(JSON.parse(body))
202
+ rescue JSON::ParserError
203
+ body
204
204
  end
205
205
  end
206
- body
206
+ CodeRay.scan(body, coderay_scanner).encode(:terminal)
207
207
  end
208
208
  end
209
209
 
210
210
  # CONFIGURE THE FARADAY CONNECTION
211
211
  faraday_options = {}
212
212
  if $options[:no_ssl_verify]
213
- faraday_options[:ssl] = {:verify => false}
213
+ faraday_options[:ssl] = { verify: false }
214
214
  end
215
215
  connection = Faraday.new(faraday_options) do |builder|
216
- builder.use MAuth::Faraday::MAuthClientUserAgent, "MAuth-Client CLI"
217
- builder.use MAuth::Faraday::RequestSigner, :mauth_client => mauth_client
216
+ builder.use MAuth::Faraday::MAuthClientUserAgent, 'MAuth-Client CLI'
217
+ builder.use MAuth::Faraday::RequestSigner, mauth_client: mauth_client
218
218
  if $options[:authenticate_response]
219
- builder.use MAuth::Faraday::ResponseAuthenticator, :mauth_client => mauth_client
219
+ builder.use MAuth::Faraday::ResponseAuthenticator, mauth_client: mauth_client
220
220
  end
221
221
  builder.use $options[:verbose] ? FaradayCurlVOutputter : FaradayOutputter
222
222
  builder.adapter Faraday.default_adapter
@@ -224,41 +224,38 @@ end
224
224
 
225
225
  httpmethod, url, body = *ARGV
226
226
 
227
- unless Faraday::Connection::METHODS.map{|m| m.to_s.downcase }.include?(httpmethod.downcase)
227
+ unless Faraday::Connection::METHODS.map { |m| m.to_s.downcase }.include?(httpmethod.downcase)
228
228
  abort "Unrecognized HTTP method given: #{httpmethod}\n\n" + opt_parser.help
229
229
  end
230
230
 
231
231
  headers = {}
232
232
  if $options[:content_type]
233
233
  headers['Content-Type'] = $options[:content_type]
234
- else
235
- if body
236
- # I'd rather not have a default content-type, but if none is set then the HTTP adapter sets this to
237
- # application/x-www-form-urlencoded anyway. application/json is a better default for our purposes.
238
- headers['Content-Type'] = 'application/json'
239
- end
234
+ elsif body
235
+ headers['Content-Type'] = 'application/json'
236
+ # I'd rather not have a default content-type, but if none is set then the HTTP adapter sets this to
237
+ # application/x-www-form-urlencoded anyway. application/json is a better default for our purposes.
240
238
  end
241
239
 
242
- if $options[:additional_headers]
243
- $options[:additional_headers].each do |cur|
244
- raise "Headers must be in the format of [key]:[value]" unless cur.include?(':')
245
- key, throw_away ,value = cur.partition(':')
246
- headers[key] = value
247
- end
240
+ $options[:additional_headers]&.each do |cur|
241
+ raise 'Headers must be in the format of [key]:[value]' unless cur.include?(':')
242
+
243
+ key, _throw_away, value = cur.partition(':')
244
+ headers[key] = value
248
245
  end
249
246
 
250
247
  # OH LOOK IT'S FINALLY ACTUALLY CONNECTING TO SOMETHING
251
248
 
252
249
  begin
253
- response = connection.run_request(httpmethod.downcase.to_sym, url, body, headers)
250
+ connection.run_request(httpmethod.downcase.to_sym, url, body, headers)
254
251
  rescue MAuth::InauthenticError, MAuth::UnableToAuthenticateError, MAuth::MAuthNotPresent, MAuth::MissingV2Error => e
255
- if $options[:color].nil? ? STDERR.tty? : $options[:color]
252
+ if $options[:color].nil? ? $stderr.tty? : $options[:color]
256
253
  class_color = Term::ANSIColor.method(e.is_a?(MAuth::UnableToAuthenticateError) ? :intense_yellow : :intense_red)
257
254
  message_color = Term::ANSIColor.method(e.is_a?(MAuth::UnableToAuthenticateError) ? :yellow : :red)
258
255
  else
259
- class_color = proc{|s| s }
260
- message_color = proc{|s| s }
256
+ class_color = proc { |s| s }
257
+ message_color = proc { |s| s }
261
258
  end
262
- STDERR.puts(class_color.call(e.class.to_s))
263
- STDERR.puts(message_color.call(e.message))
259
+ warn(class_color.call(e.class.to_s))
260
+ warn(message_color.call(e.message))
264
261
  end