mauth-client 6.3.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: 3d26cf42f3bc98d5ce98981ee710c52d2b87a9360b6ae54391288182c95fa09a
4
- data.tar.gz: 03c4a9d0e96187d57232d5a1923935ad5db9c190a891fda410595010bbf1d946
3
+ metadata.gz: fc8cbe23e9d1c4aed81b5c3879945892303f21ce8617060f97d59bf4504bf266
4
+ data.tar.gz: eef092f242b51ca385b1aec1e10c57aed8195483da3a29f94e693cd2488473c3
5
5
  SHA512:
6
- metadata.gz: 58751eb9040426589a0274390307abfc518c1465372c6b26329debb25a12c06fb63e96fccd4093fd45e90bd24fefd6c64966160b6520513515cd5dc9ac96f804
7
- data.tar.gz: 0febdd455262d240d5f456acc00785d8a0941627ca352ffa559526ddadbaab726213b87e24eaa8f576c430b0a856725224ed48909cdc64cf9ce6b3a77b8c4acf
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
@@ -3,26 +3,32 @@ language: ruby
3
3
  cache: bundler
4
4
 
5
5
  rvm:
6
- - 2.5
7
6
  - 2.6
8
7
  - 2.7
9
8
  - 3.0
9
+ - 3.1
10
+
11
+ env:
12
+ global:
13
+ - BUNDLE_JOBS=4
10
14
 
11
15
  jobs:
12
16
  exclude:
13
17
  - rvm: 3.0
14
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)
15
21
 
16
22
  gemfile:
17
23
  - gemfiles/faraday_0.x.gemfile
18
24
  - gemfiles/faraday_1.x.gemfile
25
+ - gemfiles/faraday_2.x.gemfile
19
26
 
20
27
  before_install:
21
- - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)"
22
- - gem install bundler --force -N && bundle --version
28
+ - gem update --system --force -N > /dev/null && echo "Rubygems version $(gem --version)" && bundle --version
23
29
 
24
30
  install:
25
- - bundle install --jobs=3 --retry=3
31
+ - bundle install
26
32
  - >-
27
33
  curl -H 'Cache-Control: no-cache'
28
34
  https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/main/travis_ci/fossa_install.sh |
@@ -30,6 +36,7 @@ install:
30
36
 
31
37
  script:
32
38
  - bundle exec rspec
39
+ - bundle exec rubocop
33
40
  - bundle exec rake benchmark
34
41
  - >-
35
42
  curl -H 'Cache-Control: no-cache'
@@ -44,4 +51,4 @@ deploy:
44
51
  on:
45
52
  tags: true
46
53
  repo: mdsol/mauth-client-ruby
47
- condition: $TRAVIS_RUBY_VERSION == 3.0 && $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,3 +1,8 @@
1
+ ## v6.4.0
2
+ - Support Ruby 3.1.
3
+ - Drop support for Ruby < 2.6.0.
4
+ - Allow Faraday 2.x.
5
+
1
6
  ## v6.3.0
2
7
  - Support Ruby 3.0.
3
8
  - Drop support for Ruby < 2.5.0.
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,13 +1,12 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- mauth-client (6.3.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)
8
+ faraday (>= 0.9, < 3.0)
9
9
  faraday-http-cache (>= 2.0, < 3.0)
10
- faraday_middleware (>= 0.9, < 2.0)
11
10
  rack
12
11
  term-ansicolor (~> 1.0)
13
12
 
@@ -17,21 +16,22 @@ GEM
17
16
  addressable (2.8.0)
18
17
  public_suffix (>= 2.0.2, < 5.0)
19
18
  coderay (1.1.3)
20
- dice_bag (1.6.0)
19
+ dice_bag (1.6.1)
21
20
  diff-lcs (~> 1.0)
22
21
  rake
23
22
  thor (< 2.0)
24
- diff-lcs (1.4.4)
25
- faraday (1.8.0)
23
+ diff-lcs (1.5.0)
24
+ faraday (1.9.3)
26
25
  faraday-em_http (~> 1.0)
27
26
  faraday-em_synchrony (~> 1.0)
28
27
  faraday-excon (~> 1.1)
29
- faraday-httpclient (~> 1.0.1)
28
+ faraday-httpclient (~> 1.0)
29
+ faraday-multipart (~> 1.0)
30
30
  faraday-net_http (~> 1.0)
