Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for nested property handler resolution for nodejs. #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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