Class: BasePathMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/internal/app/functions/jets/base_path_mapping.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, stage_name) ⇒ BasePathMapping

Returns a new instance of BasePathMapping.



5
6
7
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 5

def initialize(event, stage_name)
  @event, @stage_name = event, stage_name
end

Instance Method Details

#apigatewayObject



74
75
76
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 74

def apigateway
  @apigateway ||= Aws::APIGateway::Client.new
end

#base_pathObject



56
57
58
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 56

def base_path
  @base_path ||= parameter_value('BasePath') || ''
end

#cfnObject



78
79
80
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 78

def cfn
  @cfn ||= Aws::CloudFormation::Client.new
end

#createObject



35
36
37
38
39
40
41
42
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 35

def create
  apigateway.create_base_path_mapping(
    domain_name: domain_name, # required
    base_path: base_path,
    rest_api_id: rest_api_id, # required
    stage: @stage_name,
  )
end

#delete(fail_silently = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 22

def delete(fail_silently=false)
  apigateway.delete_base_path_mapping(
    domain_name: domain_name, # required
    base_path: base_path.empty? ? '(none)' : base_path,
  )
# https://github.com/tongueroo/jets/issues/255
# Used to return: Aws::APIGateway::Errors::NotFoundException
# Now returns: Aws::APIGateway::Errors::InternalFailure
# So we'll use a more generic error
rescue Aws::APIGateway::Errors::ServiceError => e
  raise(e) unless fail_silently
end

#deleting_parent?Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 65

def deleting_parent?
  stack = cfn.describe_stacks(stack_name: parent_stack_name).stacks.first
  stack.stack_status == 'DELETE_IN_PROGRESS'
end

#deployment_stackObject



44
45
46
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 44

def deployment_stack
  @deployment_stack ||= cfn.describe_stacks(stack_name: @event['StackId']).stacks.first
end

#domain_nameObject



52
53
54
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 52

def domain_name
  @domain_name ||= parameter_value('DomainName')
end

#parameter_value(parameter_key) ⇒ Object



60
61
62
63
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 60

def parameter_value(parameter_key)
  param = deployment_stack[:parameters].find { |p| p.parameter_key == parameter_key }
  param&.parameter_value # possible for this to be nil when removing the config: IE: config.domain.name = nil
end

#parent_stack_nameObject



70
71
72
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 70

def parent_stack_name
  deployment_stack[:root_id]
end

#rest_api_idObject



48
49
50
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 48

def rest_api_id
  @rest_api_id ||= parameter_value('RestApi')
end

#should_delete?Boolean

Dont delete the newly created base path mapping unless this is an operation where we’re fully deleting the stack

Returns:

  • (Boolean)


18
19
20
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 18

def should_delete?
  deleting_parent?
end

#updateObject

Cannot use update_base_path_mapping to update the base_mapping because it doesnt allow us to change the rest_api_id. So we delete and create.



11
12
13
14
# File 'lib/jets/internal/app/functions/jets/base_path_mapping.rb', line 11

def update
  delete(true)
  create
end