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