fog-core 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +20 -0
  3. data/changelog.md +17 -0
  4. data/fog-core.gemspec +2 -1
  5. data/lib/fog/account.rb +3 -5
  6. data/lib/fog/billing.rb +3 -4
  7. data/lib/fog/cdn.rb +3 -5
  8. data/lib/fog/compute.rb +17 -20
  9. data/lib/fog/compute/models/server.rb +21 -26
  10. data/lib/fog/core.rb +61 -60
  11. data/lib/fog/core/association.rb +15 -0
  12. data/lib/fog/core/associations/default.rb +21 -3
  13. data/lib/fog/core/associations/many_identities.rb +8 -2
  14. data/lib/fog/core/associations/many_models.rb +7 -2
  15. data/lib/fog/core/associations/one_identity.rb +6 -1
  16. data/lib/fog/core/associations/one_model.rb +5 -1
  17. data/lib/fog/core/attributes.rb +41 -44
  18. data/lib/fog/core/attributes/array.rb +5 -1
  19. data/lib/fog/core/attributes/boolean.rb +5 -1
  20. data/lib/fog/core/attributes/default.rb +12 -2
  21. data/lib/fog/core/attributes/float.rb +5 -1
  22. data/lib/fog/core/attributes/integer.rb +5 -1
  23. data/lib/fog/core/attributes/string.rb +5 -1
  24. data/lib/fog/core/attributes/time.rb +5 -1
  25. data/lib/fog/core/attributes/timestamp.rb +5 -1
  26. data/lib/fog/core/collection.rb +22 -27
  27. data/lib/fog/core/connection.rb +5 -6
  28. data/lib/fog/core/credentials.rb +7 -7
  29. data/lib/fog/core/current_machine.rb +10 -8
  30. data/lib/fog/core/deprecated_connection_accessors.rb +0 -1
  31. data/lib/fog/core/deprecation.rb +0 -2
  32. data/lib/fog/core/errors.rb +3 -5
  33. data/lib/fog/core/hmac.rb +4 -6
  34. data/lib/fog/core/logger.rb +10 -11
  35. data/lib/fog/core/mock.rb +19 -25
  36. data/lib/fog/core/model.rb +9 -20
  37. data/lib/fog/core/provider.rb +6 -9
  38. data/lib/fog/core/scp.rb +14 -24
  39. data/lib/fog/core/service.rb +28 -31
  40. data/lib/fog/core/ssh.rb +16 -24
  41. data/lib/fog/core/stringify_keys.rb +7 -9
  42. data/lib/fog/core/time.rb +5 -7
  43. data/lib/fog/core/utils.rb +24 -20
  44. data/lib/fog/core/uuid.rb +2 -3
  45. data/lib/fog/core/version.rb +3 -1
  46. data/lib/fog/core/wait_for.rb +2 -2
  47. data/lib/fog/core/wait_for_defaults.rb +13 -10
  48. data/lib/fog/core/whitelist_keys.rb +1 -1
  49. data/lib/fog/dns.rb +6 -8
  50. data/lib/fog/identity.rb +5 -6
  51. data/lib/fog/image.rb +3 -5
  52. data/lib/fog/metering.rb +3 -6
  53. data/lib/fog/monitoring.rb +3 -5
  54. data/lib/fog/network.rb +4 -6
  55. data/lib/fog/orchestration.rb +3 -5
  56. data/lib/fog/schema/data_validator.rb +17 -22
  57. data/lib/fog/storage.rb +22 -16
  58. data/lib/fog/support.rb +3 -6
  59. data/lib/fog/test_helpers.rb +10 -10
  60. data/lib/fog/test_helpers/collection_helper.rb +23 -43
  61. data/lib/fog/test_helpers/compute/flavors_helper.rb +4 -10
  62. data/lib/fog/test_helpers/compute/server_helper.rb +3 -9
  63. data/lib/fog/test_helpers/compute/servers_helper.rb +0 -4
  64. data/lib/fog/test_helpers/formats_helper.rb +13 -14
  65. data/lib/fog/test_helpers/helper.rb +9 -4
  66. data/lib/fog/test_helpers/mock_helper.rb +92 -94
  67. data/lib/fog/test_helpers/model_helper.rb +7 -15
  68. data/lib/fog/test_helpers/responds_to_helper.rb +1 -3
  69. data/lib/fog/test_helpers/succeeds_helper.rb +1 -3
  70. data/lib/fog/volume.rb +3 -6
  71. data/lib/fog/vpn.rb +3 -5
  72. data/lib/tasks/test_task.rb +2 -6
  73. data/spec/compute_spec.rb +11 -13
  74. data/spec/connection_spec.rb +24 -14
  75. data/spec/credentials_spec.rb +23 -23
  76. data/spec/current_machine_spec.rb +6 -6
  77. data/spec/fake_app/fake_service.rb +18 -0
  78. data/spec/fake_app/models/collection.rb +5 -0
  79. data/spec/fake_app/models/model.rb +2 -0
  80. data/spec/fake_app/requests/request.rb +11 -0
  81. data/spec/fog_attribute_spec.rb +178 -136
  82. data/spec/identity_spec.rb +11 -13
  83. data/spec/mocking_spec.rb +7 -8
  84. data/spec/service_spec.rb +21 -7
  85. data/spec/spec_helper.rb +14 -8
  86. data/spec/storage_spec.rb +25 -13
  87. data/spec/test_helpers/formats_helper_spec.rb +52 -52
  88. data/spec/test_helpers/schema_validator_spec.rb +45 -45
  89. data/spec/timeout_spec.rb +1 -2
  90. data/spec/utils_spec.rb +2 -2
  91. data/spec/uuid_spec.rb +1 -1
  92. data/spec/wait_for_spec.rb +7 -4
  93. metadata +57 -33
