// buildDPNBag bags the DPNBag object that will eventually be entered into // the DPN registry. This is not the bag itself, just the DPN registry entry. func (packager *DPNPackager) buildDPNBag(manifest *models.DPNIngestManifest) { packager.Context.MessageLog.Info("Building DPN bag record for %s", manifest.IntellectualObject.Identifier) depositingInstitution := packager.getInstitution(manifest) if depositingInstitution == nil { return } manifest.DPNBag = models.NewDPNBag( manifest.IntellectualObject.Identifier, depositingInstitution.DPNUUID, packager.Context.Config.DPN.LocalNode) // Calculate the sha256 digest of the tag manifest. This is used for // validating bag transfers in DPN. Note that we are NOT using a // nonce when we call shaHash.Sum(nil). Though the DPN spec allows // us to use a nonce, no nodes are using nonces as of late 2016. tagManifestFile := filepath.Join(manifest.LocalDir, "tagmanifest-sha256.txt") if !fileutil.FileExists(tagManifestFile) { manifest.PackageSummary.AddError("Cannot find tag manifest %s", tagManifestFile) return } reader, err := os.Open(tagManifestFile) if err != nil { manifest.PackageSummary.AddError("Cannot read tag manifest at %s: %v", tagManifestFile, err) return } defer reader.Close() shaHash := sha256.New() io.Copy(shaHash, reader) tagManifestDigest := fmt.Sprintf("%x", shaHash.Sum(nil)) // Now create the MessageDigest for this bag, with the tag manifest // checksum that will be used to verify transfers. When a remote // node copies this bag to fulfill a replication request, we expect // the node to return this fixity value as proof that it received // a valid copy of the bag. digest := &models.MessageDigest{ Bag: manifest.DPNBag.UUID, Algorithm: constants.AlgSha256, Node: packager.Context.Config.DPN.LocalNode, Value: tagManifestDigest, CreatedAt: time.Now().UTC(), } manifest.DPNBag.MessageDigests = append(manifest.DPNBag.MessageDigests, digest) // Now that we have a valid DPN bag object, we can name the tar file. // According to the DPN spec, the tar file name should be the bag's // UUID plus a ".tar" extension. parentOfBagDir := filepath.Dir(manifest.LocalDir) manifest.LocalTarFile = filepath.Join(parentOfBagDir, manifest.DPNBag.UUID+".tar") }