mirror of
https://github.com/safedep/vet.git
synced 2025-12-11 01:01:10 -06:00
feat: Building code graph Refactor to support import processing Handle relative import name fixup Add docs for code analysis framework Update docs to include additional examples feat: Function call graph Update code graph to link function decl and calls Include call node in function calls feat: Flatten vulnerabilities in CSV reporter refactor: Maintain separation of concerns for code analysis framework refactor: Separate storage entities in its own package feat: Add callback support in code graph builder docs: Fix code analysis framework docs Signed-off-by: abhisek <abhisek.datta@gmail.com>
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package entities
|
|
|
|
import "github.com/safedep/vet/pkg/storage/graph"
|
|
|
|
const (
|
|
// The entity type
|
|
PackageEntity = "package"
|
|
|
|
// Entity specific constants
|
|
PackageEntitySourceTypeApp = "app"
|
|
PackageEntitySourceTypeImport = "import"
|
|
|
|
// Property names
|
|
PackagePropertyName = "name"
|
|
PackagePropertySourceFilePath = "sourceFilePath"
|
|
PackagePropertySourceFileType = "sourceFileType"
|
|
|
|
// Relationship names
|
|
PackageRelationshipImports = "imports"
|
|
PackageRelationshipDeclaresFunction = "declares_function"
|
|
)
|
|
|
|
type Package struct {
|
|
Id string
|
|
Name string
|
|
SourceFilePath string
|
|
SourceFileType string
|
|
}
|
|
|
|
func (p *Package) Properties() map[string]string {
|
|
return map[string]string{
|
|
PackagePropertyName: p.Name,
|
|
PackagePropertySourceFilePath: p.SourceFilePath,
|
|
PackagePropertySourceFileType: p.SourceFileType,
|
|
}
|
|
}
|
|
|
|
func (p *Package) Imports(anotherPackage *Package) *graph.Edge {
|
|
return &graph.Edge{
|
|
Name: PackageRelationshipImports,
|
|
From: &graph.Node{
|
|
ID: p.Id,
|
|
Label: PackageEntity,
|
|
Properties: p.Properties(),
|
|
},
|
|
To: &graph.Node{
|
|
ID: anotherPackage.Id,
|
|
Label: PackageEntity,
|
|
Properties: anotherPackage.Properties(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func (p *Package) DeclaresFunction(fn *FunctionDecl) *graph.Edge {
|
|
return &graph.Edge{
|
|
Name: PackageRelationshipDeclaresFunction,
|
|
From: &graph.Node{
|
|
ID: p.Id,
|
|
Label: PackageEntity,
|
|
Properties: p.Properties(),
|
|
},
|
|
To: &graph.Node{
|
|
ID: fn.Id,
|
|
Label: FunctionDeclEntity,
|
|
Properties: fn.Properties(),
|
|
},
|
|
}
|
|
}
|