cpl 2.0.1 → 2.1.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.
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TemplateParser
4
+ attr_reader :config, :deprecated_variables
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def template_dir
11
+ "#{config.app_cpln_dir}/templates"
12
+ end
13
+
14
+ def template_filename(name)
15
+ "#{template_dir}/#{name}.yml"
16
+ end
17
+
18
+ def parse(filenames)
19
+ @deprecated_variables = {}
20
+
21
+ filenames.each_with_object([]) do |filename, templates|
22
+ yaml_file = File.read(filename)
23
+ yaml_file = replace_variables(yaml_file)
24
+
25
+ template_yamls = yaml_file.split(/^---\s*$/)
26
+ template_yamls.each do |template_yaml|
27
+ template = YAML.safe_load(template_yaml)
28
+ templates.push(template)
29
+ end
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def replace_variables(yaml_file) # rubocop:disable Metrics/MethodLength
36
+ yaml_file = yaml_file
37
+ .gsub("{{APP_ORG}}", config.org)
38
+ .gsub("{{APP_NAME}}", config.app)
39
+ .gsub("{{APP_LOCATION}}", config.location)
40
+ .gsub("{{APP_LOCATION_LINK}}", config.location_link)
41
+ .gsub("{{APP_IMAGE}}", cp.latest_image)
42
+ .gsub("{{APP_IMAGE_LINK}}", config.image_link(cp.latest_image))
43
+ .gsub("{{APP_IDENTITY}}", config.identity)
44
+ .gsub("{{APP_IDENTITY_LINK}}", config.identity_link)
45
+ .gsub("{{APP_SECRETS}}", config.secrets)
46
+ .gsub("{{APP_SECRETS_POLICY}}", config.secrets_policy)
47
+
48
+ find_deprecated_variables(yaml_file)
49
+
50
+ # Kept for backwards compatibility
51
+ yaml_file
52
+ .gsub("APP_ORG", config.org)
53
+ .gsub("APP_GVC", config.app)
54
+ .gsub("APP_LOCATION", config.location)
55
+ .gsub("APP_IMAGE", cp.latest_image)
56
+ end
57
+
58
+ def find_deprecated_variables(yaml_file)
59
+ new_variables.each do |old_key, new_key|
60
+ @deprecated_variables[old_key] = new_key if yaml_file.include?(old_key)
61
+ end
62
+ end
63
+
64
+ def new_variables
65
+ {
66
+ "APP_ORG" => "{{APP_ORG}}",
67
+ "APP_GVC" => "{{APP_NAME}}",
68
+ "APP_LOCATION" => "{{APP_LOCATION}}",
69
+ "APP_IMAGE" => "{{APP_IMAGE}}"
70
+ }
71
+ end
72
+
73
+ def cp
74
+ @cp ||= Controlplane.new(config)
75
+ end
76
+ end
data/lib/cpl/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cpl
4
- VERSION = "2.0.1"
4
+ VERSION = "2.1.0"
5
5
  MIN_CPLN_VERSION = "2.0.1"
6
6
  end
data/lib/cpl.rb CHANGED
@@ -58,6 +58,8 @@ module Cpl
58
58
  default_task :no_command
59
59
 
60
60
  def self.start(*args)
61
+ ENV["CPLN_SKIP_UPDATE_CHECK"] = "true"
62
+
61
63
  check_cpln_version
62
64
  check_cpl_version
63
65
  fix_help_option
@@ -177,6 +179,7 @@ module Cpl
177
179
  examples = command_class::EXAMPLES
178
180
  hide = command_class::HIDE || deprecated
179
181
  with_info_header = command_class::WITH_INFO_HEADER
182
+ validations = command_class::VALIDATIONS
180
183
 
181
184
  long_description += "\n#{examples}" if examples.length.positive?
182
185
 
@@ -198,9 +201,10 @@ module Cpl
198
201
 
199
202
  @commands_with_extra_options.push(name_for_method.to_sym) if accepts_extra_options
200
203
 
201
- define_method(name_for_method) do |*provided_args| # rubocop:disable Metrics/MethodLength
204
+ define_method(name_for_method) do |*provided_args| # rubocop:disable Metrics/BlockLength, Metrics/MethodLength
202
205
  if deprecated
