basic_auth_mark 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a065ee9ed62c4fc94e3ddc1bb9a4f46e5d7e9e4
4
- data.tar.gz: 1aec11414b421ed299ab32351d182e3297aadd5e
3
+ metadata.gz: bd31e4c0da901e5afa10db5ffb65100b55738d0b
4
+ data.tar.gz: 3c9b3a9d7d76d38eabe936d053af9e2b23326856
5
5
  SHA512:
6
- metadata.gz: dd9f3102fa0ec404c47b7696cc62175aa0c6652a75b277c8ac4c6f760272648f0e63e0593773d21e394a4d39a8a2c11af1e0678ee6e9e5b16a103f3d938f5437
7
- data.tar.gz: 1d11ed30c450aadf5c65de7b7302ab2d9966871d9dc6ef20bff1dea62c276bfdcd88c5523a7b4094450f9678c451c191d550ca95bcf5f574e81f1427ac3d8265
6
+ metadata.gz: 729660cd2276b579ac0d48f81023829d4e4551c7bd179127d7105c073f07503c6297cd313da5f0641a25b7d000e1a4b0c43c935b156948a80bec644d979fa3c8
7
+ data.tar.gz: 3bc3680bc3b71050abadcaa008c48488d41ddf5d81260eca7d11106a56018626800f8b15dc0dbfb37fd4f3a408a36c31ee7ebc1e71a6aed76699fa34519f7dd7
data/README.md CHANGED
@@ -20,6 +20,8 @@ Rails.application.configure do
20
20
  config.basic_auth_mark.position = 'left-bottom' # left-top/right-top/left-bottom/right-bottom
21
21
  # change color(default: 880000)
22
22
  config.basic_auth_mark.color = '0000aa'
23
+ # change markable ip addresses(default: all ip addresses)
24
+ config.basic_auth_mark.markable_ip_addresses = ['127.0.0.1']
23
25
  end
24
26
  ```
25
27
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["kazuki ozawa"]
10
10
  spec.email = ["kazuki.ozawa@outlook.jp"]
11
11
 
12
- spec.summary = %q{Check Whether HTTP Basic Authentication is enabled or not.}
13
- spec.description = %q{Check Whether HTTP Basic Authentication is enabled or not.}
12
+ spec.summary = %q{Show ribbon mark if basic authenticaiton is enabled.}
13
+ spec.description = %q{Show ribbon mark if basic authenticaiton is enabled.}
14
14
  spec.homepage = 'https://github.com/g-ozawa/basic_auth_mark'
15
15
  spec.license = "MIT"
16
16
 
@@ -21,5 +21,17 @@ module BasicAuthMark
21
21
  def color=(color)
22
22
  @color = color
23
23
  end
24
+
25
+ def markable_ip_addresses
26
+ @markable_ip_addresses ||= []
27
+ end
28
+
29
+ def markable_ip_addresses=(markable_ip_addresses)
30
+ if markable_ip_addresses.is_a?(Array)
31
+ @markable_ip_addresses = markable_ip_addresses
32
+ else
33
+ @markable_ip_addresses = [markable_ip_addresses]
34
+ end
35
+ end
24
36
  end
25
37
  end
@@ -12,19 +12,26 @@ module BasicAuthMark
12
12
  return [status, headers, response] unless headers['Content-Type'].to_s =~ %r{\btext/html\b}i
13
13
  return [status, headers, response] if status >= 300 && status < 400
14
14
 
15
- request = Rack::Auth::Basic::Request.new(env)
16
- if request.provided? && request.basic?
17
- new_body = ''
18
- response.each do |b|
19
- begin
20
- new_body << insert_basic_auth_marks(b)
21
- rescue => exception
22
- $stderr.write %Q|Failed to insert basic auth marks: #{exception.message}\n #{exception.backtrace.join(" \n")}|
15
+ markable_ip_addresses = BasicAuthMark.markable_ip_addresses
16
+
17
+ request = Rack::Request.new(env)
18
+
19
+ if markable_ip_addresses.empty? || markable_ip_addresses.include?(request.ip)
20
+ basic_request = Rack::Auth::Basic::Request.new(env)
21
+
22
+ if basic_request.provided? && basic_request.basic?
23
+ new_body = ''
24
+ response.each do |b|
25
+ begin
26
+ new_body << insert_basic_auth_marks(b)
27
+ rescue => exception
28
+ $stderr.write %Q|Failed to insert basic auth marks: #{exception.message}\n #{exception.backtrace.join(" \n")}|
29
+ end
23
30
  end
31
+ response.close if response.respond_to?(:close)
32
+ headers['Content-Length'] &&= new_body.bytesize.to_s
33
+ response = [new_body]
24
34
  end
25
- response.close if response.respond_to?(:close)
26
- headers['Content-Length'] &&= new_body.bytesize.to_s
27
- response = [new_body]
28
35
  end
29
36
 
30
37
  [status, headers, response]
@@ -12,6 +12,7 @@ module BasicAuthMark
12
12
  options = config.basic_auth_mark
13
13
  BasicAuthMark.position = options.position if options.position
14
14
  BasicAuthMark.color = options.color if options.color
15
+ BasicAuthMark.markable_ip_addresses = options.markable_ip_addresses if options.markable_ip_addresses
15
16
  end
16
17
  end
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module BasicAuthMark
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basic_auth_mark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuki ozawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
11
+ date: 2019-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: Check Whether HTTP Basic Authentication is enabled or not.
69
+ description: Show ribbon mark if basic authenticaiton is enabled.
70
70
  email:
71
71
  - kazuki.ozawa@outlook.jp
72
72
  executables: []
@@ -110,5 +110,5 @@ rubyforge_project:
110
110
  rubygems_version: 2.4.5.1
111
111
  signing_key:
112
112
  specification_version: 4
113
- summary: Check Whether HTTP Basic Authentication is enabled or not.
113
+ summary: Show ribbon mark if basic authenticaiton is enabled.
114
114
  test_files: []