github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/language/dotnet/depsjson/metadata.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package depsjson
    16  
    17  import (
    18  	pb "github.com/google/osv-scalibr/binary/proto/scan_result_go_proto"
    19  )
    20  
    21  // Metadata holds parsing information for a deps.json package.
    22  type Metadata struct {
    23  	PackageName    string // The name of the package.
    24  	PackageVersion string // The version of the package.
    25  	// Type indicates the type of the package. Examples include:
    26  	// - "package": Represents an external dependency, such as a NuGet package.
    27  	// - "project": Represents an internal dependency, such as the main application
    28  	Type string
    29  }
    30  
    31  // SetProto sets the DEPSJSONMetadata field in the Package proto.
    32  func (m *Metadata) SetProto(p *pb.Package) {
    33  	if m == nil {
    34  		return
    35  	}
    36  	if p == nil {
    37  		return
    38  	}
    39  
    40  	p.Metadata = &pb.Package_DepsjsonMetadata{
    41  		DepsjsonMetadata: &pb.DEPSJSONMetadata{
    42  			PackageName:    m.PackageName,
    43  			PackageVersion: m.PackageVersion,
    44  			Type:           m.Type,
    45  		},
    46  	}
    47  }
    48  
    49  // ToStruct converts the DEPSJSONMetadata proto to a Metadata struct.
    50  func ToStruct(m *pb.DEPSJSONMetadata) *Metadata {
    51  	if m == nil {
    52  		return nil
    53  	}
    54  
    55  	return &Metadata{
    56  		PackageName:    m.GetPackageName(),
    57  		PackageVersion: m.GetPackageVersion(),
    58  		Type:           m.GetType(),
    59  	}
    60  }