fog-core 1.24.0 → 1.25.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 +5 -13
- data/.rubocop.yml +20 -0
- data/changelog.md +17 -0
- data/fog-core.gemspec +2 -1
- data/lib/fog/account.rb +3 -5
- data/lib/fog/billing.rb +3 -4
- data/lib/fog/cdn.rb +3 -5
- data/lib/fog/compute.rb +17 -20
- data/lib/fog/compute/models/server.rb +21 -26
- data/lib/fog/core.rb +61 -60
- data/lib/fog/core/association.rb +15 -0
- data/lib/fog/core/associations/default.rb +21 -3
- data/lib/fog/core/associations/many_identities.rb +8 -2
- data/lib/fog/core/associations/many_models.rb +7 -2
- data/lib/fog/core/associations/one_identity.rb +6 -1
- data/lib/fog/core/associations/one_model.rb +5 -1
- data/lib/fog/core/attributes.rb +41 -44
- data/lib/fog/core/attributes/array.rb +5 -1
- data/lib/fog/core/attributes/boolean.rb +5 -1
- data/lib/fog/core/attributes/default.rb +12 -2
- data/lib/fog/core/attributes/float.rb +5 -1
- data/lib/fog/core/attributes/integer.rb +5 -1
- data/lib/fog/core/attributes/string.rb +5 -1
- data/lib/fog/core/attributes/time.rb +5 -1
- data/lib/fog/core/attributes/timestamp.rb +5 -1
- data/lib/fog/core/collection.rb +22 -27
- data/lib/fog/core/connection.rb +5 -6
- data/lib/fog/core/credentials.rb +7 -7
- data/lib/fog/core/current_machine.rb +10 -8
- data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
- data/lib/fog/core/deprecation.rb +0 -2
- data/lib/fog/core/errors.rb +3 -5
- data/lib/fog/core/hmac.rb +4 -6
- data/lib/fog/core/logger.rb +10 -11
- data/lib/fog/core/mock.rb +19 -25
- data/lib/fog/core/model.rb +9 -20
- data/lib/fog/core/provider.rb +6 -9
- data/lib/fog/core/scp.rb +14 -24
- data/lib/fog/core/service.rb +28 -31
- data/lib/fog/core/ssh.rb +16 -24
- data/lib/fog/core/stringify_keys.rb +7 -9
- data/lib/fog/core/time.rb +5 -7
- data/lib/fog/core/utils.rb +24 -20
- data/lib/fog/core/uuid.rb +2 -3
- data/lib/fog/core/version.rb +3 -1
- data/lib/fog/core/wait_for.rb +2 -2
- data/lib/fog/core/wait_for_defaults.rb +13 -10
- data/lib/fog/core/whitelist_keys.rb +1 -1
- data/lib/fog/dns.rb +6 -8
- data/lib/fog/identity.rb +5 -6
- data/lib/fog/image.rb +3 -5
- data/lib/fog/metering.rb +3 -6
- data/lib/fog/monitoring.rb +3 -5
- data/lib/fog/network.rb +4 -6
- data/lib/fog/orchestration.rb +3 -5
- data/lib/fog/schema/data_validator.rb +17 -22
- data/lib/fog/storage.rb +22 -16
- data/lib/fog/support.rb +3 -6
- data/lib/fog/test_helpers.rb +10 -10
- data/lib/fog/test_helpers/collection_helper.rb +23 -43
- data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
- data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
- data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
- data/lib/fog/test_helpers/formats_helper.rb +13 -14
- data/lib/fog/test_helpers/helper.rb +9 -4
- data/lib/fog/test_helpers/mock_helper.rb +92 -94
- data/lib/fog/test_helpers/model_helper.rb +7 -15
- data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
- data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
- data/lib/fog/volume.rb +3 -6
- data/lib/fog/vpn.rb +3 -5
- data/lib/tasks/test_task.rb +2 -6
- data/spec/compute_spec.rb +11 -13
- data/spec/connection_spec.rb +24 -14
- data/spec/credentials_spec.rb +23 -23
- data/spec/current_machine_spec.rb +6 -6
- data/spec/fake_app/fake_service.rb +18 -0
- data/spec/fake_app/models/collection.rb +5 -0
- data/spec/fake_app/models/model.rb +2 -0
- data/spec/fake_app/requests/request.rb +11 -0
- data/spec/fog_attribute_spec.rb +178 -136
- data/spec/identity_spec.rb +11 -13
- data/spec/mocking_spec.rb +7 -8
- data/spec/service_spec.rb +21 -7
- data/spec/spec_helper.rb +14 -8
- data/spec/storage_spec.rb +25 -13
- data/spec/test_helpers/formats_helper_spec.rb +52 -52
- data/spec/test_helpers/schema_validator_spec.rb +45 -45
- data/spec/timeout_spec.rb +1 -2
- data/spec/utils_spec.rb +2 -2
- data/spec/uuid_spec.rb +1 -1
- data/spec/wait_for_spec.rb +7 -4
- metadata +57 -33
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fog
|
2
|
+
class Association < Collection
|
3
|
+
def initialize(associations = [])
|
4
|
+
@loaded = true
|
5
|
+
load(associations)
|
6
|
+
end
|
7
|
+
|
8
|
+
def load(associations)
|
9
|
+
return unless associations.kind_of?(Array)
|
10
|
+
associations.each do |association|
|
11
|
+
self << association
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,15 +1,33 @@
|
|
1
1
|
module Fog
|
2
2
|
module Associations
|
3
|
+
# = Fog Default Association
|
4
|
+
#
|
5
|
+
# This class has the shared behavior between all association models.
|
3
6
|
class Default
|
4
|
-
attr_reader :model, :name
|
7
|
+
attr_reader :model, :name, :aliases, :as, :association_class
|
5
8
|
|
6
|
-
def initialize(model, name, collection_name)
|
9
|
+
def initialize(model, name, collection_name, options)
|
7
10
|
@model = model
|
8
11
|
@name = name
|
9
12
|
model.associations[name] = collection_name
|
13
|
+
@aliases = options.fetch(:aliases, [])
|
14
|
+
@as = options.fetch(:as, name)
|
15
|
+
@association_class = options.fetch(:association_class, Fog::Association)
|
10
16
|
create_setter
|
11
17
|
create_getter
|
18
|
+
create_aliases
|
19
|
+
create_mask
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_aliases
|
23
|
+
Array(aliases).each do |alias_name|
|
24
|
+
model.aliases[alias_name] = name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_mask
|
29
|
+
model.masks[name] = as
|
12
30
|
end
|
13
31
|
end
|
14
32
|
end
|
15
|
-
end
|
33
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Fog
|
2
2
|
module Associations
|
3
|
+
# = Fog Multiple Association
|
4
|
+
#
|
5
|
+
# This class handles multiple association between the models.
|
6
|
+
# It expects the provider to return a collection of ids.
|
7
|
+
# The association models will be loaded based on the collection of ids.
|
3
8
|
class ManyIdentities < Default
|
4
9
|
def create_setter
|
5
10
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -15,12 +20,13 @@ module Fog
|
|
15
20
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
16
21
|
def #{name}
|
17
22
|
return [] if associations[:#{name}].nil?
|
18
|
-
Array(associations[:#{name}]).map do |association|
|
23
|
+
data = Array(associations[:#{name}]).map do |association|
|
19
24
|
service.send(self.class.associations[:#{name}]).get(association)
|
20
25
|
end
|
26
|
+
#{association_class}.new(data)
|
21
27
|
end
|
22
28
|
EOS
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
26
|
-
end
|
32
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Associations
|
3
|
+
# = Fog Multiple Association
|
4
|
+
#
|
5
|
+
# This class handles multiple association between the models.
|
6
|
+
# It expects the provider to map the attribute with a collection of objects.
|
3
7
|
class ManyModels < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -12,10 +16,11 @@ module Fog
|
|
12
16
|
def create_getter
|
13
17
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
14
18
|
def #{name}
|
15
|
-
|
19
|
+
data = associations[:#{name}]
|
20
|
+
#{association_class}.new(data)
|
16
21
|
end
|
17
22
|
EOS
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
21
|
-
end
|
26
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Fog
|
2
2
|
module Associations
|
3
|
+
# = Fog Single Association
|
4
|
+
#
|
5
|
+
# This class handles single association between the models.
|
6
|
+
# It expects the provider to return only the id of the association.
|
7
|
+
# The association model will be loaded based on the id initialized.
|
3
8
|
class OneIdentity < Default
|
4
9
|
def create_setter
|
5
10
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -19,4 +24,4 @@ module Fog
|
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
22
|
-
end
|
27
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Associations
|
3
|
+
# = Fog Single Association
|
4
|
+
#
|
5
|
+
# This class handles single association between the models.
|
6
|
+
# It expects the provider to map the attribute with an initialized object.
|
3
7
|
class OneModel < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -18,4 +22,4 @@ module Fog
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
21
|
-
end
|
25
|
+
end
|
data/lib/fog/core/attributes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
3
|
module ClassMethods
|
4
|
-
|
5
4
|
def _load(marshalled)
|
6
5
|
new(Marshal.load(marshalled))
|
7
6
|
end
|
@@ -22,45 +21,47 @@ module Fog
|
|
22
21
|
@default_values ||= {}
|
23
22
|
end
|
24
23
|
|
24
|
+
def masks
|
25
|
+
@masks ||= {}
|
26
|
+
end
|
27
|
+
|
25
28
|
def attribute(name, options = {})
|
26
|
-
type = options.fetch(:type,
|
27
|
-
Fog::Attributes
|
29
|
+
type = options.fetch(:type, "default").to_s.capitalize
|
30
|
+
Fog::Attributes.const_get(type).new(self, name, options)
|
28
31
|
end
|
29
32
|
|
30
|
-
def has_one(name, collection_name)
|
31
|
-
Fog::Associations::OneModel.new(self, name, collection_name)
|
33
|
+
def has_one(name, collection_name, options = {})
|
34
|
+
Fog::Associations::OneModel.new(self, name, collection_name, options)
|
32
35
|
end
|
33
36
|
|
34
|
-
def has_many(name, collection_name)
|
35
|
-
Fog::Associations::ManyModels.new(self, name, collection_name)
|
37
|
+
def has_many(name, collection_name, options = {})
|
38
|
+
Fog::Associations::ManyModels.new(self, name, collection_name, options)
|
36
39
|
end
|
37
40
|
|
38
|
-
def has_one_identity(name, collection_name)
|
39
|
-
Fog::Associations::OneIdentity.new(self, name, collection_name)
|
41
|
+
def has_one_identity(name, collection_name, options = {})
|
42
|
+
Fog::Associations::OneIdentity.new(self, name, collection_name, options)
|
40
43
|
end
|
41
44
|
|
42
|
-
def has_many_identities(name, collection_name)
|
43
|
-
Fog::Associations::ManyIdentities.new(self, name, collection_name)
|
45
|
+
def has_many_identities(name, collection_name, options = {})
|
46
|
+
Fog::Associations::ManyIdentities.new(self, name, collection_name, options)
|
44
47
|
end
|
45
48
|
|
46
49
|
def identity(name, options = {})
|
47
50
|
@identity = name
|
48
|
-
|
51
|
+
attribute(name, options)
|
49
52
|
end
|
50
53
|
|
51
54
|
def ignore_attributes(*args)
|
52
|
-
@ignored_attributes = args.
|
55
|
+
@ignored_attributes = args.map(&:to_s)
|
53
56
|
end
|
54
57
|
|
55
58
|
def ignored_attributes
|
56
59
|
@ignored_attributes ||= []
|
57
60
|
end
|
58
|
-
|
59
61
|
end
|
60
62
|
|
61
63
|
module InstanceMethods
|
62
|
-
|
63
|
-
def _dump(level)
|
64
|
+
def _dump(_level)
|
64
65
|
Marshal.dump(attributes)
|
65
66
|
end
|
66
67
|
|
@@ -72,16 +73,20 @@ module Fog
|
|
72
73
|
@associations ||= {}
|
73
74
|
end
|
74
75
|
|
76
|
+
def masks
|
77
|
+
self.class.masks
|
78
|
+
end
|
79
|
+
|
75
80
|
def all_attributes
|
76
|
-
self.class.attributes.
|
77
|
-
hash[attribute] = send(attribute)
|
81
|
+
self.class.attributes.reduce({}) do |hash, attribute|
|
82
|
+
hash[masks[attribute]] = send(attribute)
|
78
83
|
hash
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
82
87
|
def all_associations
|
83
|
-
self.class.associations.keys.
|
84
|
-
hash[association] = associations[association] || send(association)
|
88
|
+
self.class.associations.keys.reduce({}) do |hash, association|
|
89
|
+
hash[masks[association]] = associations[association] || send(association)
|
85
90
|
hash
|
86
91
|
end
|
87
92
|
end
|
@@ -97,23 +102,22 @@ module Fog
|
|
97
102
|
end
|
98
103
|
|
99
104
|
def identity
|
100
|
-
send(self.class.instance_variable_get(
|
105
|
+
send(self.class.instance_variable_get("@identity"))
|
101
106
|
end
|
102
107
|
|
103
108
|
def identity=(new_identity)
|
104
|
-
send("#{self.class.instance_variable_get(
|
109
|
+
send("#{self.class.instance_variable_get("@identity")}=", new_identity)
|
105
110
|
end
|
106
111
|
|
107
112
|
def merge_attributes(new_attributes = {})
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
113
|
+
new_attributes.each_pair do |key, value|
|
114
|
+
next if self.class.ignored_attributes.include?(key)
|
115
|
+
if self.class.aliases[key]
|
116
|
+
send("#{self.class.aliases[key]}=", value)
|
117
|
+
elsif self.respond_to?("#{key}=", true)
|
118
|
+
send("#{key}=", value)
|
119
|
+
else
|
120
|
+
attributes[key] = value
|
117
121
|
end
|
118
122
|
end
|
119
123
|
self
|
@@ -151,20 +155,16 @@ module Fog
|
|
151
155
|
end
|
152
156
|
|
153
157
|
def requires_one(*args)
|
154
|
-
|
155
|
-
|
156
|
-
raise(ArgumentError, "#{missing[0...-1].join(", ")} or #{missing[-1]} are required for this operation")
|
157
|
-
end
|
158
|
+
return unless missing_attributes(args).length == args.length
|
159
|
+
raise(ArgumentError, "#{missing[0...-1].join(", ")} or #{missing[-1]} are required for this operation")
|
158
160
|
end
|
159
161
|
|
160
162
|
protected
|
161
163
|
|
162
164
|
def missing_attributes(args)
|
163
165
|
missing = []
|
164
|
-
|
165
|
-
unless send("#{arg}") || attributes.
|
166
|
-
missing << arg
|
167
|
-
end
|
166
|
+
([:service] | args).each do |arg|
|
167
|
+
missing << arg unless send("#{arg}") || attributes.key?(arg)
|
168
168
|
end
|
169
169
|
missing
|
170
170
|
end
|
@@ -176,13 +176,10 @@ module Fog
|
|
176
176
|
private
|
177
177
|
|
178
178
|
def remap_attributes(attributes, mapping)
|
179
|
-
|
180
|
-
if attributes.key?(key)
|
181
|
-
attributes[value] = attributes.delete(key)
|
182
|
-
end
|
179
|
+
mapping.each_pair do |key, value|
|
180
|
+
attributes[value] = attributes.delete(key) if attributes.key?(key)
|
183
181
|
end
|
184
182
|
end
|
185
|
-
|
186
183
|
end
|
187
184
|
end
|
188
185
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Array Attribute
|
4
|
+
#
|
5
|
+
# This class handles Array attributes from the providers,
|
6
|
+
# converting values to Array objects
|
3
7
|
class Array < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -18,4 +22,4 @@ module Fog
|
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
21
|
-
end
|
25
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Boolean Attribute
|
4
|
+
#
|
5
|
+
# This class handles Boolean attributes from the providers,
|
6
|
+
# converting values to Boolean objects
|
3
7
|
class Boolean < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -15,4 +19,4 @@ module Fog
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
18
|
-
end
|
22
|
+
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Default Attribute
|
4
|
+
#
|
5
|
+
# This class handles the attributes without a type force.
|
6
|
+
# The attributes returned from the provider will keep its original values.
|
3
7
|
class Default
|
4
|
-
attr_reader :model, :name, :squash, :aliases, :default
|
8
|
+
attr_reader :model, :name, :squash, :aliases, :default, :as
|
5
9
|
|
6
10
|
def initialize(model, name, options)
|
7
11
|
@model = model
|
@@ -10,10 +14,12 @@ module Fog
|
|
10
14
|
@squash = options.fetch(:squash, false)
|
11
15
|
@aliases = options.fetch(:aliases, [])
|
12
16
|
@default = options[:default]
|
17
|
+
@as = options.fetch(:as, name)
|
13
18
|
create_setter
|
14
19
|
create_getter
|
15
20
|
create_aliases
|
16
21
|
set_defaults
|
22
|
+
create_mask
|
17
23
|
end
|
18
24
|
|
19
25
|
def create_setter
|
@@ -63,6 +69,10 @@ module Fog
|
|
63
69
|
def set_defaults
|
64
70
|
model.default_values[name] = default unless default.nil?
|
65
71
|
end
|
72
|
+
|
73
|
+
def create_mask
|
74
|
+
model.masks[name] = as
|
75
|
+
end
|
66
76
|
end
|
67
77
|
end
|
68
|
-
end
|
78
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Float Attribute
|
4
|
+
#
|
5
|
+
# This class handles Float attributes from the providers,
|
6
|
+
# converting values to Float objects
|
3
7
|
class Float < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -10,4 +14,4 @@ module Fog
|
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Integer Attribute
|
4
|
+
#
|
5
|
+
# This class handles Integer attributes from the providers,
|
6
|
+
# converting values to Integer objects
|
3
7
|
class Integer < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -10,4 +14,4 @@ module Fog
|
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog String Attribute
|
4
|
+
#
|
5
|
+
# This class handles String attributes from the providers,
|
6
|
+
# converting values to String objects
|
3
7
|
class String < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -10,4 +14,4 @@ module Fog
|
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
13
|
-
end
|
17
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Time Attribute
|
4
|
+
#
|
5
|
+
# This class handles Time attributes from the providers,
|
6
|
+
# converting values to Time objects
|
3
7
|
class Time < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -16,4 +20,4 @@ module Fog
|
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
19
|
-
end
|
23
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Fog
|
2
2
|
module Attributes
|
3
|
+
# = Fog Timestamp Attribute
|
4
|
+
#
|
5
|
+
# This class handles Timestamp attributes from the providers,
|
6
|
+
# converting Integer and String values as a real Timestamp objects
|
3
7
|
class Timestamp < Default
|
4
8
|
def create_setter
|
5
9
|
model.class_eval <<-EOS, __FILE__, __LINE__
|
@@ -14,4 +18,4 @@ module Fog
|
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|