Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion checks/handler_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/newrelic/newrelic-lambda-extension/config"
Expand Down Expand Up @@ -35,8 +36,8 @@ func handlerCheck(ctx context.Context, conf *config.Configuration, reg *api.Regi

func (r runtimeConfig) check(h handlerConfigs) bool {
functionHandler := r.getTrueHandler(h)
p := removePathMethodName(functionHandler)
if r.language == Node {
p := removePathMethodNameNode(functionHandler)
pJS := pathFormatter(p, "js")
cJS := pathFormatter(p, "cjs")
pMJS := pathFormatter(p, "mjs")
Expand All @@ -45,6 +46,7 @@ func (r runtimeConfig) check(h handlerConfigs) bool {
return true
}
} else {
p := removePathMethodName(functionHandler)
p = pathFormatter(p, r.fileType)
}
return util.PathExists(p)
Expand Down Expand Up @@ -74,6 +76,16 @@ func removePathMethodName(p string) string {
return strings.Join(s[:len(s)-1], "/")
}

func removePathMethodNameNode(p string) string {
mh := filepath.Base(p)
mr := p[0:strings.Index(p, mh)]

s := strings.Split(mh, ".")
m := s[0]

return filepath.Join(mr, m)
}

func pathFormatter(functionHandler string, fileType string) string {
p := fmt.Sprintf("%s/%s.%s", handlerPath, functionHandler, fileType)
return p
Expand Down