# Subclasses of BaseGuessor must implement interface: # detect_class_name # method_name # error_message # class Jets::Commands::Call class BaseGuesser include Jets::AwsServices # provided_function_name: # admin/related_pages_controller-list_all # admin-related-pages-controller-list-all def initialize(provided_function_name) @provided_function_name = provided_function_name end def class_name return @class_name if @detection_ran @class_name = detect_class_name @detection_ran = true @class_name end def function_name # Strip the project namespace if the user has accidentally added it # Since we're going to automatically add it no matter what at the end # and dont want the namespace to be included twice @provided_function_name = @provided_function_name.sub("#{Jets.config.project_namespace}-", "") code_path = class_name.underscore.gsub('/','-') function_name = [Jets.config.project_namespace, code_path, method_name].join('-') generated_function_name(function_name) end def generated_function_name(function_name) if function_name.size > Jets::MAX_FUNCTION_NAME_SIZE # name generated by CloudFormation logical_id = @class_name.gsub('::','') parent_resources = stack_resources(parent_stack.stack_id) app_stack = parent_resources.find { |s| s.logical_resource_id == logical_id } resources = stack_resources(app_stack.physical_resource_id) resource = resources.find { |r| r.logical_resource_id == method_name.camelize + "LambdaFunction" } # method_name only contains the method resource.physical_resource_id # actual function name else function_name end end # Class variable caches @@stack_resources = {} def stack_resources(stack_name) @@stack_resources[stack_name] ||= cfn.describe_stack_resources(stack_name: stack_name).stack_resources end @@parent_stack = nil def parent_stack @@parent_stack ||= cfn.describe_stacks(stack_name: Jets::Names.parent_stack_name).stacks.first end end end