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 +4 -4
- data/.rubocop.yml +53 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -5
- data/Appraisals +6 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/Rakefile +4 -2
- data/examples/Gemfile +2 -0
- data/examples/Gemfile.lock +14 -13
- data/examples/get_user_info.rb +6 -6
- data/exe/mauth-client +88 -91
- data/exe/mauth-proxy +10 -10
- data/gemfiles/faraday_2.x.gemfile +7 -0
- data/lib/mauth/autoload.rb +2 -0
- data/lib/mauth/client/authenticator_base.rb +9 -6
- data/lib/mauth/client/local_authenticator.rb +11 -8
- data/lib/mauth/client/remote_authenticator.rb +20 -10
- data/lib/mauth/client/security_token_cacher.rb +4 -3
- data/lib/mauth/client/signer.rb +5 -3
- data/lib/mauth/client.rb +46 -37
- data/lib/mauth/core_ext.rb +2 -0
- data/lib/mauth/dice_bag/mauth_templates.rb +3 -1
- data/lib/mauth/errors.rb +2 -0
- data/lib/mauth/fake/rack.rb +17 -13
- data/lib/mauth/faraday.rb +5 -1
- data/lib/mauth/middleware.rb +4 -2
- data/lib/mauth/proxy.rb +12 -9
- data/lib/mauth/rack.rb +14 -6
- data/lib/mauth/request_and_response.rb +20 -12
- data/lib/mauth/version.rb +1 -1
- data/lib/mauth-client.rb +2 -0
- data/lib/rack/mauth.rb +2 -0
- data/mauth-client.gemspec +15 -10
- metadata +87 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc8cbe23e9d1c4aed81b5c3879945892303f21ce8617060f97d59bf4504bf266
|
4
|
+
data.tar.gz: eef092f242b51ca385b1aec1e10c57aed8195483da3a29f94e693cd2488473c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
54
|
+
condition: $TRAVIS_RUBY_VERSION == 3.1 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
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
data/examples/Gemfile.lock
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
mauth-client (6.
|
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, <
|
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.
|
19
|
+
dice_bag (1.6.1)
|
21
20
|
diff-lcs (~> 1.0)
|
22
21
|
rake
|
23
22
|
thor (< 2.0)
|
24
|
-
diff-lcs (1.
|
25
|
-
faraday (1.
|
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
|
28
|
+
faraday-httpclient (~> 1.0)
|
29
|
+
faraday-multipart (~> 1.0)
|
30
30
|
faraday-net_http (~> 1.0)
|
31
|
-
faraday-net_http_persistent (~> 1.
|
31
|
+
faraday-net_http_persistent (~> 1.0)
|
32
32
|
faraday-patron (~> 1.0)
|
33
33
|
faraday-rack (~> 1.0)
|
34
|
-
|
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
|
-
|
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
|
57
|
-
tins (1.
|
57
|
+
thor (1.2.1)
|
58
|
+
tins (1.31.0)
|
58
59
|
sync
|
59
60
|
|
60
61
|
PLATFORMS
|
data/examples/get_user_info.rb
CHANGED
@@ -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
|
-
@
|
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[
|
22
|
-
builder.use MAuth::Faraday::RequestSigner, config[
|
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
|
-
|
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
|
-
|
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
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
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 =
|
27
|
+
opts.banner = 'Usage: mauth-client [options] <verb> <url> [body]'
|
29
28
|
|
30
|
-
opts.on(
|
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(
|
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(
|
35
|
+
opts.on('--[no-]authenticate', 'Authenticate the response received') do |v|
|
37
36
|
$options[:authenticate_response] = v
|
38
37
|
end
|
39
|
-
opts.on(
|
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(
|
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(
|
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(
|
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).
|
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.
|
68
|
+
File.exist?(File.expand_path(filename))
|
69
69
|
end
|
70
70
|
unless mauth_config_yml
|
71
|
-
message =
|
72
|
-
|
73
|
-
|
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(:
|
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(
|
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=
|
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}
|
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')}
|
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
|
-
|
165
|
-
:
|
166
|
-
:
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
171
|
-
:
|
172
|
-
:
|
173
|
-
:
|
174
|
-
:
|
175
|
-
:
|
176
|
-
:
|
177
|
-
:
|
178
|
-
:
|
179
|
-
:
|
180
|
-
:
|
181
|
-
:
|
182
|
-
:
|
183
|
-
:
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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] = {:
|
213
|
+
faraday_options[:ssl] = { verify: false }
|
214
214
|
end
|
215
215
|
connection = Faraday.new(faraday_options) do |builder|
|
216
|
-
builder.use MAuth::Faraday::MAuthClientUserAgent,
|
217
|
-
builder.use MAuth::Faraday::RequestSigner, :
|
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, :
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
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
|
-
|
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? ?
|
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
|
-
|
263
|
-
|
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
|
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 = !
|
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
|
-
|
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] =
|
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, :
|
37
|
-
:
|
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
|