Skip to content
moov-ioPublic

About

Open Source Metro 2 consumer credit history report for credit report file creation and validation

Topics

Resources

Contributing

Security policy

Stars

131 stars

Watchers

5 watching

Forks

Repository files navigation

Moov Banner Logo

Project Documentation · API Endpoints · API Guide · Community · Blog

GoDoc Build Status Coverage Status Go Report Card Repo Size Apache 2 License Slack Channel Docker Pulls GitHub Stars Twitter

moov-io/metro2

Moov's mission is to give developers an easy way to create and integrate bank processing into their own software products. Our open source projects are each focused on solving a single responsibility in financial services and designed around performance, scalability, and ease-of-use.

Metro2 implements a reader, writer, and validator for consumer credit history reports in an HTTP server and Go library. The HTTP server is available in a Docker image and the Go package github.com/moov-io/metro2 is available.

Table of contents

Project status

Moov Metro2 is actively used in multiple production environments. Please star the project if you are interested in its progress. If you have layers above Metro2 to simplify tasks, perform business operations, or found bugs we would appreciate an issue or pull request. Thanks!

Usage

The Metro2 project implements an HTTP server and Go library for creating and modifying files in Metro 2 format, which is used for consumer credit history reporting by U.S. credit bureaus.

Docker

We publish a public Docker image moov/metro2 on Docker Hub with each tagged release of Metro2. No configuration is required to serve on :8080. We also have Docker images for OpenShift published as quay.io/moov/metro2.

Pull & start the Docker image:

docker pull moov/metro2:latest
docker run -p 8080:8080 moov/metro2:latest

Upload a file and validate it:

curl -X POST --form "file=@./test/testdata/packed_file.json" http://localhost:8080/validator
{"status":"valid file"}

Convert a file from JSON to raw Metro format:

curl -X POST --form "file=@./test/testdata/packed_file.json" --form "format=metro" http://localhost:8080/convert

The response is a packed Metro 2 file (Content-Type: application/octet-stream) that starts with binary block and record descriptor words (01 72 00 00 01 6e 00 00, then HEADER), not ASCII text. To get character-encoded records, add --form "type=character".

Convert a file from raw Metro format to JSON:

