cmd

package
v0.0.0-...-1c79960 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2025 License: BSD-2-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EXIT_OK means program completed successfully.
	EXIT_OK = 0

	// EXIT_RUNTIME_ERR means program did not complete
	// successfully due to an error. The error may have
	// occurred outside the program, such as a network
	// error or an error on a remote server.
	EXIT_RUNTIME_ERR = 1

	// EXIT_BAG_INVALID is used primarily for apt_validate.
	// It means the program completed its run and found that
	// the bag is not valid.
	EXIT_BAG_INVALID = 2

	// EXIT_USER_ERR means the user did not supply some
	// required option or argument, or the user supplied
	// invalid options/arguments.
	EXIT_USER_ERR = 3

	// EXIT_REQUEST_ERROR means the remote server responded
	// with a 4xx or 5xx HTTP status code.
	EXIT_REQUEST_ERROR = 4

	// EXIT_NO_OP means the user requested help message or
	// version info. The program printed the info, and no other
	// operations were performed.
	EXIT_NO_OP = 100
)

Variables

View Source
var BuildDate string
View Source
var CommitId string
View Source
var ErrImbalancedArgPair = errors.New("odd number of filter args")
View Source
var Version string

Functions

func EnsureDefaultListParams

func EnsureDefaultListParams(values url.Values)

EnsureDefaultListParams adds sort and per_page params to url.Values if they're not already there. This ensures that we don't get too many results per page, and that paging works correctly.

func EnsureDefaultTags

func EnsureDefaultTags(tags []*bagit.TagDefinition) []*bagit.TagDefinition

func Execute

func Execute()

func FindTag

func FindTag(tags []*bagit.TagDefinition, tagFile, tagName string) *bagit.TagDefinition

TODO: Change this to find tags? Tags can repeat.

func GetFlagValue

func GetFlagValue(flags *pflag.FlagSet, flagName, errMsg string) string

GetFlagValue returns the parsed value of flagName. If you specify a non-empty error message, this will cause the program to exit with code EXIT_USER_ERROR and will print the message.

Call this with an empty error message for optional flags, and it won't exit if the flag is missing.

func GetTagValues

func GetTagValues(args []string) []*bagit.TagDefinition

GetTagValues parses tag values from the supplied string slice, which should be collected from the --tags flags.

Format is "tagfile.txt/Tag-Name=Value". If tag file name is missing from param, it's assumed to be bag-info.txt, which is the only customizable tag file in the BagIt standard.

As with the LOC's BagIt-Python library, we convert the first letter of each word in tag names to upper-case. For example, "source-organization" will be converted here to "Source-Organization".

While the BagIt spec does not officially say that tag names must use title case, the examples in the BagIt spec and common convention use title-cased tag names. Some parses may expect or demand title-cased names when validating bags, so we will stick to title case for now.

func GetUrlValues

func GetUrlValues(args []string) url.Values

GetUrlValues converts command-line args that look like name-value pairs into URL values. It converts only those args that contain an equal sign. If an arg is specified more than once, the resulting url.Values will include all of that arg's values.

func InitRegistryRequest

func InitRegistryRequest(config *Config, args []string) (*network.RegistryClient, url.Values)

InitRegistryRequest initializes a registry REST client and the params to be sent in a query string.

func LoadProfile

func LoadProfile(name string) (*bagit.Profile, error)

LoadProfile loads a BagIt profile.

func LooksLikePreservationBucket

func LooksLikePreservationBucket(bucket string) bool

LooksLikePreservationBucket returns true if the bucket name looks like the name of an APTrust preservation bucket.

The caller should exit if the user tries to access an APTrust preservation bucket. Though these buckets have strict access controls with only a single IAM user allowed to write or delete files, we want to protect against the case where some inattentive APTrust admin runs this tool with credentials belonging to that one IAM user. (E.g. An APTrust admin runs this on a production server, and the app pulls crendentials from the environment.) We call this only on S3 upload and delete.

func NewRegistryClient

func NewRegistryClient(config *Config) (*network.RegistryClient, error)

NewRegistryClient returns a new client that can talk to the APTrust Registry. It will return an error if the config lacks essential Registry settings.

func NewS3Client

func NewS3Client(config *Config, s3Host string) *minio.Client

NewS3Client returns a client that can talk to an S3 endpoint. It will return an error if the config is lacking S3 authentication settings.

func PrettyPrintJSON

func PrettyPrintJSON(jsonBytes []byte)

PrettyPrintJSON converts unformatted JSON, such as that returned by the Registry, to formatted JSON.

func PrintErrors

func PrintErrors(errors []string)

func ValidateManifestAlgorithms

func ValidateManifestAlgorithms(profile *bagit.Profile, algs []string) []string

ValidateManifestAlgorithms checks to see whether the user-specified manifest algorithms are allowed by the profile, and whether the user specified all of the profile's required algorithms. We do this work up front, before creating the bag, to avoid creating an invalid bag.

func ValidateTags

func ValidateTags(profile *bagit.Profile, tags []*bagit.TagDefinition) []string

ValidateTags verifies that tags required by the BagIt profile are present and contain valid values. We check this BEFORE bagging because in case where the user is packaging 500+ GB, they don't want to wait two hours to find out their bag is invalid.

Types

type ArgPair

type ArgPair struct {
	Name  string
	Value string
}

func ParseArgPairs

func ParseArgPairs(args []string) []ArgPair

ParseArgPairs converts command-line args that look like key-value pairs into ArgPair objects. It ignores flags and args that do not contain an equal sign.

type Config

type Config struct {
	RegistryURL        string
	RegistryAPIVersion string
	RegistryEmail      string
	RegistryAPIKey     string
	AWSKey             string
	AWSSecret          string
	ConfigSource       string
}

func (*Config) String

func (config *Config) String() string

func (*Config) ValidateAWSCredentials

func (config *Config) ValidateAWSCredentials() error

func (*Config) ValidateRegistryConfig

func (config *Config) ValidateRegistryConfig() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL