Categorygithub.com/dmolesUC3/cos
repositorypackage
0.6.1
Repository: https://github.com/dmolesuc3/cos.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

cos

A tool for testing and validating cloud object storage.

Invocation

Invocation is in the form

cos <command> [flags] [URL]

where <command> is one of:

  • check: compute and (optionally) verify the digest of an object
  • crvd: create, retrieve, verify, and delete an object
  • keys: test the keys supported by an object storage endpoint
  • suite: run a suite of test cases investigating various possible limitations of a cloud storage service
  • help: list these commands, or get help for a subcommand

and [URL] can be the URL of an object or of a bucket/container, depending on the context. The protocol (s3:// or swift://) of the URL is used to determine the cloud storage API to use.

Authentication

For authentication, cos uses the same environment variables as the AWS CLI (for S3 and compatible storage) or OpenStack Swift CLI (for Swift storage):

ProtocolVariablePurpose
S3AWS_ACCESS_KEY_IDAWS access key
AWS_SECRET_ACCESS_KEYSecret key associated with the AWS access key
SwiftST_USERSwift username
ST_KEYSwift password

Credentials for S3 storage can also be specified in various other ways supported by the AWS SDK for Go, such as a shared credentials file or, when running in the Amazon EC2 environment, an IAM role.

Flags

All cos commands support the following flags:

Short formFlagDescription
-e--endpoint ENDPOINTHTTP(S) endpoint URL (required)
-r--region REGIONAWS region (optional)
-v--verboseVerbose output
-h--helpPrint help and exit

For Amazon S3 buckets, the region can usually be determined from the endpoint URL. If not, and if the --region flag is not provided, it defaults to us-west-2.

For OpenStack Swift containers, the --region flag is ignored.

Additional command-specific flags are listed below.

Commands

cos check

The check command computes and (optionally) verifies the digest of an object. The object is streamed in five-megabyte chunks, each chunk being added to the digest computation and then discarded, thus making it possible to verify objects of arbitary size, not limited by local storage space.

In addition to the global flags listed above, the check command supports the following:

Short formFlagDescription
-a--algorithm ALGDigest algorithm (md5 or sha256; defaults to sha256)
-x--expected DIGESTExpected digest value

By default, check outputs the digest to standard output, and exits:

$ cos check --endpoint https://s3.us-west-2.amazonaws.com/ s3://www.dmoles.net/images/fa/archive.svg/
c99ad299fa53d5d9688909164cf25b386b33bea8d4247310d80f615be29978f5

If given an expected value that does not match, prints a message to standard error, and exits with a nonzero (unsuccessful) exit code.

$ cos check --endpoint https://s3.us-west-2.amazonaws.com/ s3://www.dmoles.net/images/fa/archive.svg/ \
  -x 5f87992eb516f08d0137424d8aeb33b683b52fc4619098869d5d35af992da99c
digest mismatch: 
expected: 5f87992eb516f08d0137424d8aeb33b683b52fc4619098869d5d35af992da99c
actual: c99ad299fa53d5d9688909164cf25b386b33bea8d4247310d80f615be29978f5

cos crvd

The crvd command creates, retrieves, verifies, and deletes an object. The object consists of a stream of random bytes of the specified size.

The size may be specified as an exact number of bytes, or using human-readable quantities such as "5K" (4 KiB or 4096 bytes), "3.5M" (3.5 MiB or 3670016 bytes), etc. The units supported are bytes (B), binary kilobytes (K, KB, KiB), binary megabytes (M, MB, MiB), binary gigabytes (G, GB, GiB), and binary terabytes (T, TB, TiB). If no unit is specified, bytes are assumed.

Random bytes are generated using the Go default random number generator, with a default seed of 0, for repeatability. An alternative seed can be specified with the --random-seed flag.

In addition to the global flags listed above, the check command supports the following:

Short formFlagDescription
-s--size SIZEsize of object to create (default 128 bytes)
-k--key KEYkey to create (defaults to cos-crvd-TIMESTAMP.bin)
--random-seed SEEDseed for random-number generator (default 1)
--keepkeep object after verification (default false)
$ crvd swift://distrib.stage.9001.__c5e/ -e http://cloud.sdsc.edu/auth/v1.0 
128B object created, retrieved, verified, and deleted (swift://distrib.stage.9001.__c5e/cos-crvd-1549324512.bin)

cos keys

The keys command tests the keys supported by an object storage endpoint, creating, retrieving, validating, and deleting a small object for each value in the specified key list.

In addition to the global flags listed above, the keys command supports the following:

Short formFlagDescription
--rawwrite keys in raw (unquoted) format
-o--ok FILEwrite successful ("OK") keys to specified file
-b--bad FILEwrite failed ("bad") keys to specified file
-l--list LISTuse the specified 'standard' list of keys
-f--file FILEread keys to be tested from the specified file
-s--sample COUNTsample size, or 0 for all keys

By default, keys outputs only failed keys, to standard output, writing each key as a quoted Go string literal.

$ cos keys s3://uc3-s3mrt5001-stg/ -e 'https://s3-us-west-2.amazonaws.com/' --list misc 
"../leading-double-dot-path"
"../../leading-multiple-double-dot-path"
"trailing-double-dot-path/.."
(...etc.)

Use the --raw option to write the keys without quoting or escaping; note that this may produce confusing results if any of the keys contain newlines.

$ cos keys s3://uc3-s3mrt5001-stg/ -e 'https://s3-us-west-2.amazonaws.com/' --list misc --raw
../leading-double-dot-path
../../leading-multiple-double-dot-path
trailing-double-dot-path/..
trailing-multiple-double-dot-path/../..
(...etc.)

Use the --ok option to write successful keys to a file, and the --bad option (or shell redirection) to write failed keys to a file instead of stdout.

$ cos keys s3://uc3-s3mrt5001-stg/ -e 'https://s3-us-west-2.amazonaws.com/' --list misc \
  --ok out/keys-ok.txt --bad out/keys-bad.txt

Several "standard" lists are provided (though these aren't very systematic; see #10). Use the --file option to specify a file containing keys to test, one key per file, separated by newlines (LF, U+000A, \n).

$ cos keys s3://uc3-s3mrt5001-stg/ -e 'https://s3-us-west-2.amazonaws.com/' \
  --file my-keys.txt

Use the --sample option to check only a random sample from a large key list:

$ cos keys s3://uc3-s3mrt5001-stg/ -e 'https://s3-us-west-2.amazonaws.com/' \
  --file my-very-long-list-of-keys.txt \
  --sample 500

cos suite

The suite command a suite of test cases investigating various possible limitations of a cloud storage service:

  • maximum file size (--size)
  • maximum number of files per key prefix (--count)
  • Unicode key support (--unicode)

If none of --size, --count, etc. is specified, all test cases are run.

Unicode key support tests are further divided into:

  • Unicode category support (--unicode-categories)
  • Unicode script support (--unicode-scripts)
  • Unicode properties support (--unicode-properties)
  • Unicode emoji support (--unicode-emoji)

If --unicode is specified, all of these are run.

Note that there is considerable overlap between the characters in the category support, script support, and properties support tests.

In addition to the global flags listed above, the keys command supports the following:

Short formFlagDescription
-s--sizetest file sizes
--size-max SIZEmax file size to create (default "256G")
-c--counttest file counts
--count-max COUNTmax number of files to create, or -1 for no limit (default 16777216)
-u--unicodetest Unicode keys
--unicode-categoriestest Unicode categories
--unicode-scriptstest Unicode scripts
--unicode-propertiestest Unicode properties
--unicode-emojitest Unicode emoji
-n--dry-rundry run; list all tests that would be run, but don't make any requests

The maximum size may be specified as an exact number of bytes, or using human-readable quantities such as "5K" (4 KiB or 4096 bytes), "3.5M" (3.5 MiB or 3670016 bytes), etc. The units supported are bytes (B), binary kilobytes (K, KB, KiB), binary megabytes (M, MB, MiB), binary gigabytes (G, GB, GiB), and binary terabytes (T, TB, TiB). If no unit is specified, bytes are assumed.

For developers

cos is a Go 1.11 module.

As such, it requires Go 1.11 or later, and should be cloned outside $GOPATH/src.

Building

The cos project can be built and installed simply with go build and go install, but it also supports Mage.

To install the latest version of Mage:

  1. visit their releases page, download the appropriate binary, and place it in your $PATH, or

  2. from outside this project directory (go get behaves differently when run in the context of a module project), execute the following:

    go get -u -d github.com/magefile/mage \
    && cd $GOPATH/src/github.com/magefile/mage \
    && go run bootstrap.go
    

Mage tasks:

TasksPurpose
buildbuilds a binary for the current platform
buildAllbuilds a binary for each target platform
buildLinuxbuilds a linux-amd64 binary (the most common cross-compile case)
cleanremoves compiled binaries from the current working directory
installinstalls in $GOPATH/bin
platformslists target platforms for buildAll

Note that mage build is a thin wrapper around go build and supports the same environment variables, e.g. $GOOS and $GOARCH.

Running tests

To run all tests in all subpackages, from the project root, use go test ./....

To run all tests in all subpackages with coverage and view a coverage report, use

go test -coverprofile=coverage.out ./... \
&& go tool cover -html=coverage.out

Configuring JetBrains IDEs (GoLand or IDEA)

In Preferences > Go > Go Modules (vgo) (GoLand) or Preferences > Languages & Frameworks Go > Go Modules (vgo) (IDEA + Go plugin) , check “Enable Go Modules (vgo) integration“. The “Vgo Executable” field should default to “Project SDK” (1.11.x).