aws-cache 0.0.03 → 0.0.04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/aws-cache.rb +15 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWExNjliYjZjZmViNDU2MmJiNmJlZDA4OGNmYTlkMWIyMWVjZDk0MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Njk1ZmYxMjgzYjQ5M2IyMWY0OGUxOTNkMzIzMGZkM2I1ZDcwMTFlZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzFjYzZiNzVlN2Y1NzhjZWQ1ZjE1MzE1M2MzMDk0MjIwNTAzZTBhMTZlNDBk
|
10
|
+
MmFkODAzYTY2MzAwZDMzOGUyYzkwNDcyYjBkYjI1ZWJlYjdhYzUwMGQ3Y2Mx
|
11
|
+
NGQxMDQ0YmU5MTYxYTI2ZDdhNjc0ZTc2YjAyYzE4MDJmZGI0ZmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGQzOTA1NjcyZWY2NDZmYmVlODgzYWE2OGZlNzcyODFhZDIxYjRiOWZkNjZh
|
14
|
+
OGJkZGNjNTg0ZDNhZGFjMGFkMjk1OTczYmY0NzIzMDRjYzY2ZGZkMGE1MTY4
|
15
|
+
ZTE4NjRhMzBkNjM2MWI5YjcyNjhmOWQxYjJkMjFlOTcyZDY3MDc=
|
data/lib/aws-cache.rb
CHANGED
@@ -2,6 +2,7 @@ require 'redis'
|
|
2
2
|
require 'json'
|
3
3
|
require 'aws-sdk'
|
4
4
|
require 'yaml'
|
5
|
+
require 'pry'
|
5
6
|
|
6
7
|
class AwsCache
|
7
8
|
# Please follow semantic versioning (semver.org).
|
@@ -43,7 +44,7 @@ class AwsCache
|
|
43
44
|
instances = self.ec2_instances
|
44
45
|
stack_instances = {}
|
45
46
|
instances.each do |id, instance|
|
46
|
-
if stack_name == optional_element(instance, [
|
47
|
+
if stack_name == optional_element(instance, [:tags,'StackName',:value], '')
|
47
48
|
stack_instances[id] = instance
|
48
49
|
end
|
49
50
|
end
|
@@ -75,7 +76,7 @@ class AwsCache
|
|
75
76
|
groups = self.auto_scaling_groups
|
76
77
|
stack_groups = {}
|
77
78
|
groups.each do |name, group|
|
78
|
-
if stack_name == optional_element(group, [
|
79
|
+
if stack_name == optional_element(group, [:tags,'StackName',:value], '')
|
79
80
|
stack_groups[name] = group
|
80
81
|
end
|
81
82
|
end
|
@@ -152,7 +153,7 @@ class AwsCache
|
|
152
153
|
private
|
153
154
|
def optional_element(hash, keys, default=nil)
|
154
155
|
keys.each do |key|
|
155
|
-
if !
|
156
|
+
if !has_key?(hash, key)
|
156
157
|
return default
|
157
158
|
end
|
158
159
|
hash = hash[key]
|
@@ -160,6 +161,17 @@ class AwsCache
|
|
160
161
|
return hash
|
161
162
|
end
|
162
163
|
|
164
|
+
def has_key?(hash_or_struct, key)
|
165
|
+
hos = hash_or_struct
|
166
|
+
if hos.is_a?(Hash) && hos.has_key?(key)
|
167
|
+
return true
|
168
|
+
end
|
169
|
+
if hos.is_a?(Struct) && hos.members.any? { |m| m == key }
|
170
|
+
return true
|
171
|
+
end
|
172
|
+
return false
|
173
|
+
end
|
174
|
+
|
163
175
|
def cache_get(key, ttl)
|
164
176
|
vkey = "#{key}_#{@keyspace}"
|
165
177
|
hash = @redis.get(vkey)
|