Skip to content

Commit

Permalink
fix(python): poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki-working committed Nov 28, 2023
1 parent 20ea3b1 commit e589d67
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions module/poetry/poetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package poetry

import (
"context"
"fmt"
"github.com/murphysecurity/murphysec/model"
"github.com/murphysecurity/murphysec/utils"
"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -48,6 +49,9 @@ func (i *Inspector) InspectProject(ctx context.Context) error {
cmap[it.CompName] = it.CompVersion
}
poetryFile := filepath.Join(task.Dir(), "poetry.lock.py")
if !utils.IsFile(poetryFile) {
poetryFile = filepath.Join(task.Dir(), "poetry.lock")
}
if utils.IsFile(poetryFile) {
if deps, e := parsePoetryLock(ctx, poetryFile); e == nil {
for _, it := range deps {
Expand Down Expand Up @@ -82,13 +86,13 @@ func parsePoetry(input []byte) (*Manifest, error) {
if e := toml.Unmarshal(input, &root.v); e != nil {
return nil, errors.WithMessage(ErrParsePoetry, "Parse toml failed")
}
m, ok := root.Get("tool", "poetry", "dependencies").v.(map[string]string)
if !ok {
m, ok := root.Get("tool", "poetry", "dependencies").v.(map[string]any)
if !ok || m == nil {
return nil, errors.WithMessage(ErrParsePoetry, "bad toml")
}
var deps []model.DependencyItem
for k, v := range m {
v := strings.Trim(v, "~^* ")
v := strings.Trim(fmt.Sprint(v), "~^* ")
if v == "" {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion module/poetry/poetry_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func parsePoetryLock(ctx context.Context, f string) (rs []model.DependencyItem,
return nil, e
}
root := &tomlTree{}
if e := toml.Unmarshal(data, &root); e != nil {
if e := toml.Unmarshal(data, &root.v); e != nil {
logger.Warnf("Parse toml failed. %v %v", e.Error(), f)
return nil, e
}
Expand Down

0 comments on commit e589d67

Please sign in to comment.