github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/extractor/dotnetcom/dotnetcom.go (about)

     1  package dotnetcom
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/vchain-us/vcn/pkg/api"
     9  	"github.com/vchain-us/vcn/pkg/bom/artifact"
    10  	"github.com/vchain-us/vcn/pkg/bom/dotnet"
    11  	"github.com/vchain-us/vcn/pkg/extractor"
    12  	"github.com/vchain-us/vcn/pkg/uri"
    13  )
    14  
    15  // Scheme for Go component
    16  const Scheme = "dotnetcom"
    17  
    18  // Artifact returns a file *api.Artifact from a given uri
    19  func Artifact(u *uri.URI, options ...extractor.Option) ([]*api.Artifact, error) {
    20  	if u.Scheme != Scheme {
    21  		return nil, nil
    22  	}
    23  
    24  	path := strings.TrimPrefix(u.Opaque, "//")
    25  
    26  	fields := strings.Split(path, "@")
    27  	if len(fields) != 2 {
    28  		return nil, errors.New("component path format is <name>@<version>")
    29  	}
    30  
    31  	pkgCacheDirs, err := dotnet.GetPackageHCacheDirs()
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	hash, err := dotnet.GetPackageHash(fields[0], fields[1], pkgCacheDirs)
    37  	if err != nil {
    38  		return nil, fmt.Errorf("cannot get checksum for module %s: %w", path, err)
    39  	}
    40  
    41  	return []*api.Artifact{artifact.ToApiArtifact(dotnet.AssetType, fields[0], fields[1], hash, artifact.HashSHA512)}, nil
    42  }