From 60e04637ab6ad0210ae2b780acc3eff1a455a564 Mon Sep 17 00:00:00 2001 From: Emily McMullan Date: Mon, 24 Jun 2024 14:18:01 -0400 Subject: [PATCH] validate files Signed-off-by: Emily McMullan --- cmd/analyze.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/analyze.go b/cmd/analyze.go index ff2a507..1baae38 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -69,6 +69,7 @@ var ( } ) +// supported providers const ( javaProvider = "java" goProvider = "go" @@ -87,6 +88,14 @@ const ( dependencyProviderPath = "dependencyProviderPath" ) +// valid java file extensions +const ( + JavaArchive = ".jar" + WebArchive = ".war" + EnterpriseArchive = ".ear" + ClassFile = ".class" +) + // TODO add network and volume w/ interface type ProviderInit struct { port int @@ -374,6 +383,14 @@ func (a *analyzeCommand) Validate(ctx context.Context) error { // when input isn't a dir, it's pointing to a binary // we need abs path to mount the file correctly if !stat.Mode().IsDir() { + // validate file types + fileExt := filepath.Ext(a.input) + switch fileExt { + case JavaArchive, WebArchive, EnterpriseArchive, ClassFile: + a.log.V(5).Info("valid java file found") + default: + return fmt.Errorf("invalid file type %v", fileExt) + } a.input, err = filepath.Abs(a.input) if err != nil { return fmt.Errorf("%w failed to get absolute path for input file %s", err, a.input)