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



113
114
115
116
117
118
119
120
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 113

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
# 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)',
  )
rescue Aws::APIGateway::Errors::NotFoundException => e
  raise(e) unless fail_silently
end

#deleting_parent?Boolean

Returns:

  • (Boolean)


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

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

#deployment_stackObject



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

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

#get_domain_nameObject



122
123
124
125
# File 'lib/jets/internal/app/functions/jets/base_path.rb', line 122

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

#get_rest_api_idObject



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

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

#parent_stack_nameObject



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

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