mauth-client 6.2.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +53 -0
- data/.ruby-version +1 -0
- data/.travis.yml +23 -10
- data/Appraisals +6 -0
- data/CHANGELOG.md +15 -3
- data/Gemfile +2 -0
- data/Rakefile +4 -2
- data/examples/Gemfile +2 -0
- data/examples/Gemfile.lock +35 -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 +12 -9
- data/lib/mauth/client/remote_authenticator.rb +20 -10
- data/lib/mauth/client/security_token_cacher.rb +36 -37
- data/lib/mauth/client/signer.rb +6 -4
- 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 +21 -13
- 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 +16 -11
- metadata +94 -69
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
@@ -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
|
31
|
+
- bundle install
|
21
32
|
- >-
|
22
33
|
curl -H 'Cache-Control: no-cache'
|
23
|
-
https://raw.githubusercontent.com/mdsol/fossa_ci_scripts/
|
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/
|
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:
|
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 ==
|
54
|
+
condition: $TRAVIS_RUBY_VERSION == 3.1 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
|
data/Appraisals
CHANGED
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
|
-
|
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
|
-
|
17
|
+
- Replace `URI.escape` with `CGI.escape` in SecurityTokenCacher to suppress "URI.escape is obsolete" warning.
|
6
18
|
|
7
19
|
## v6.1.0
|
8
|
-
|
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
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,39 +1,61 @@
|
|
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, <
|
9
|
-
|
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.
|
16
|
+
addressable (2.8.0)
|
17
17
|
public_suffix (>= 2.0.2, < 5.0)
|
18
18
|
coderay (1.1.3)
|
19
|
-
dice_bag (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.
|
24
|
-
faraday (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
|
-
|
27
|
-
|
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.
|
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.
|
36
|
-
tins (1.
|
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.
|
69
|
+
2.2.29
|
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
|