Documentation ¶
Index ¶
Constants ¶
const ( REQUIRED = "required" OPTIONAL = "optional" FORBIDDEN = "forbidden" )
const VALIDATION_DB_SUFFIX = ".valdb"
Variables ¶
var TAR_SUFFIX = regexp.MustCompile("\\.tar$")
Functions ¶
func ValidPresenceValue ¶
Returns true if value is a valid presence value.
Types ¶
type BagValidationConfig ¶
type BagValidationConfig struct { // FileSpecs is a map of FileSpec structures, describing // rules for specific files. The key is the relative path // to the file within the bag. // E.g. bag-info.txt or dpn_tags/dpn-info.txt. FileSpecs map[string]FileSpec // TagSpecs is a map of TagSpec objects. The key is the // tag name (e.g. Source-Organization or Internal-Sender-Description) // and the value is the TagSpec. TagSpecs map[string]TagSpec // AllowFetchTxt describes whether we should allow the fetch.txt file // to be present in a bag. APTrust prohibits this, because honoring // fetch.txt involves downloading remote files, validating their // checksums, and saving them in preservation storage. AllowFetchTxt bool // AllowMiscTopLevelFiles describes whether a valid bag can // contain files not specifically defined in the config. AllowMiscTopLevelFiles bool // AllowMiscDirectories describes whether a valid bag can // contain Directories other than the data directory. AllowMiscDirectories bool // TopLevelDirMustMatchBagName describes whether a tarred bag // must untar to a directory whose name matches the tar file // name. E.g. Must my_bag.tar untar to a directory called my_tar? TopLevelDirMustMatchBagName bool // Which fixity algorithms should we calculate on tag and // payload files? FixityAlgorithms []string // Regex to describe valid file and directory names. // This can also be set to APTRUST to use the standard APTrust // filename pattern defined in constants.APTrustFileNamePattern, // or POSIX to use POSIX file name rules. FileNamePattern string // Regex compiled internally from FileNamePattern. FileNameRegex *regexp.Regexp }
BagValidationConfig lets us specify what constitutes a valid bag. While our validator will do standard validations, such as verifying checksums against manifests, this config lets us specify whether certain files and tags must be present for the specific BagIt spec we're validating against.
func LoadBagValidationConfig ¶
func LoadBagValidationConfig(pathToConfigFile string) (*BagValidationConfig, []error)
func NewBagValidationConfig ¶
func NewBagValidationConfig() *BagValidationConfig
func (*BagValidationConfig) CompileFileNameRegex ¶
func (config *BagValidationConfig) CompileFileNameRegex() error
Call this before testing file names in the bag. This compiles the filename validation regex, if the config includes a validation pattern. Note the two built-in patterns: constants.APTrustFileNamePattern and constants.PosixFileNamePattern. If you load your validation config from a file, LoadBagValidationConfig calls this for you.
func (*BagValidationConfig) ValidateConfig ¶
func (config *BagValidationConfig) ValidateConfig() []error
type FileSpec ¶
type FileSpec struct { // Presence can be REQUIRED, OPTIONAL, or FORBIDDEN. Presence string // If this is true, the file must be parsed as a BagIt // tag file, using the label:value format. ParseAsTagFile bool }
FileSpec defines whether files at a specified path within the bag are required, optional, or forbidden.
type TagSpec ¶
type TagSpec struct { // FilePath is the path of the file within the bag. // This will obviously be a relative path. FilePath string // Presence can be REQUIRED, OPTIONAL, or FORBIDDEN. Presence string // EmptyOK indicates whether its OK for the tag value // to be empty. EmptyOK bool // Describes which values are allowed (case-insensitive). AllowedValues []string }
TagSpec describes rules for tags in colon-delimited BagIt-parsable text files.
type Validator ¶
type Validator struct { PathToBag string BagValidationConfig *BagValidationConfig PreserveExtendedAttributes bool ObjIdentifier string // contains filtered or unexported fields }
Validator validates a BagIt bag using a BagValidationConfig object, which describes the bag's requirements.
func NewValidator ¶
func NewValidator(pathToBag string, bagValidationConfig *BagValidationConfig, preserveExtendedAttributes bool) (*Validator, error)
NewValidator creates a new Validator. Param pathToBag should be an absolute path to either the tarred bag (.tar file) or to the untarred bag (a directory). Param bagValidationConfig defines what we need to validate, in addition to the checksums in the manifests. If param preserveExtendedAttributes is true, the validator will preserve special data attributes used by the APTrust ingest process, AND will leave the .valdb validation database in place after it completes its work. If false, it will keep just enough data to validate file lists and checksums, and will delete the .valdb database when it's finished.