Skip to content

Commit

Permalink
Fix some lints
Browse files Browse the repository at this point in the history
Signed-off-by: C0D3 M4513R <[email protected]>
  • Loading branch information
C0D3-M4513R committed Jun 20, 2024
1 parent d700f57 commit 9a83f3f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
60 changes: 30 additions & 30 deletions syft/pkg/rust/cargo_lock_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/sha1" //#nosec G505 G401 -- sha1 is used as a required hash function for SPDX, not a crypto function
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -106,35 +105,36 @@ func (r *RustCargoLockEntry) getPrefix() string {
}
}

func (r *RustCargoLockEntry) getIndexPath() string {
return fmt.Sprintf("%s/%s", strings.ToLower(r.getPrefix()), strings.ToLower(r.Name))
}

func (r *RustCargoLockEntry) getIndexContent() ([]DependencyInformation, []error) {
var deps []DependencyInformation
var sourceID, err = r.getSourceID()
if err != nil {
return deps, []error{err}
}
var content []byte
var errors []error
content, err = sourceID.GetPath(r.getIndexPath())
if err != nil {
return deps, []error{err}
}
for _, v := range bytes.Split(content, []byte("\n")) {
var depInfo = DependencyInformation{
StructVersion: 1,
}
err = json.Unmarshal(v, &depInfo)
if err == nil {
deps = append(deps, depInfo)
} else {
errors = append(errors, err)
}
}
return deps, errors
}
// Todo: Do we care about any metadata present in the rust repository index?
// func (r *RustCargoLockEntry) getIndexPath() string {
// return fmt.Sprintf("%s/%s", strings.ToLower(r.getPrefix()), strings.ToLower(r.Name))
// }
//
// func (r *RustCargoLockEntry) getIndexContent() ([]DependencyInformation, []error) {
// var deps []DependencyInformation
// var sourceID, err = r.getSourceID()
// if err != nil {
// return deps, []error{err}
// }
// var content []byte
// var errors []error
// content, err = sourceID.GetPath(r.getIndexPath())
// if err != nil {
// return deps, []error{err}
// }
// for _, v := range bytes.Split(content, []byte("\n")) {
// var depInfo = DependencyInformation{
// StructVersion: 1,
// }
// err = json.Unmarshal(v, &depInfo)
// if err == nil {
// deps = append(deps, depInfo)
// } else {
// errors = append(errors, err)
// }
// }
// return deps, errors
// }

func (r *RustCargoLockEntry) getContent() ([]byte, string, error) {
var content []byte
Expand Down
10 changes: 5 additions & 5 deletions syft/pkg/rust/config.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package rust

type CatalogerConfig struct {
//Todo: find a way to replicate cargo's mapping from repository source to their repository dir name
// Todo: find a way to replicate cargo's mapping from repository source to their repository dir name
// When that's done we could enable LocalModCacheDir to point to cargo's cache and read directly from there
//SearchLocalModCacheLicenses bool `yaml:"search-local-mod-cache-licenses" json:"search-local-mod-cache-licenses" mapstructure:"search-local-mod-cache-licenses"`
//LocalModCacheDir string `yaml:"local-mod-cache-dir" json:"local-mod-cache-dir" mapstructure:"local-mod-cache-dir"`
// SearchLocalModCacheLicenses bool `yaml:"search-local-mod-cache-licenses" json:"search-local-mod-cache-licenses" mapstructure:"search-local-mod-cache-licenses"`
// LocalModCacheDir string `yaml:"local-mod-cache-dir" json:"local-mod-cache-dir" mapstructure:"local-mod-cache-dir"`
SearchRemote bool `yaml:"search-remote" json:"search-remote" mapstructure:"search-remote"`
}

func DefaultCatalogerConfig() CatalogerConfig {
return CatalogerConfig{
//SearchLocalModCacheLicenses: true,
//LocalModCacheDir: "~/.cargo/registry",
// SearchLocalModCacheLicenses: true,
// LocalModCacheDir: "~/.cargo/registry",
SearchRemote: true,
}
}
8 changes: 2 additions & 6 deletions syft/pkg/rust/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func (r *CargoInfoResolver) Resolve(entry RustCargoLockEntry) (SourceGeneratedDe
return EmptySourceGeneratedDepInfo(), fmt.Errorf("no Registry Information present")
}

return r.crateCache.Resolve(entry.Source, func() (SourceGeneratedDepInfo, error) {
return entry.getGeneratedInformationUncached()
})
return r.crateCache.Resolve(entry.Source, entry.getGeneratedInformationUncached)
}

func (r *CargoInfoResolver) ResolveRepo(entry RustCargoLockEntry) (RegistryGeneratedInfo, error) {
Expand All @@ -51,7 +49,5 @@ func (r *CargoInfoResolver) ResolveRepo(entry RustCargoLockEntry) (RegistryGener
return EmptyRegistryGeneratedDepInfo(), fmt.Errorf("we are not allowed to search remotly for extra info")
}

return r.repoCache.Resolve(entry.Source, func() (RegistryGeneratedInfo, error) {
return entry.toRegistryGeneratedDepInfo()
})
return r.repoCache.Resolve(entry.Source, entry.toRegistryGeneratedDepInfo)
}

0 comments on commit 9a83f3f

Please sign in to comment.