keycard 0.2.3 → 0.2.4

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: 11ebd7d6befe9108e42fc03665fad56c487e24d7ae043a3c75ebee3a065cb3da
4
- data.tar.gz: 3ef4f849ece815de42e85cafe7ce1173493753716ea7cfb481ef41cab7429cad
3
+ metadata.gz: 289f06e8e7d3002eba8c6aa13bedf6be9fd2cd643f2923ce8cb5185aeaec6fda
4
+ data.tar.gz: 885e1c86b158ff4778764ea0d2a5ee6bd18ff133e811af47032b42b7a56f0e24
5
5
  SHA512:
6
- metadata.gz: 84c21531e967ff071a7655df6eefe68691609e08bee68b86c1984d85dce0e5bdf615b57fd6668d406dd91d5a5422d86de04582c1b90088a145da44b6a1d78eb6
7
- data.tar.gz: fa8d79a2976c0400cb34407237ce9311f5c01556357a021ecf200587d3bb6003a850b9f1addba939bf0578ad7cad19b6cf38bc5c37f0aef0238a8691a4b9208a
6
+ metadata.gz: 1c510e8be9b90985c08d54c07489368b14911c28d595abe51748acea4ec9f2b5914a06c3425d97afc7e9eeae18c8a7a02b1ca8a3850bc0795f88fb897918b384
7
+ data.tar.gz: d60d7e51da879687dd570c26382947a619f9978309de7cb797bde095e11043e71c28783e85847f22c12beff652b685db8b0dcdeb55b715197ea502fb0f6c7d4f
data/keycard.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  lib = File.expand_path('lib', __dir__)
@@ -88,6 +88,38 @@ module Keycard::Request
88
88
 
89
89
  private
90
90
 
91
+ # Retrieve the value from the request's environment for a given key.
92
+ #
93
+ # This will trim whitespace and yield nil for empty values or those with
94
+ # the special value of '(null)'. Use {#safe} if you always want a string.
95
+ #
96
+ # @return [String|nil] value for the key, filtered and trimmed to nil
97
+ def get(key)
98
+ scrub request.env[key]
99
+ end
100
+
101
+ # Retrieve a guaranteed string value from the request's environment for a
102
+ # given key.
103
+ #
104
+ # This has the same behavior as {#get}, except that it will coalesce
105
+ # missing values to an empty string, convenient if you need to do string
106
+ # operations like splitting the value.
107
+ def safe(key)
108
+ get(key) || ''
109
+ end
110
+
111
+ # Scrub a value to remove whitespace, filter the special '(null)' value,
112
+ # and translate resulting empty strings to nil.
113
+ def scrub(value)
114
+ str = (value || '').strip
115
+ case str
116
+ when nil, '(null)', ''
117
+ nil
118
+ else
119
+ str
120
+ end
121
+ end
122
+
91
123
  attr_reader :finders
92
124
  attr_reader :request
93
125
  end
@@ -15,7 +15,7 @@ module Keycard::Request
15
15
  end
16
16
 
17
17
  def user_pid
18
- request.env['HTTP_X_REMOTE_USER']
18
+ get 'HTTP_X_REMOTE_USER'
19
19
  end
20
20
 
21
21
  def user_eid
@@ -23,7 +23,7 @@ module Keycard::Request
23
23
  end
24
24
 
25
25
  def client_ip
26
- (request.env['HTTP_X_FORWARDED_FOR'] || '').split(',').first
26
+ safe('HTTP_X_FORWARDED_FOR').split(',').first
27
27
  end
28
28
  end
29
29
  end
@@ -14,7 +14,7 @@ module Keycard::Request
14
14
  end
15
15
 
16
16
  def user_pid
17
- request.env['REMOTE_USER']
17
+ get 'REMOTE_USER'
18
18
  end
19
19
 
20
20
  def user_eid
@@ -22,7 +22,7 @@ module Keycard::Request
22
22
  end
23
23
 
24
24
  def client_ip
25
- (request.env['REMOTE_ADDR'] || '').split(',').first
25
+ safe('REMOTE_ADDR').split(',').first
26
26
  end
27
27
  end
28
28
  end
@@ -18,7 +18,7 @@ module Keycard::Request
18
18
  end
19
19
 
20
20
  def user_pid
21
- request.env['HTTP_X_REMOTE_USER']
21
+ get 'HTTP_X_REMOTE_USER'
22
22
  end
23
23
 
24
24
  def user_eid
@@ -26,7 +26,7 @@ module Keycard::Request
26
26
  end
27
27
 
28
28
  def client_ip
29
- (request.env['HTTP_X_FORWARDED_FOR'] || '').split(',').first
29
+ safe('HTTP_X_FORWARDED_FOR').split(',').first
30
30
  end
31
31
  end
32
32
  end
@@ -72,15 +72,5 @@ module Keycard::Request
72
72
  def identity_keys
73
73
  %i[user_pid user_eid eduPersonScopedAffiliation]
74
74
  end
75
-
76
- private
77
-
78
- def get(key)
79
- request.env[key]
80
- end
81
-
82
- def safe(key)
83
- get(key) || ''
84
- end
85
75
  end
86
76
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Keycard
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Botimer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-19 00:00:00.000000000 Z
12
+ date: 2018-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel