skull_island 1.2.6 → 1.2.7

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: 2aee1d0a664e3a03c0ef1139816708264a40d39a324b7698cec10e5ebe303972
4
- data.tar.gz: af415232480d26cce9582d68f9e8384dcf0e8027efb7371ad1f9341a5fbd065c
3
+ metadata.gz: e8e575e528393418b57488afb653a8baa09afa06f97b88e86fcc7d984fb5bba6
4
+ data.tar.gz: a6a00f4e7c432fa0cfd77f6cc22b3cbbdc936043d12ac68e337d4500e8bb42d8
5
5
  SHA512:
6
- metadata.gz: cc1cdf72aee4a83b61284f12da0c80112d7fe66e2ddeeafdaadfe55758228c410a23b3f400e0e3bdb5d2e107f370e2c3766508bc99676f135e7aaefbb30db903
7
- data.tar.gz: b119e25b9a1557f5faffb204da95e86a20800dfbe0baec31ecdc816a9d39bd40c795b9010f7c832c1255e6c8cb8266c4cbbb662360b0b1da37a4de9e776c5e58
6
+ metadata.gz: 892f21ee6b9d43f943cbb562ae72d62e936928acc562752f8d3a7b42c3713a7281408fa401f49eb6c6394d34659131c0288c4c7832c3e5608bb58f67ee040ed3
7
+ data.tar.gz: 047ce3c0207470966af51a017d71ee23bcfa03fbe0a4371defdc4a1405e697549e519349af71ef5c3a6bcdfc8cc41d85201106d19a672d68e2fcbe8ae5d73fa9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- skull_island (1.2.6)
4
+ skull_island (1.2.7)
5
5
  deepsort (~> 0.4)
6
6
  erubi (~> 1.8)
7
7
  json (~> 2.1)
@@ -5,10 +5,12 @@ module SkullIsland
5
5
  module Resources
6
6
  # The BasicauthCredential resource class
7
7
  #
8
- # @see https://docs.konghq.com/hub/kong-inc/key-auth/ Key-Auth API definition
8
+ # @see https://docs.konghq.com/hub/kong-inc/basic-auth/ Basic-Auth API definition
9
9
  class BasicauthCredential < Resource
10
+ attr_accessor :hashed_password
11
+
10
12
  property :username, required: true, validate: true
11
- property :password, validated: true
13
+ property :password, validated: true, preprocess: true, postprocess: true
12
14
  property(
13
15
  :consumer,
14
16
  required: true, validate: true, preprocess: true, postprocess: true
@@ -44,6 +46,17 @@ module SkullIsland
44
46
  consumer ? "#{consumer.relative_uri}/basic-auth" : nil
45
47
  end
46
48
 
49
+ def digest
50
+ Digest::MD5.hexdigest(
51
+ if new? && !password.match?(/^hash{.+}$/)
52
+ hashed_pass = Digest::SHA1.hexdigest((password || '') + consumer.id)
53
+ "#{username}:hash{#{hashed_pass}}"
54
+ else
55
+ "#{username}:#{password}"
56
+ end
57
+ )
58
+ end
59
+
47
60
  def export(options = {})
48
61
  hash = { 'username' => username, 'password' => password }
49
62
  hash['consumer'] = "<%= lookup :consumer, '#{consumer.username}' %>" if consumer
@@ -56,15 +69,41 @@ module SkullIsland
56
69
  hash.reject { |_, value| value.nil? }
57
70
  end
58
71
 
59
- # Keys can't be updated, only created or deleted
72
+ # Credentials can't be updated, only deleted then created
60
73
  def modified_existing?
61
- false
74
+ return false unless new?
75
+
76
+ # Find credentials of the same username
77
+ basic_auths = consumer.credentials['basic-auth']
78
+ return false unless basic_auths
79
+
80
+ same_username = basic_auths.where(:username, username)
81
+
82
+ existing = same_username.size == 1 ? same_username.first : nil
83
+ # Need to destroy the old one then save the new one...
84
+ existing ? existing.destroy && save : false
62
85
  end
63
86
 
64
87
  def project
65
88
  consumer ? consumer.project : nil
66
89
  end
67
90
 
91
+ def <=>(other)
92
+ if id
93
+ if id < other.id
94
+ -1
95
+ elsif id > other.id
96
+ 1
97
+ elsif id == other.id
98
+ 0
99
+ else
100
+ raise Exceptions::InvalidArguments
101
+ end
102
+ else
103
+ digest <=> other.digest
104
+ end
105
+ end
106
+
68
107
  private
69
108
 
70
109
  def postprocess_consumer(value)
@@ -87,6 +126,19 @@ module SkullIsland
87
126
  end
88
127
  end
89
128
 
129
+ def postprocess_password(value)
130
+ hashed_password || !new? ? "hash{#{value}}" : value
131
+ end
132
+
133
+ def preprocess_password(input)
134
+ if input.match?(/^hash{.+}$/)
135
+ @hashed_password = true
136
+ input.match(/^hash{(.+)}$/)[1]
137
+ else
138
+ input
139
+ end
140
+ end
141
+
90
142
  # Used to validate {#consumer} on set
91
143
  def validate_consumer(value)
92
144
  # allow either a Consumer object or a Hash
@@ -4,6 +4,6 @@ module SkullIsland
4
4
  VERSION = [
5
5
  1, # Major
6
6
  2, # Minor
7
- 6 # Patch
7
+ 7 # Patch
8
8
  ].join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skull_island
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-14 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deepsort