31
- faraday-net_http_persistent (~> 1.1)
31
+ faraday-net_http_persistent (~> 1.0)
32
32
  faraday-patron (~> 1.0)
33
33
  faraday-rack (~> 1.0)
34
- multipart-post (>= 1.2, < 3)
34
+ faraday-retry (~> 1.0)
35
35
  ruby2_keywords (>= 0.0.4)
36
36
  faraday-em_http (1.0.0)
37
37
  faraday-em_synchrony (1.0.0)
@@ -39,12 +39,13 @@ GEM
39
39
  faraday-http-cache (2.2.0)
40
40
  faraday (>= 0.8)
41
41
  faraday-httpclient (1.0.1)
42
+ faraday-multipart (1.0.3)
43
+ multipart-post (>= 1.2, < 3)
42
44
  faraday-net_http (1.0.1)
43
45
  faraday-net_http_persistent (1.2.0)
44
46
  faraday-patron (1.0.0)
45
47
  faraday-rack (1.0.0)
46
- faraday_middleware (1.2.0)
47
- faraday (~> 1.0)
48
+ faraday-retry (1.0.3)
48
49
  multipart-post (2.1.1)
49
50
  public_suffix (4.0.6)
50
51
  rack (2.2.3)
@@ -53,8 +54,8 @@ GEM
53
54
  sync (0.5.0)
54
55
  term-ansicolor (1.7.1)
55
56
  tins (~> 1.0)
56
- thor (1.1.0)
57
- tins (1.29.1)
57
+ thor (1.2.1)
58
+ tins (1.31.0)
58
59
  sync
59
60
 
60
61
  PLATFORMS
@@ -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
data/exe/mauth-proxy CHANGED
@@ -1,14 +1,14 @@
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 'mauth/proxy'
7
7
  require 'rack'
8
8
 
9
9
  headers = []
10
10
  headers_index = ARGV.find_index('--header')
11
- while(headers_index) do
11
+ while headers_index
12
12
  headers << ARGV[headers_index + 1]
13
13
  ARGV.delete_at(headers_index + 1)
14
14
  ARGV.delete_at(headers_index)
@@ -16,25 +16,25 @@ while(headers_index) do
16
16
  end
17
17
 
18
18
  authenticate_responses = !ARGV.delete('--no-authenticate')
19
- browser_proxy = !(ARGV.delete('--browser_proxy').nil?)
19
+ browser_proxy = !ARGV.delete('--browser_proxy').nil?
20
20
 
21
21
  target_uri = browser_proxy ? ARGV : ARGV.pop
22
22
 
23
23
  if !target_uri || target_uri.empty?
24
- abort("Usage: mauth-proxy [rack options] --browser_proxy [--no-authenticate] <target URI> <target URI> ...\n" +
25
- "or: mauth-proxy [rack options] <target URI>")
24
+ abort("Usage: mauth-proxy [rack options] --browser_proxy [--no-authenticate] <target URI> <target URI> ...\n" \
25
+ 'or: mauth-proxy [rack options] <target URI>')
26
26
  end
27
27
 
28
28
  rack_server_options = Rack::Server::Options.new.parse!(ARGV)
29
29
 
30
- # for security, this rack server will only accept local connections, so override Host
30
+ # for security, this rack server will only accept local connections, so override Host
31
31
  # to 127.0.0.1 (from the default of 0.0.0.0)
32
32
  #
33
- # this means that the '-o' / '--host' option to Rack::Server::Options is ignored.
34
- rack_server_options[:Host] = "127.0.0.1"
33
+ # this means that the '-o' / '--host' option to Rack::Server::Options is ignored.
34
+ rack_server_options[:Host] = '127.0.0.1'
35
35
 
36
- rack_server_options[:app] = MAuth::Proxy.new(target_uri, :authenticate_responses => authenticate_responses,
37
- :browser_proxy => browser_proxy, :headers => headers)
36
+ rack_server_options[:app] = MAuth::Proxy.new(target_uri, authenticate_responses: authenticate_responses,
37
+ browser_proxy: browser_proxy, headers: headers)
38
38
 
39
39
  mauth_proxy_server = Rack::Server.new(rack_server_options)
40
40
  mauth_proxy_server.start