@@ -9,19 +9,18 @@ module Fog
9
9
  attr_reader :service
10
10
 
11
11
  Array.public_instance_methods(false).each do |method|
12
- unless [:reject, :select, :slice, :clear, :inspect].include?(method.to_sym)
13
- class_eval <<-EOS, __FILE__, __LINE__
14
- def #{method}(*args)
15
- unless @loaded
16
- lazy_load
17
- end
18
- super
12
+ next if [:reject, :select, :slice, :clear, :inspect].include?(method.to_sym)
13
+ class_eval <<-EOS, __FILE__, __LINE__
14
+ def #{method}(*args)
15
+ unless @loaded
16
+ lazy_load
19
17
  end
20
- EOS
21
- end
18
+ super
19
+ end
20
+ EOS
22
21
  end
23
22
 
24
- %w[reject select slice].each do |method|
23
+ %w(reject select slice).each do |method|
25
24
  class_eval <<-EOS, __FILE__, __LINE__
26
25
  def #{method}(*args)
27
26
  unless @loaded
@@ -33,8 +32,8 @@ module Fog
33
32
  EOS
34
33
  end
35
34
 
36
- def self.model(new_model=nil)
37
- if new_model == nil
35
+ def self.model(new_model = nil)
36
+ if new_model.nil?
38
37
  @model
39
38
  else
40
39
  @model = new_model
@@ -70,21 +69,20 @@ module Fog
70
69
  merge_attributes(attributes)
71
70
  end
72
71
 
73
-
74
72
  def inspect
75
73
  Thread.current[:formatador] ||= Formatador.new
76
74
  data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
77
75
  Thread.current[:formatador].indent do
78
76
  unless self.class.attributes.empty?
79
77
  data << "#{Thread.current[:formatador].indentation}"
80
- data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
78
+ data << self.class.attributes.map { |attribute| "#{attribute}=#{send(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}")
81
79
  data << "\n"
82
80
  end
83
81
  data << "#{Thread.current[:formatador].indentation}["
84
82
  unless self.empty?
85
83
  data << "\n"
86
84
  Thread.current[:formatador].indent do
87
- data << self.map {|member| member.inspect}.join(",\n")
85
+ data << map(&:inspect).join(", \n")
88
86
  data << "\n"
89
87
  end
90
88
  data << Thread.current[:formatador].indentation
@@ -97,19 +95,19 @@ module Fog
97
95
 
98
96
  def load(objects)
99
97
  clear
100
- for object in objects
98
+ objects.each do |object|
101
99
  self << new(object)
102
100
  end
103
101
  self
104
102
  end
105
103
 
106
104
  def model
107
- self.class.instance_variable_get('@model')
105
+ self.class.instance_variable_get("@model")
108
106
  end
109
107
 
110
108
  def new(attributes = {})
111
109
  unless attributes.is_a?(::Hash)
112
- raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
110
+ raise ArgumentError, "Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"
113
111
  end
114
112
  model.new(
115
113
  {
@@ -126,29 +124,27 @@ module Fog
126
124
  end
127
125
 
128
126
  def table(attributes = nil)
129
- Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
127
+ Formatador.display_table(map(&:attributes), attributes)
130
128
  end
131
129
 
132
- def to_json(options = {})
133
- Fog::JSON.encode(self.map {|member| member.attributes})
130
+ def to_json(_options = {})
131
+ Fog::JSON.encode(map(&:attributes))
134
132
  end
135
133
 
136
134
  private
137
135
 
138
136
  def lazy_load
139
- self.all
137
+ all
140
138
  end
141
-
142
139
  end
143
140
 
144
141
  # Base class for collection classes whose 'all' method returns only a single page of results and passes the
145
142
  # 'Marker' option along as self.filters[:marker]
146
143
  class PagedCollection < Collection
147
-
148
- def each(filters=filters)
144
+ def each(filters = filters)
149
145
  if block_given?
150
146
  begin
151
- page = self.all(filters)
147
+ page = all(filters)
152
148
  # We need to explicitly use the base 'each' method here on the page, otherwise we get infinite recursion
153
149
  base_each = Fog::Collection.instance_method(:each)
154
150
  base_each.bind(page).call { |item| yield item }
@@ -156,6 +152,5 @@ module Fog
156
152
  end
157
153
  self
158
154
  end
159
-
160
155
  end
161
156
  end
@@ -1,6 +1,5 @@
1
1
  module Fog
2
2
  module Core
3
-
4
3
  # Fog::Core::Connection is a generic class to contain a HTTP link to an API.
5
4
  #
6
5
  # It is intended to be subclassed by providers who can then add their own
@@ -24,7 +23,7 @@ module Fog
24
23
  # @option params [Fixnum] :retry_limit Set how many times we'll retry a failed request. (Default 4)
25
24
  # @option params [Class] :instrumentor Responds to #instrument as in ActiveSupport::Notifications
26
25
  # @option params [String] :instrumentor_name Name prefix for #instrument events. Defaults to 'excon'
27
- def initialize(url, persistent=false, params={})
26
+ def initialize(url, persistent = false, params = {})
28
27
  if params[:path_prefix]
29
28
  if params[:path]
30
29
  raise ArgumentError, "optional arg 'path' is invalid when 'path_prefix' is provided"
@@ -33,11 +32,11 @@ module Fog
33
32
  @path_prefix = params.delete(:path_prefix)
34
33
  end
35
34
 
36
- unless params.has_key?(:debug_response)
37
- params[:debug_response] = true
38
- end
35
+ params[:debug_response] = true unless params.key?(:debug_response)
39
36
  params[:headers] ||= {}
40
- params[:headers]['User-Agent'] ||= "fog/#{Fog::VERSION}"
37
+ user_agent = "fog-core/#{Fog::Core::VERSION}"
38
+ user_agent = "fog/#{Fog::VERSION} #{user_agent}" if defined?(Fog::VERSION)
39
+ params[:headers]["User-Agent"] ||= user_agent
41
40
  params.merge!(:persistent => params.fetch(:persistent, persistent))
42
41
  @excon = Excon.new(url, params)
43
42
  end
@@ -1,7 +1,7 @@
1
- require 'yaml'
1
+ require "yaml"
2
2
 
3
3
  module Fog
4
- require 'fog/core/deprecation'
4
+ require "fog/core/deprecation"
5
5
 
6
6
  # Sets the global configuration up from a Hash rather than using background loading from a file
7
7
  #
@@ -19,8 +19,8 @@ module Fog
19
19
  # }
20
20
  #
21
21
  # @return [Hash] The newly assigned credentials
22
- def self.credentials=(new_credentials)
23
- @credentials = new_credentials
22
+ class << self
23
+ attr_writer :credentials
24
24
  end
25
25
 
26
26
  # Assign a new credential to use from configuration file
@@ -38,7 +38,7 @@ module Fog
38
38
  #
39
39
  # @return [Symbol] The credential to use in Fog
40
40
  def self.credential
41
- @credential ||= ( ENV["FOG_CREDENTIAL"] && ENV["FOG_CREDENTIAL"].to_sym ) || :default
41
+ @credential ||= (ENV["FOG_CREDENTIAL"] && ENV["FOG_CREDENTIAL"].to_sym) || :default
42
42
  end
43
43
 
44
44
  # This returns the path to the configuration file being used globally to look for sets of
@@ -49,7 +49,7 @@ module Fog
49
49
  # @return [String] The path for configuration_file
50
50
  def self.credentials_path
51
51
  @credential_path ||= begin
52
- path = ENV["FOG_RC"] || (ENV['HOME'] && File.directory?(ENV['HOME']) && '~/.fog')
52
+ path = ENV["FOG_RC"] || (ENV["HOME"] && File.directory?(ENV["HOME"]) && "~/.fog")
53
53
  File.expand_path(path) if path
54
54
  rescue
55
55
  nil
@@ -66,7 +66,7 @@ module Fog
66
66
  # @raise [LoadError] Configuration unavailable in configuration file
67
67
  def self.credentials
68
68
  @credentials ||= begin
69
- if credentials_path && File.exists?(credentials_path)
69
+ if credentials_path && File.exist?(credentials_path)
70
70
  credentials = Fog::Core::Utils.prepare_service_settings(YAML.load_file(credentials_path))
71
71
  (credentials && credentials[credential]) || Fog::Errors.missing_credentials
72
72
  else
@@ -1,12 +1,14 @@
1
- require 'thread'
1
+ require "thread"
2
+
2
3
  module Fog
3
4
  class CurrentMachine
4
- @@lock = Mutex.new
5
- AMAZON_AWS_CHECK_IP = 'http://checkip.amazonaws.com'
5
+ @lock = Mutex.new
6
+
7
+ AMAZON_AWS_CHECK_IP = "http://checkip.amazonaws.com"
6
8
 
7
- def self.ip_address= ip_address
8
- @@lock.synchronize do
9
- @@ip_address = ip_address
9
+ def self.ip_address=(ip_address)
10
+ @lock.synchronize do
11
+ @ip_address = ip_address
10
12
  end
11
13
  end
12
14
 
@@ -26,8 +28,8 @@ module Fog
26
28
  #
27
29
  # @raise [Excon::Errors::Error] if the net/http request fails.
28
30
  def self.ip_address
29
- @@lock.synchronize do
30
- @@ip_address ||= Excon.get(AMAZON_AWS_CHECK_IP).body.chomp
31
+ @lock.synchronize do
32
+ @ip_address ||= Excon.get(AMAZON_AWS_CHECK_IP).body.chomp
31
33
  end
32
34
  end
33
35
  end
@@ -35,7 +35,6 @@ module Fog
35
35
  def prepare_service_value(attributes)
36
36
  @service = attributes[:service] || attributes[:connection]
37
37
  end
38
-
39
38
  end
40
39
  end
41
40
  end
@@ -1,6 +1,5 @@
1
1
  module Fog
2
2
  module Deprecation
3
-
4
3
  def deprecate(older, newer)
5
4
  module_eval <<-EOS, __FILE__, __LINE__
6
5
  def #{older}(*args)
@@ -18,6 +17,5 @@ module Fog
18
17
  end
19
18
  EOS
20
19
  end
21
-
22
20
  end
23
21
  end
@@ -1,6 +1,5 @@
1
1
  module Fog
2
2
  module Errors
3
-
4
3
  class Error < StandardError
5
4
  attr_accessor :verbose
6
5
 
@@ -16,9 +15,9 @@ module Fog
16
15
 
17
16
  class NotFound < Fog::Errors::Error; end
18
17
 
19
- class LoadError < LoadError; end
18
+ class LoadError < Fog::Errors::Error; end
20
19
 
21
- class TimeoutError< Fog::Errors::Error; end
20
+ class TimeoutError < Fog::Errors::Error; end
22
21
 
23
22
  class NotImplemented < Fog::Errors::Error; end
24
23
 
@@ -111,8 +110,7 @@ An alternate file may be used by placing its path in the FOG_RC environment vari
111
110
  #######################################################
112
111
 
113
112
  YML
114
- raise(Fog::Errors::LoadError.new(missing_credentials_message))
113
+ raise Fog::Errors::LoadError, missing_credentials_message
115
114
  end
116
-
117
115
  end
118
116
  end
@@ -1,12 +1,11 @@
1
1
  module Fog
2
2
  class HMAC
3
-
4
3
  def initialize(type, key)
5
4
  @key = key
6
5
  case type
7
- when 'sha1'
6
+ when "sha1"
8
7
  setup_sha1
9
- when 'sha256'
8
+ when "sha256"
10
9
  setup_sha256
11
10
  end
12
11
  end
@@ -18,18 +17,17 @@ module Fog
18
17
  private
19
18
 
20
19
  def setup_sha1
21
- @digest = OpenSSL::Digest.new('sha1')
20
+ @digest = OpenSSL::Digest.new("sha1")
22
21
  @signer = lambda do |data|
23
22
  OpenSSL::HMAC.digest(@digest, @key, data)
24
23
  end
25
24
  end
26
25
 
27
26
  def setup_sha256
28
- @digest = OpenSSL::Digest.new('sha256')
27
+ @digest = OpenSSL::Digest.new("sha256")
29
28
  @signer = lambda do |data|
30
29
  OpenSSL::HMAC.digest(@digest, @key, data)
31
30
  end
32
31
  end
33
-
34
32
  end
35
33
  end
@@ -1,12 +1,11 @@
1
1
  module Fog
2
2
  class Logger
3
-
4
3
  @channels = {
5
4
  :deprecation => ::STDERR,
6
5
  :warning => ::STDERR
7
6
  }
8
7
 
9
- @channels[:debug] = ::STDERR if ENV['DEBUG']
8
+ @channels[:debug] = ::STDERR if ENV["DEBUG"]
10
9
 
11
10
  def self.[](channel)
12
11
  @channels[channel]
@@ -17,28 +16,28 @@ module Fog
17
16
  end
18
17
 
19
18
  def self.debug(message)
20
- self.write(:debug, "[light_black][fog][DEBUG] #{message}[/]\n")
19
+ write(:debug, "[light_black][fog][DEBUG] #{message}[/]\n")
21
20
  end
22
21
 
23
22
  def self.deprecation(message)
24
- self.write(:deprecation, "[yellow][fog][DEPRECATION] #{message}[/]\n")
23
+ write(:deprecation, "[yellow][fog][DEPRECATION] #{message}[/]\n")
25
24
  end
26
25
 
27
26
  def self.warning(message)
28
- self.write(:warning, "[yellow][fog][WARNING] #{message}[/]\n")
27
+ write(:warning, "[yellow][fog][WARNING] #{message}[/]\n")
29
28
  end
30
29
 
31
30
  def self.write(key, value)
32
- if channel = @channels[key]
31
+ channel = @channels[key]
32
+ if channel
33
33
  message = if channel.tty?
34
- value.gsub(Formatador::PARSE_REGEX) { "\e[#{Formatador::STYLES[$1.to_sym]}m" }.gsub(Formatador::INDENT_REGEX, '')
35
- else
36
- value.gsub(Formatador::PARSE_REGEX, '').gsub(Formatador::INDENT_REGEX, '')
37
- end
34
+ value.gsub(Formatador::PARSE_REGEX) { "\e[#{Formatador::STYLES[$1.to_sym]}m" }.gsub(Formatador::INDENT_REGEX, "")
35
+ else
36
+ value.gsub(Formatador::PARSE_REGEX, "").gsub(Formatador::INDENT_REGEX, "")
37
+ end
38
38
  channel.write(message)
39
39
  end
40
40
  nil
41
41
  end
42
-
43
42
  end
44
43
  end
@@ -1,5 +1,4 @@
1
1
  module Fog
2
-
3
2
  @mocking = false
4
3
 
5
4
  def self.mock!
@@ -10,19 +9,18 @@ module Fog
10
9
  @mocking = false
11
10
  end
12
11
 
13
- def self.mock?
14
- @mocking
15
- end
12
+ class << self
13
+ attr_reader :mocking
16
14
 
17
- def self.mocking?
18
- @mocking
15
+ alias_method :mock?, :mocking
16
+ alias_method :mocking?, :mocking
19
17
  end
20
18
 
21
19
  module Mock
22
-
23
20
  @delay = 1
24
- def self.delay
25
- @delay
21
+
22
+ class << self
23
+ attr_reader :delay
26
24
  end
27
25
 
28
26
  def self.delay=(new_delay)
@@ -30,11 +28,11 @@ module Fog
30
28
  @delay = new_delay
31
29
  end
32
30
 
33
- def self.not_implemented(message = 'Contributions welcome!')
34
- raise Fog::Errors::MockNotImplemented.new(message)
31
+ def self.not_implemented(message = "Contributions welcome!")
32
+ raise Fog::Errors::MockNotImplemented, message
35
33
  end
36
34
 
37
- def self.random_ip(opts = {:version => :v4})
35
+ def self.random_ip(opts = { :version => :v4 })
38
36
  version = opts[:version]
39
37
  if version == :v6
40
38
  bit_length = 128
@@ -46,7 +44,7 @@ module Fog
46
44
  raise ArgumentError, "Unknown IP version: #{version}"
47
45
  end
48
46
 
49
- seed = 1 + rand((2**bit_length)-1)
47
+ seed = 1 + rand((2**bit_length) - 1)
50
48
  IPAddr.new(seed, family).to_s
51
49
  end
52
50
 
@@ -58,31 +56,31 @@ module Fog
58
56
  end
59
57
 
60
58
  def self.random_hex(length)
61
- max = ('f' * length).to_i(16)
62
- rand(max).to_s(16).rjust(length, '0')
59
+ max = ("f" * length).to_i(16)
60
+ rand(max).to_s(16).rjust(length, "0")
63
61
  end
64
62
 
65
63
  def self.random_letters(length)
66
64
  random_selection(
67
- 'abcdefghijklmnopqrstuvwxyz',
65
+ "abcdefghijklmnopqrstuvwxyz",
68
66
  length
69
67
  )
70
68
  end
71
69
 
72
70
  def self.random_numbers(length)
73
- max = ('9' * length).to_i
71
+ max = ("9" * length).to_i
74
72
  rand(max).to_s
75
73
  end
76
74
 
77
75
  def self.random_letters_and_numbers(length)
78
76
  random_selection(
79
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
77
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
80
78
  length
81
79
  )
82
80
  end
83
81
 
84
82
  def self.random_selection(characters, length)
85
- selection = ''
83
+ selection = ""
86
84
  length.times do
87
85
  position = rand(characters.length)
88
86
  selection << characters[position..position]
@@ -97,19 +95,15 @@ module Fog
97
95
  x_const.respond_to?(:constants) && x_const.constants.map do |y|
98
96
  y_const = x_const.const_get(y)
99
97
  y_const.respond_to?(:constants) && y_const.constants.map do |z|
100
- if z.to_sym == :Mock
101
- mocked_services << y_const.const_get(z)
102
- end
98
+ mocked_services << y_const.const_get(z) if z.to_sym == :Mock
103
99
  end
104
100
  end
105
101
  end
106
102
 
107
- for mocked_service in mocked_services
103
+ mocked_services.each do |mocked_service|
108
104
  next unless mocked_service.respond_to?(:reset)
109
105
  mocked_service.reset
110
106
  end
111
107
  end
112
-
113
108
  end
114
-
115
109
  end