Skip to content

Commit

Permalink
validate files
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Jun 24, 2024
1 parent 1300c6e commit 60e0463
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
}
)

// supported providers
const (
javaProvider = "java"
goProvider = "go"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 60e0463

Please sign in to comment.