Module: Pipedream::AwsServices::Helpers

Included in:
Pipedream::AwsServices
Defined in:
lib/pipedream/aws_services/helpers.rb

Instance Method Summary collapse

Instance Method Details

#are_you_sure?(stack_name, action) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pipedream/aws_services/helpers.rb', line 52

def are_you_sure?(stack_name, action)
  if @options[:sure]
    sure = 'y'
  else
    message = case action
    when :update
      "Are you sure you want to want to update the #{stack_name.color(:green)} stack with the changes? (y/N)"
    when :delete
      "Are you sure you want to want to delete the #{stack_name.color(:green)} stack? (y/N)"
    end
    puts message
    sure = $stdin.gets
  end

  unless sure =~ /^y/
    puts "Whew! Exiting without running #{action}."
    exit 0
  end
end

#inferred_pipeline_nameObject



34
35
36
37
# File 'lib/pipedream/aws_services/helpers.rb', line 34

def inferred_pipeline_name
  # Essentially the project's parent folder
  File.basename(Dir.pwd).gsub('_','-').gsub(/\.+/,'-').gsub(/[^0-9a-zA-Z,-]/, '')
end

#inferred_stack_name(pipeline_name) ⇒ Object

Examples:

myapp-ci-deploy # with Settings stack_naming append_env set to false.
myapp-ci-deploy-development
myapp-ci-deploy-development-2


45
46
47
48
49
50
# File 'lib/pipedream/aws_services/helpers.rb', line 45

def inferred_stack_name(pipeline_name)
  items = [pipeline_name, @options[:type], Pipedream.env_extra, "pipe"]
  append_env = Pipedream.settings.dig(:stack_naming, :append_env)
  items.insert(2, Pipedream.env) if append_env
  items.reject(&:blank?).compact.join("-")
end

#pipeline_name_convention(name_base) ⇒ Object



28
29
30
31
32
# File 'lib/pipedream/aws_services/helpers.rb', line 28

def pipeline_name_convention(name_base)
  items = [@pipeline_name, @options[:type], Pipedream.env_extra]
  items.insert(2, Pipedream.env) if Pipedream.settings.dig(:stack_naming, :append_env)
  items.reject(&:blank?).compact.join("-")
end

#stack_exists?(stack_name) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pipedream/aws_services/helpers.rb', line 3

def stack_exists?(stack_name)
  return false if ENV['TEST']

  exist = nil
  begin
    # When the stack does not exist an exception is raised. Example:
    # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
    cfn.describe_stacks(stack_name: stack_name)
    exist = true
  rescue Aws::CloudFormation::Errors::ValidationError => e
    if e.message =~ /does not exist/
      exist = false
    elsif e.message.include?("'stackName' failed to satisfy constraint")
      # Example of e.message when describe_stack with invalid stack name
      # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
      puts "Invalid stack name: #{stack_name}"
      puts "Full error message: #{e.message}"
      exit 1
    else
      raise # re-raise exception  because unsure what other errors can happen
    end
  end
  exist
end