Class: BasePathMapping

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

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ BasePathMapping

Returns a new instance of BasePathMapping.



84
85
86
87
88
89
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 84

def initialize(event)
  @event = event
  @rest_api_id = get_rest_api_id
  @domain_name = get_domain_name
  @base_path = ''
end

Instance Method Details

#createObject



117
118
119
120
121
122
123
124
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 117

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



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 104

def delete(fail_silently=false)
  apigateway.delete_base_path_mapping(
    domain_name: @domain_name, # required
    base_path: '(none)',
  )
# 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)


140
141
142
143
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 140

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

#deployment_stackObject



131
132
133
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 131

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

#get_domain_nameObject



126
127
128
129
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 126

def get_domain_name
  param = deployment_stack[:parameters].find { |p| p.parameter_key == 'DomainName' }
  param.parameter_value
end

#get_rest_api_idObject



135
136
137
138
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 135

def get_rest_api_id
  param = deployment_stack[:parameters].find { |p| p.parameter_key == 'RestApi' }
  param.parameter_value
end

#parent_stack_nameObject



145
146
147
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 145

def parent_stack_name
  deployment_stack[:root_id]
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)


100
101
102
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 100

def should_delete?
  deleting_parent?
end

#updateObject



91
92
93
94
95
96
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 91

def update
  # 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.
  delete(true)
  create
end