optout

package module
v0.0.0-...-719d336 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: CC0-1.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ImportComplete = "Completed"
View Source
const ImportFail = "Failed"
View Source
const ImportInprog = "In-Progress"

Variables

This section is empty.

Functions

func ConvertDt

func ConvertDt(s string) (time.Time, error)

func IsForCurrentEnv

func IsForCurrentEnv(filePath string) bool

Checks if the given S3 filePath is for the current environment; this is necessary for lower environments since they share a single BFD S3 bucket and will upload files under a subdirectory for the given env.

func IsOptOut

func IsOptOut(filename string) (isOptOut bool, matches []string)

func ParseS3Uri

func ParseS3Uri(str string) (bucket string, key string)

Parses an S3 URI and returns the bucket and key.

@example:

input: s3://my-bucket/path/to/file
output: "my-bucket", "path/to/file"

@example

input: s3://my-bucket
output: "my-bucket", ""

Types

type FakeSaver

type FakeSaver struct {
	Files         []OptOutFile
	OptOutRecords []OptOutRecord
}

func (*FakeSaver) SaveFile

func (m *FakeSaver) SaveFile(optOutFile OptOutFile) (fileID uint, err error)

func (*FakeSaver) SaveOptOutRecord

func (m *FakeSaver) SaveOptOutRecord(optOutRecord OptOutRecord) error

func (*FakeSaver) UpdateImportStatus

func (m *FakeSaver) UpdateImportStatus(metadata OptOutFilenameMetadata, status string) error

type LocalFileHandler

type LocalFileHandler struct {
	Logger                 logrus.FieldLogger
	PendingDeletionDir     string
	FileArchiveThresholdHr uint
}

LocalFileHandler manages files from local directories. This handler should only be used for local dev/testing now.

func (*LocalFileHandler) CleanupOptOutFiles

func (handler *LocalFileHandler) CleanupOptOutFiles(suppresslist []*OptOutFilenameMetadata) error

func (*LocalFileHandler) LoadOptOutFiles

func (handler *LocalFileHandler) LoadOptOutFiles(path string) (suppressList *[]*OptOutFilenameMetadata, skipped int, err error)

func (*LocalFileHandler) OpenFile

func (handler *LocalFileHandler) OpenFile(metadata *OptOutFilenameMetadata) (*bufio.Scanner, func(), error)

type OptOutFile

type OptOutFile struct {
	ID           uint
	Name         string
	Timestamp    time.Time
	ImportStatus string
}

An OptOutFile is a basic file representation that can be stored in a database.

type OptOutFileHandler

type OptOutFileHandler interface {
	// Load opt out files from the given path.
	//
	// Return a list of metadata parsed from valid filenames,
	// and the number of files skipped due to unknown filenames.
	LoadOptOutFiles(path string) (suppressList *[]*OptOutFilenameMetadata, skipped int, err error)
	// Cleanup any opt out files that were successfully imported, and handle
	// any files that failed to be imported.
	CleanupOptOutFiles(suppressList []*OptOutFilenameMetadata) error
	// Open a given opt out file, specified by the metadata struct.
	OpenFile(metadata *OptOutFilenameMetadata) (*bufio.Scanner, func(), error)
}

File handlers can load opt out files from a given source and can optionally clean them up afterwards. This interface allows us to implement file loading from multiple sources, including local directories and AWS S3.

type OptOutFilenameMetadata

type OptOutFilenameMetadata struct {
	Name         string
	Timestamp    time.Time
	FilePath     string
	Imported     bool
	DeliveryDate time.Time
	FileID       uint
}

OptOutFilenameMetadata is metadata information parsed from the filename.

func ParseMetadata

func ParseMetadata(filename string) (OptOutFilenameMetadata, error)

func (OptOutFilenameMetadata) String

func (m OptOutFilenameMetadata) String() string

type OptOutRecord

type OptOutRecord struct {
	ID                  uint
	FileID              uint
	MBI                 string
	SourceCode          string
	EffectiveDt         time.Time
	PrefIndicator       string
	SAMHSASourceCode    string
	SAMHSAEffectiveDt   time.Time
	SAMHSAPrefIndicator string
	ACOCMSID            string
	BeneficiaryLinkKey  int
}

An OptOutRecord represents a single record parsed from an opt out file.

func ParseRecord

func ParseRecord(metadata *OptOutFilenameMetadata, b []byte) (*OptOutRecord, error)

type S3FileHandler

type S3FileHandler struct {
	Logger logrus.FieldLogger
	// Optional S3 endpoint to use for connection.
	Endpoint string
	// Optional role to assume when connecting to S3.
	AssumeRoleArn string
	// AWS session, created once and cached here.
	Session *session.Session
}

S3FileHandler manages files located on AWS S3.

func (*S3FileHandler) CleanupOptOutFiles

func (handler *S3FileHandler) CleanupOptOutFiles(suppresslist []*OptOutFilenameMetadata) error

func (*S3FileHandler) Delete

func (handler *S3FileHandler) Delete(filePath string) error

func (*S3FileHandler) Errorf

func (handler *S3FileHandler) Errorf(format string, rest ...interface{})

func (*S3FileHandler) Infof

func (handler *S3FileHandler) Infof(format string, rest ...interface{})

func (*S3FileHandler) ListFiles

func (handler *S3FileHandler) ListFiles(bucket, prefix string) (objects []*s3.Object, err error)

func (*S3FileHandler) LoadOptOutFiles

func (handler *S3FileHandler) LoadOptOutFiles(path string) (suppressList *[]*OptOutFilenameMetadata, skipped int, err error)

func (*S3FileHandler) OpenFile

func (handler *S3FileHandler) OpenFile(metadata *OptOutFilenameMetadata) (*bufio.Scanner, func(), error)

func (*S3FileHandler) OpenFileBytes

func (handler *S3FileHandler) OpenFileBytes(filePath string) ([]byte, error)

func (*S3FileHandler) Warningf

func (handler *S3FileHandler) Warningf(format string, rest ...interface{})

type Saver

type Saver interface {
	SaveFile(optOutFile OptOutFile) (fileID uint, err error)
	SaveOptOutRecord(optOutRecord OptOutRecord) error
	UpdateImportStatus(metadata OptOutFilenameMetadata, status string) error
}

Out opt savers save file metadata and individual records into the database.

Jump to

Keyboard shortcuts

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