Class: Command::SetupApp

Inherits:
Base
  • Object
show all
Defined in:
lib/command/setup_app.rb

Constant Summary collapse

NAME =
"setup-app"
OPTIONS =
[
  app_option(required: true),
  skip_secret_access_binding_option
].freeze
DESCRIPTION =
"Creates an app and all its workloads"
LONG_DESCRIPTION =
<<~DESC
  - Creates an app and all its workloads
  - Specify the templates for the app and workloads through `setup_app_templates` in the `.controlplane/controlplane.yml` file
  - This should only be used for temporary apps like review apps, never for persistent apps like production (to update workloads for those, use 'cpl apply-template' instead)
  - Automatically binds the app to the secrets policy, as long as both the identity and the policy exist
  - Use `--skip-secret-access-binding` to prevent the automatic bind
DESC

Constants inherited from Base

Base::ACCEPTS_EXTRA_OPTIONS, Base::DEFAULT_ARGS, Base::EXAMPLES, Base::HIDE, Base::NO_IMAGE_AVAILABLE, Base::REQUIRES_ARGS, Base::USAGE, Base::WITH_INFO_HEADER

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

all_commands, all_options, all_options_by_key_name, #app_identity, #app_identity_link, #app_image_link, #app_location_link, app_option, #app_secrets, #app_secrets_policy, #args_join, clean_on_failure_option, commit_option, common_options, #cp, domain_option, #ensure_workload_deleted, #extract_image_commit, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, location_option, org_option, #perform!, #progress, run_release_phase_option, skip_confirm_option, skip_secret_access_binding_option, #step, #step_error, #step_finish, terminal_size_option, trace_option, upstream_token_option, use_local_token_option, verbose_option, version_option, #wait_for_replica, #wait_for_workload, wait_option, workload_option

Methods included from Helpers

#random_four_digits, #strip_str_and_validate

Constructor Details

This class inherits a constructor from Command::Base

Instance Method Details

#callObject

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/command/setup_app.rb', line 19

def call # rubocop:disable Metrics/MethodLength
  templates = config[:setup_app_templates]

  app = cp.fetch_gvc
  if app
    raise "App '#{config.app}' already exists. If you want to update this app, " \
          "either run 'cpl delete -a #{config.app}' and then re-run this command, " \
          "or run 'cpl apply-template #{templates.join(' ')} -a #{config.app}'."
  end

  Cpl::Cli.start(["apply-template", *templates, "-a", config.app])

  return if config.options[:skip_secret_access_binding]

  progress.puts

  if cp.fetch_identity(app_identity).nil? || cp.fetch_policy(app_secrets_policy).nil?
    raise "Can't bind identity to policy: identity '#{app_identity}' or " \
          "policy '#{app_secrets_policy}' doesn't exist. " \
          "Please create them or use `--skip-secret-access-binding` to ignore this message."
  end

  step("Binding identity to policy") do
    cp.bind_identity_to_policy(app_identity_link, app_secrets_policy)
  end
end