curl -X POST --form "file=@./test/testdata/packed_file.dat" --form "format=json" http://localhost:8080/convert
{"header": {"blockDescriptorWord": 370,"recordDescriptorWord": 366,"recordIdentifier": "HEADER","transUnionProgramIdentifier": "5555555555","activityDate": "2002-08-20T00:00:00Z", ...

Google Cloud Run

To get started in a hosted environment you can deploy this project to the Google Cloud Platform.

From your Google Cloud dashboard create a new project and call it:

moov-metro2-demo

Enable the Artifact Registry and Cloud Run APIs for your project and associate a billing account if needed. Then, open the Cloud Shell terminal and run the following commands, substituting your unique project ID and a region close to you (for example us-central1):

gcloud services enable artifactregistry.googleapis.com run.googleapis.com

gcloud artifacts repositories create moov   --repository-format=docker   --location=us-central1   --description="Docker images"

gcloud auth configure-docker us-central1-docker.pkg.dev

docker pull moov/metro2
docker tag moov/metro2 us-central1-docker.pkg.dev/<PROJECT-ID>/moov/metro2
docker push us-central1-docker.pkg.dev/<PROJECT-ID>/moov/metro2

Deploy the container to Cloud Run:

gcloud run deploy metro2 --image us-central1-docker.pkg.dev/<PROJECT-ID>/moov/metro2 --port 8080 --region us-central1

You can also deploy the public image directly with gcloud run deploy metro2 --image moov/metro2:latest --port 8080 --region us-central1. Upon a successful deploy you will be given a URL where the API has been deployed:

https://YOUR-METRO2-APP-URL.a.run.app

Now you can complete a health check:

curl https://YOUR-METRO2-APP-URL.a.run.app/health

You should get this response:

{"status":"alive"}

Data persistence

By design, Metro2 does not persist (save) any data about the files or entry details created. The only storage occurs in memory of the process and upon restart Metro2 will have no files or data saved. Also, no in-memory encryption of the data is performed.

Command line

Metro2 has a command line interface to manage Metro 2 files and launch a web service.

Download a release binary from the latest GitHub release. Assets are named metro2-linux-amd64, metro2-darwin-amd64, and metro2.exe (Windows):

curl -sSL -o metro2 "https://github.com/moov-io/metro2/releases/download/v0.10.0/metro2-linux-amd64"
chmod +x metro2

Or install with Go 1.26 or newer:

go install github.com/moov-io/metro2/cmd/metro2@latest

From a source checkout, make build writes ./bin/metro2.

metro2 --help

Moov Metro 2 file reader, writer, and validator

Usage:
  metro2 [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  convert     Convert metro file format
  help        Help about any command
  print       Print metro file
  validator   Validate metro file
  version     Print the version of metro2
  web         Launches web server

Flags:
  -h, --help           help for metro2
      --input string   input file (default is $PWD/metro.json)

Use "metro2 [command] --help" for more information about a command.

The CLI exits 0 on success and 1 on error (missing input, validation failure, or a convert path whose parent directory does not exist). convert supports --format json|metro, --type character|packed, -n/--newline, and -g/--generate. See the command line documentation for packed versus character format, sample output, and exit codes.

Each interaction that the library supports is exposed in a command-line option:

Command Info
convert The convert command allows users to convert a metro file to a specified file format (json, metro). The result will create a new file.
print The print command allows users to print a metro file in a specified file format (json, metro).
validator The validator command allows users to validate a metro file.
version Print the library version.
web The web command will launch a web server with endpoints to manage metro files.

Go library

This project uses Go Modules and Go v1.26 or newer. See Golang's install instructions for help setting up Go. You can download the source code and we offer tagged and released versions as well. We highly recommend you use a tagged release for production.

Package Installation

# Clone the repository
git clone git@github.com:moov-io/metro2.git

# Add a tagged package to your Go module (avoid go get -u; it can bump
# the Go version in go.mod and leave missing go.sum entries)
go get github.com/moov-io/metro2/pkg/file@v0.10.0

go doc github.com/moov-io/metro2/pkg/file

Package Overview

The Go API lives in pkg/file, pkg/lib, and pkg/utils. file.File is the main entry point:

func NewFile(format string) (File, error)
func NewFileFromReader(r io.Reader) (File, error)
func CreateFile(buf []byte) (File, error)

type File
	GetType() string
	SetType(string) error
	SetRecord(lib.Record) error
	AddDataRecord(lib.Record) error
	GetRecord(string) (lib.Record, error)
	GetDataRecords() []lib.Record
	GeneratorTrailer() (lib.Record, error)
	Parse(record []byte, isVariableLength bool) error
	Bytes() []byte
	String(newline bool) string
	ConcurrentString(newline bool, goroutines int) string
	Validate() error

Use utils.CharacterFileFormat or utils.PackedFileFormat with NewFile. Records (lib.HeaderRecord, lib.BaseSegment, lib.TrailerRecord, and the packed variants) implement Parse([]byte, bool), String(), Bytes(), and Validate(). Optional J1, J2, K1–K4, L1, and N1 segments attach to a base record with AddApplicableSegment. See the Go library docs for details and a from-scratch example.

Package Examples

Read a Metro 2 file, validate it, and write it back out:

r, err := os.Open("test/testdata/unpacked_fixed_file.dat")
if err != nil {
	log.Fatal(err)
}
defer r.Close()

f, err := file.NewFileFromReader(r)
if err != nil {
	log.Fatal(err)
}
if err := f.Validate(); err != nil {
	log.Fatal(err)
}

fmt.Print(f.String(true))

To build a file from scratch, create a file.File, SetRecord a header, AddDataRecord one or more base segments (with optional J1/K segments), then GeneratorTrailer / SetRecord and Validate. A complete, tested example is in the Go library docs and as ExampleNewFileFromReader / Example_createFile in pkg/file.

Learn about Metro 2

Getting help

channel info
Twitter @moov You can follow Moov.io's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories.
GitHub Issue If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error.
moov-io slack Join our slack channel to have an interactive discussion about the development of the project.

Supported and tested platforms

  • 64-bit Linux (Ubuntu, Debian), macOS, and Windows

Contributing

Yes please! Please review our Contributing guide and Code of Conduct to get started!

This project uses Go Modules and Go v1.26 or newer. See Golang's install instructions for help setting up Go. You can download the source code and we offer tagged and released versions as well. We highly recommend you use a tagged release for production.

Releasing

To make a release of metro2 update version.go with the next version number and push a tag (i.e. git push origin v1.0.0) so CI can create the GitHub Release. Release notes live on GitHub Releases; CHANGELOG.md is frozen for historical entries.

Testing

We maintain a comprehensive suite of unit tests and recommend table-driven testing when a particular function warrants several very similar test cases. To run all test files in the current directory, use go test. Current overall coverage can be found on Codecov.

Fuzzing

We currently run fuzzing over Metro 2 in the form of a Github Action. Please report crash examples to oss@moov.io. Thanks!

Related projects

As part of Moov's initiative to offer open source fintech infrastructure, we have a large collection of active projects you may find useful:

  • Moov Watchman offers search functions over numerous trade sanction lists from the United States and European Union.

  • Moov Fed implements utility services for searching the United States Federal Reserve System such as ABA routing numbers, financial institution name lookup, and FedACH and Fedwire routing information.

  • Moov Wire implements an interface to write files for the Fedwire Funds Service, a real-time gross settlement funds transfer system operated by the United States Federal Reserve Banks.

  • Moov ACH provides ACH file generation and parsing, supporting all Standard Entry Codes for the primary method of money movement throughout the United States.

  • Moov Image Cash Letter implements Image Cash Letter (ICL) files used for Check21, X.9 or check truncation files for exchange and remote deposit in the U.S.

License

Apache License 2.0 - See LICENSE for details.

About

Open Source Metro 2 consumer credit history report for credit report file creation and validation

Topics

Resources

Contributing

Security policy

Stars

131 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages