yle_tf 1.2.0 → 1.3.0

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: a8818ef98a06e9ccd0e7890e54284f0b3640a0ca7a1e5000f951c4f82bb99011
4
- data.tar.gz: 3a4ec6e95da88cdea69c5d02d93829a9a777303f46dcd571469ec5866c932d64
3
+ metadata.gz: 7811f980206094727502839932ba9a800a4e37694ae26bc71d9c4935de38d3c3
4
+ data.tar.gz: 95e2c481a30b3caffb65c08407f9e222210fe01514f59ff88ca38a00915ea31b
5
5
  SHA512:
6
- metadata.gz: 1dba1594a58ceff3dc5519f938b9096fd0269e935c0e1443c12be20f16733ff2bb4cc4fc2c0956ba4629e75e579c00ac81638204eea0490520968e97321c2752
7
- data.tar.gz: 0655f4e7d53d0cc57008afd7787c8b18ab47986a36d24d36e77fc602feef1e921e9fcdb504a0945e334337478c045891336db0a94c88bfe9942d16c78c089a7a
6
+ metadata.gz: 84010f77dfa1d2786f0c9b4a3783073ad15bbf6146bac16f4a49401b8b378e28f0747f82a6880eb01dda175fccbd1465f3e25391586e10c11d424e304fe8e74b
7
+ data.tar.gz: 95c19822da06edb58e250215fb0c5e2154da99e8881a2b8a8ce4fb9fe7c124772e81d7a2774595fdedb97cec3166e0b34e7c098ac20d8133ad97bfcb1196534e
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pathname'
4
+
3
5
  require 'yle_tf/logger'
4
6
  require 'yle_tf/plugin'
5
7
  require 'yle_tf/system'
@@ -14,13 +16,14 @@ class YleTf
14
16
  stdout: :debug # Hide the output to the debug level
15
17
  }.freeze
16
18
 
19
+ attr_reader :config
20
+
17
21
  def initialize(app)
18
22
  @app = app
19
23
  end
20
24
 
21
25
  def call(env)
22
- config = env[:config]
23
- backend = backend(config)
26
+ @config = env[:config]
24
27
 
25
28
  Logger.info('Initializing Terraform')
26
29
  Logger.debug("Backend configuration: #{backend}")
@@ -34,17 +37,34 @@ class YleTf
34
37
  Logger.debug('Configuring the backend')
35
38
  backend.configure
36
39
 
40
+ Logger.debug('Symlinking errored.tfstate')
41
+ symlink_errored_tfstate
42
+
37
43
  Logger.debug('Initializing Terraform')
38
- YleTf::System.cmd('terraform', 'init', *TF_CMD_ARGS, TF_CMD_OPTS)
44
+ YleTf::System.cmd('terraform', 'init', *TF_CMD_ARGS, **TF_CMD_OPTS)
45
+ end
46
+
47
+ def backend
48
+ @backend ||= find_backend
39
49
  end
40
50
 
41
- def backend(config)
51
+ def find_backend
42
52
  backend_type = config.fetch('backend', 'type').downcase
43
53
  backend_proc = Plugin.manager.backends[backend_type]
44
54
 
45
55
  klass = backend_proc.call
46
56
  klass.new(config)
47
57
  end
58
+
59
+ def symlink_errored_tfstate
60
+ local_path = Pathname.pwd.join('errored.tfstate')
61
+ remote_path = config.module_dir.join('errored.tfstate')
62
+
63
+ # Remove the possibly copied old file
64
+ local_path.unlink if local_path.exist?
65
+
66
+ local_path.make_symlink(remote_path)
67
+ end
48
68
  end
49
69
  end
50
70
  end
@@ -10,7 +10,7 @@ class YleTf
10
10
  RC_PATH = '~/.terraformrc'
11
11
 
12
12
  # Path of the plugin cache directory
13
- DEFAULT_PLUGIN_CACHE_PATH = '~/.terraform.d/plugin-cache'
13
+ DEFAULT_PLUGIN_CACHE_PATH = '$HOME/.terraform.d/plugin-cache'
14
14
 
15
15
  def initialize(app)
16
16
  @app = app
@@ -50,7 +50,7 @@ class YleTf
50
50
  if TF_OPTIONS.include?(arg)
51
51
  @tf_options[key(arg)] = true
52
52
  else
53
- STDERR.puts "Unknown option '#{arg}'"
53
+ warn "Unknown option '#{arg}'"
54
54
  @tf_command = 'help'
55
55
  @tf_env = 'error'
56
56
  break
@@ -20,7 +20,7 @@ class YleTf
20
20
  }
21
21
 
22
22
  config = Loader.new(opts).load
23
- new(config, opts)
23
+ new(config, **opts)
24
24
  end
25
25
 
26
26
  attr_reader :config, :tf_env, :module_dir
@@ -91,7 +91,7 @@ class YleTf
91
91
 
92
92
  def migrate_old_config(config, **opts)
93
93
  task(' -> Migrating') do
94
- Config::Migration.migrate_old_config(config, opts)
94
+ Config::Migration.migrate_old_config(config, **opts)
95
95
  end
96
96
  end
97
97
 
@@ -23,7 +23,6 @@ class YleTf
23
23
 
24
24
  def self.logger
25
25
  @logger ||= ::Logger.new(DEVICE).tap do |logger|
26
- patch_for_old_ruby(logger)
27
26
  logger.level = log_level
28
27
  logger.formatter = log_formatter
29
28
  end
@@ -65,14 +64,5 @@ class YleTf
65
64
  :brown
66
65
  end
67
66
  end
68
-
69
- # Patches the `::Logger` in older Ruby versions to
70
- # accept log level as a `String`
71
- def self.patch_for_old_ruby(logger)
72
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.3')
73
- require_relative '../../vendor/logger_level_patch'
74
- logger.extend(LoggerLevelPatch)
75
- end
76
- end
77
67
  end
78
68
  end
@@ -3,6 +3,7 @@
3
3
  require 'English'
4
4
  require 'open3'
5
5
  require 'shellwords'
6
+ require 'stringio'
6
7
  require 'thwait'
7
8
  require 'yle_tf/error'
8
9
  require 'yle_tf/logger'
@@ -46,7 +47,7 @@ class YleTf
46
47
 
47
48
  def self.read_cmd(*args, **opts)
48
49
  buffer = StringIO.new
49
- cmd(*args, opts.merge(stdout: buffer))
50
+ cmd(*args, **opts.merge(stdout: buffer))
50
51
  buffer.string
51
52
  end
52
53
 
@@ -108,7 +108,7 @@ class YleTf
108
108
  while (data = source.readpartial(BLOCK_SIZE))
109
109
  target.write(data)
110
110
  end
111
- rescue EOFError # rubocop:disable Lint/HandleExceptions
111
+ rescue EOFError # rubocop:disable Lint/SuppressedException
112
112
  # All read
113
113
  rescue IOError => e
114
114
  YleTf::Logger.debug e.full_message
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class YleTf
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yle_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yleisradio
8
8
  - Teemu Matilainen
9
9
  - Antti Forsell
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-01-24 00:00:00.000000000 Z
13
+ date: 2020-10-12 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thwait
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 0.2.0
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: bundler
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -46,14 +60,14 @@ dependencies:
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: '12.0'
63
+ version: '13.0'
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - "~>"
55
69
  - !ruby/object:Gem::Version
56
- version: '12.0'
70
+ version: '13.0'
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: rspec
59
73
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +160,6 @@ files:
146
160
  - lib/yle_tf_plugins/commands/version/command.rb
147
161
  - lib/yle_tf_plugins/commands/version/plugin.rb
148
162
  - vendor/hash_deep_merge.rb
149
- - vendor/logger_level_patch.rb
150
163
  - vendor/middleware/LICENSE
151
164
  - vendor/middleware/builder.rb
152
165
  - vendor/middleware/runner.rb
@@ -154,7 +167,7 @@ homepage: https://github.com/Yleisradio/yle_tf
154
167
  licenses:
155
168
  - MIT
156
169
  metadata: {}
157
- post_install_message:
170
+ post_install_message:
158
171
  rdoc_options: []
159
172
  require_paths:
160
173
  - lib
@@ -169,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
182
  - !ruby/object:Gem::Version
170
183
  version: '0'
171
184
  requirements: []
172
- rubygems_version: 3.0.1
173
- signing_key:
185
+ rubygems_version: 3.1.2
186
+ signing_key:
174
187
  specification_version: 4
175
188
  summary: Tooling for Terraform
176
189
  test_files: []
@@ -1,29 +0,0 @@
1
- require 'logger'
2
-
3
- class YleTf
4
- module LoggerLevelPatch
5
- # Taken from Ruby 2.4.1
6
- def level=(severity)
7
- if severity.is_a?(Integer)
8
- @level = severity
9
- else
10
- case severity.to_s.downcase
11
- when 'debug'.freeze
12
- @level = ::Logger::DEBUG
13
- when 'info'.freeze
14
- @level = ::Logger::INFO
15
- when 'warn'.freeze
16
- @level = ::Logger::WARN
17
- when 'error'.freeze
18
- @level = ::Logger::ERROR
19
- when 'fatal'.freeze
20
- @level = ::Logger::FATAL
21
- when 'unknown'.freeze
22
- @level = ::Logger::UNKNOWN
23
- else
24
- raise ArgumentError, "invalid log level: #{severity}"
25
- end
26
- end
27
- end
28
- end
29
- end