203
- ::Shell.warn_deprecated("Command '#{command_key}' is deprecated, " \
206
+ normalized_old_name = ::Helpers.normalize_command_name(command_key)
207
+ ::Shell.warn_deprecated("Command '#{normalized_old_name}' is deprecated, " \
204
208
  "please use '#{name}' instead.")
205
209
  $stderr.puts
206
210
  end
@@ -222,6 +226,11 @@ module Cpl
222
226
 
223
227
  Cpl::Cli.show_info_header(config) if with_info_header
224
228
 
229
+ if validations.any? && ENV.fetch("DISABLE_VALIDATIONS", nil) != "true"
230
+ doctor = DoctorService.new(config)
231
+ doctor.run_validations(validations, silent_if_passing: true)
232
+ end
233
+
225
234
  command_class.new(config).call
226
235
  rescue RuntimeError => e
227
236
  ::Shell.abort(e.message)
@@ -235,14 +244,23 @@ module Cpl
235
244
  check_unknown_options!(except: @commands_with_extra_options)
236
245
  stop_on_unknown_option!
237
246
 
238
- def self.validate_options!(options)
247
+ def self.validate_options!(options) # rubocop:disable Metrics/MethodLength
239
248
  options.each do |name, value|
240
- raise "No value provided for option '#{name}'." if value.to_s.strip.empty?
249
+ normalized_name = ::Helpers.normalize_option_name(name)
250
+ raise "No value provided for option #{normalized_name}." if value.to_s.strip.empty?
251
+
252
+ option = ::Command::Base.all_options.find { |current_option| current_option[:name].to_s == name }
253
+ if option[:new_name]
254
+ normalized_new_name = ::Helpers.normalize_option_name(option[:new_name])
255
+ ::Shell.warn_deprecated("Option #{normalized_name} is deprecated, " \
256
+ "please use #{normalized_new_name} instead.")
257
+ $stderr.puts
258
+ end
241
259
 
242
- params = ::Command::Base.all_options.find { |option| option[:name].to_s == name }[:params]
260
+ params = option[:params]
243
261
  next unless params[:valid_regex]
244
262
 
245
- raise "Invalid value provided for option '#{name}'." unless value.match?(params[:valid_regex])
263
+ raise "Invalid value provided for option #{normalized_name}." unless value.match?(params[:valid_regex])
246
264
  end
247
265
  end
248
266
 
@@ -267,8 +285,4 @@ module Cpl
267
285
  end
268
286
  end
269
287
 
270
- # nice Ctrl+C
271
- trap "INT" do
272
- puts
273
- exit(ExitCode::INTERRUPT)
274
- end
288
+ Shell.trap_interrupt unless ENV.fetch("DISABLE_INTERRUPT_TRAP", nil) == "true"
data/templates/app.yml CHANGED
@@ -11,8 +11,3 @@ spec:
11
11
  staticPlacement:
12
12
  locationLinks:
13
13
  - {{APP_LOCATION_LINK}}
14
- ---
15
- # Identity is needed to access secrets
16
- kind: identity
17
- name: {{APP_IDENTITY}}
18
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-05-16 00:00:00.000000000 Z
12
+ date: 2024-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: debug
@@ -243,11 +243,11 @@ files:
243
243
  - docs/migrating.md
244
244
  - docs/postgres.md
245
245
  - docs/redis.md
246
+ - docs/secrets-and-env-values.md
246
247
  - docs/tips.md
247
248
  - docs/troubleshooting.md
248
249
  - examples/circleci.yml
249
250
  - examples/controlplane.yml
250
- - googlee2da545df05d92f9.html
251
251
  - lib/command/apply_template.rb
252
252
  - lib/command/base.rb
253
253
  - lib/command/build_image.rb
@@ -257,6 +257,7 @@ files:
257
257
  - lib/command/copy_image_from_upstream.rb
258
258
  - lib/command/delete.rb
259
259
  - lib/command/deploy_image.rb
260
+ - lib/command/doctor.rb
260
261
  - lib/command/env.rb
261
262
  - lib/command/exists.rb
262
263
  - lib/command/generate.rb
@@ -284,10 +285,11 @@ files:
284
285
  - lib/core/config.rb
285
286
  - lib/core/controlplane.rb
286
287
  - lib/core/controlplane_api.rb
287
- - lib/core/controlplane_api_cli.rb
288
288
  - lib/core/controlplane_api_direct.rb
289
+ - lib/core/doctor_service.rb
289
290
  - lib/core/helpers.rb
290
291
  - lib/core/shell.rb
292
+ - lib/core/template_parser.rb
291
293
  - lib/cpl.rb
292
294
  - lib/cpl/version.rb
293
295
  - lib/deprecated_commands.json
@@ -311,9 +313,8 @@ files:
311
313
  - templates/rails.yml
312
314
  - templates/redis.yml
313
315
  - templates/redis2.yml
314
- - templates/secrets.yml
315
316
  - templates/sidekiq.yml
316
- homepage: https://github.com/shakacode/heroku-to-control-plane
317
+ homepage: https://github.com/shakacode/control-plane-flow
317
318
  licenses:
318
319
  - MIT
319
320
  metadata:
@@ -333,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
333
334
  - !ruby/object:Gem::Version
334
335
  version: '0'
335
336
  requirements: []
336
- rubygems_version: 3.4.21
337
+ rubygems_version: 3.5.10
337
338
  signing_key:
338
339
  specification_version: 4
339
340
  summary: Heroku to Control Plane
@@ -1 +0,0 @@
1
- google-site-verification: googlee2da545df05d92f9.html
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ControlplaneApiCli
4
- def call(url, method:)
5
- result = Shell.cmd("cpln", "rest", method, url, "-o", "json", capture_stderr: true)
6
- raise(result[:output]) unless result[:success]
7
-
8
- JSON.parse(result[:output])
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- kind: secret
2
- name: {{APP_SECRETS}}
3
- type: dictionary
4
- data: {}
5
- ---
6
- # Policy is needed to allow identities to access secrets
7
- kind: policy
8
- name: {{APP_SECRETS_POLICY}}
9
- targetKind: secret
10
- targetLinks:
11
- - //secret/{{APP_SECRETS}}