1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 2 3package builder2v2 4 5import ( 6 "time" 7 8 "github.com/spdx/tools-golang/spdx/common" 9 "github.com/spdx/tools-golang/spdx/v2_2" 10) 11 12// BuildCreationInfoSection2_2 creates an SPDX Package (version 2.2), returning that 13// package or error if any is encountered. Arguments: 14// - packageName: name of package / directory 15// - code: verification code from Package 16// - namespacePrefix: prefix for DocumentNamespace (packageName and code will be added) 17// - creatorType: one of Person, Organization or Tool 18// - creator: creator string 19// - testValues: for testing only; call with nil when using in production 20func BuildCreationInfoSection2_2(creatorType string, creator string, testValues map[string]string) (*v2_2.CreationInfo, error) { 21 // build creator slices 22 creators := []common.Creator{ 23 // add builder as a tool 24 { 25 Creator: "github.com/spdx/tools-golang/builder", 26 CreatorType: "Tool", 27 }, 28 { 29 Creator: creator, 30 CreatorType: creatorType, 31 }, 32 } 33 34 // use test Created time if passing test values 35 location, _ := time.LoadLocation("UTC") 36 locationTime := time.Now().In(location) 37 created := locationTime.Format("2006-01-02T15:04:05Z") 38 if testVal := testValues["Created"]; testVal != "" { 39 created = testVal 40 } 41 42 ci := &v2_2.CreationInfo{ 43 Creators: creators, 44 Created: created, 45 } 46 return ci, nil 47} 48