authorized_networks 1.0.0 → 1.0.1

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: f566c1e34f168c5114387ed6d83898eebde38521ed2968e0905475a7fdae9838
4
- data.tar.gz: 2b6347ee201917c2bff2bd5453014c67e4160ab742a59f99d10518c02f2ac9e2
3
+ metadata.gz: 3954c21789b8c65cf2317bb9ddc52f25dd181a565accbe591a4e33d5768ffc5b
4
+ data.tar.gz: 06fbc9eb20a3e43cb5a232eded7b8488afca862475c4f693a21fb938cc8df58d
5
5
  SHA512:
6
- metadata.gz: 26900b8f10c3843cd8570a2f2f206324c8ff6705c0996a1faa3229f0a80285f826e6a27566530e49195cec2de0dddda217218eb5d0b3a935ff18597a93840edd
7
- data.tar.gz: 5de810d467c3666a7f7137c0044e31b373ba7bb4e053f2c1375dac327b396ae435569201c213c6518d37c9d782764cb70008ccef9a99d4a41b0b515ca8ddc239
6
+ metadata.gz: c28e96f6885162c0b2e4f49b72d17859d5ba97ea95aaa0cfb2cf5f299efb35aa94327e8a5fab2b8e6eb986e95f92f44885f29adbcc8518218c96ad05c9ee0dac
7
+ data.tar.gz: b9314211914c77f1cd00fe718df558fe3c4caa50d1fe444f55c67149971ddc2389b2e9a2cd51f26428aa00a50062002f31812dd0205424f68232ca63af0d644a
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- �O�%|�T�́Ҏ�ڊ��N��5}�(9��)�g�5�l8���5ˊ ���"fūWe����Y����(�5��b���"���d�!�~��%�Y��>G�ߕ�䳟E���D:t�G1�m�����/fk�q/¨�;� ��9˼ٶ"�c�\�)�y�\�H�&�l��,j�6Ӌd�/F<�+.O~�W�}ظ��G�~�����^�қ���-:���A�i�Ѥ��slW�L9�f�m&���H��9yZ{,s_{3x���kp���Nw��+��'�q,�}Y��Qo�b��
1
+ �-C��!�-�sg��)��Å{��.���ve���O��u��T0��!�ƍ^�!
2
+ ͻQ��Ke����C�#{����+�(�[�1D�K+Q��5M]��|7��q��&=��]�(��5��o2����Ԋ�eZ��]3�M�����4��P�������wl�53Lͭ�٪t�C��Ȝ���ìS|�*y勏��ӥ)�g��\6}�b]{���>�n>�;��3��–���O`���0A�QXL�lš�v�������u'�J�P~�8
data.tar.gz.sig CHANGED
Binary file
@@ -30,6 +30,19 @@ module AuthorizedNetworks
30
30
  end
31
31
  attr_writer :network_list_cache_ttl
32
32
 
33
+ # Is this disabled?
34
+ #
35
+ # @return [Boolean]
36
+ def disabled?
37
+ @disabled || false
38
+ end
39
+
40
+ # Disable everything. Any call to valid_ip? will be returned as true and no
41
+ # network lists will be loaded.
42
+ def disable!
43
+ @disabled = true
44
+ end
45
+
33
46
  private
34
47
 
35
48
  def find_default_networks_file_path
@@ -20,7 +20,15 @@ module AuthorizedNetworks
20
20
 
21
21
  @networks ||= begin
22
22
  if @config.networks
23
- normalize_ips(@config.networks)
23
+ if @config.networks.is_a?(Proc)
24
+ normalize_ips(@config.networks.call)
25
+ elsif @config.networks.is_a?(Hash)
26
+ normalize_ips(@config.networks)
27
+ elsif @config.networks.is_a?(Array)
28
+ normalize_ips(:default => @config.networks)
29
+ else
30
+ {}
31
+ end
24
32
  elsif File.exist?(@config.networks_file_path)
25
33
  @networks_cached_at = Time.now.utc
26
34
  normalize_ips(YAML.safe_load(File.read(@config.networks_file_path)))
@@ -34,6 +42,8 @@ module AuthorizedNetworks
34
42
  #
35
43
  # @return [Boolean]
36
44
  def valid_ip?(ip, options = {})
45
+ return true if @config.disabled?
46
+
37
47
  ip = IPAddr.new(ip.to_s) rescue nil
38
48
  return false unless ip.is_a?(IPAddr)
39
49
  groups = options[:groups] || @config.default_groups
@@ -61,10 +71,14 @@ module AuthorizedNetworks
61
71
  hash.each_with_object({}) do |(group_name, networks), hash|
62
72
  networks = [networks.to_s] unless networks.is_a?(Array)
63
73
  hash[group_name.to_sym] = networks.map do |network|
64
- begin
65
- IPAddr.new(network.to_s)
66
- rescue IPAddr::InvalidAddressError
67
- nil
74
+ if network.is_a?(IPAddr)
75
+ network
76
+ else
77
+ begin
78
+ IPAddr.new(network.to_s)
79
+ rescue IPAddr::InvalidAddressError
80
+ nil
81
+ end
68
82
  end
69
83
  end.compact
70
84
  end
@@ -1,3 +1,3 @@
1
1
  module AuthorizedNetworks
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authorized_networks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
@@ -35,7 +35,7 @@ cert_chain:
35
35
  iyQrH6PJ0xgVJNYx+DLq3eFmo2hYJkw/lVhYAK+MdajtYJbD5VvCIEHO0d5RRgV+
36
36
  qnCNZoPPy0UtRmGKZTMZvVJEZiw4g0fY
37
37
  -----END CERTIFICATE-----
38
- date: 2018-03-06 00:00:00.000000000 Z
38
+ date: 2018-03-07 00:00:00.000000000 Z
39
39
  dependencies: []
40
40
  description: An easy way to verify IPs are on authorized networkjs.
41
41
  email:
metadata.gz.sig CHANGED
Binary file