utils

package
v0.0.0-...-e4e8516 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2016 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KeyForObfuscation = []byte("1sf2324knkfnsfff")

KeyForObfuscation is a crypto key that should only be used for obfuscating data

Functions

func ByteArrayToHexString

func ByteArrayToHexString(byteArray []byte) string

ByteArrayToHexString converter

func ByteArrayToUUIDString

func ByteArrayToUUIDString(byteArray []byte) (UUIDString string, err error)

ByteArrayToUUIDString Given a byte array converts it to a UUID string

func CheckExists

func CheckExists(path string) (doesExist bool)

CheckExists returns true if the file exists, else false

func ConvertYYYYMMDDtoUnix

func ConvertYYYYMMDDtoUnix(input string) int64

ConvertYYYYMMDDtoUnix takes a date in the form 2013-01-20 and converts it to unix time for the database

func DBTimeNow

func DBTimeNow() int64

DBTimeNow returns the current unix time as suitable for the database

func ExpandSha256HexstringToPath

func ExpandSha256HexstringToPath(fileName string) string

ExpandSha256HexstringToPath converts a sha hash like "0a8ce026714e03e72c619307bd598add5f9b639cfd91437cb8d9c847bf9f6894" to "0a/8c/0a8ce026714e03e72c619307bd598add5f9b639cfd91437cb8d9c847bf9f6894" Assumes the string has already been sanity checked to ensure it's a lowercase sha256

func GetDateMatchOperator

func GetDateMatchOperator(jsonOperator string) string

GetDateMatchOperator translates an operator from JSON into SQL

func GetIntMatchOperator

func GetIntMatchOperator(jsonOperator string) string

GetIntMatchOperator translates an operator from JSON into SQL

func GetNullString

func GetNullString(str sql.NullString, defaultStr string) string

GetNullString returns the string value if valid, else the default value

func GetStringMatchOperator

func GetStringMatchOperator(jsonOperator string) string

GetStringMatchOperator translates an operator from JSON into SQL

func GetStringSubstrMatchOperator

func GetStringSubstrMatchOperator(jsonOperator string) string

GetStringSubstrMatchOperator translates an operator from JSON into SQL

func GetSystemIDFromUUID

func GetSystemIDFromUUID(db *gorp.DbMap, SystemUUIDString string, CustomerUUIDString string) (int64, error)

GetSystemIDFromUUID Returns the System ID given the System UUID and CustomerUUID

func Int64ToUnixTimeString

func Int64ToUnixTimeString(secondsFromEpoch int64, dateOnly bool) string

Int64ToUnixTimeString returns a human readable time and date string

func RecordFileSeenOnSystem

func RecordFileSeenOnSystem(db *gorp.DbMap, fileID int64, systemID int64, timeOfEvent int64, filePath string) (err error)

RecordFileSeenOnSystem helper function to update the FileToSystemMap table

Inserts or updates the table to show this file has been seen on this system and provide some meta data

func SendPasswordResetEmail

func SendPasswordResetEmail(db *gorp.DbMap, awsSes AwsSes, emailAddress string, baseURL string) (err error)

SendPasswordResetEmail checks the email is a known user, and if so, send an email to them to allow them to change their password and be logged in

func Sha256File

func Sha256File(f *os.File) (hash []byte, err error)

Sha256File returns the sha256 hash of a file

func SymmetricDecrypt

func SymmetricDecrypt(key []byte, input []byte) ([]byte, error)

SymmetricDecrypt to be used for small symmetric crypto operations

func SymmetricEncrypt

func SymmetricEncrypt(key []byte, plaintext []byte) ([]byte, error)

SymmetricEncrypt to be used for small symmetric crypto operations Taken from: http://stackoverflow.com/questions/18817336/golang-encrypting-a-string-with-aes-and-base64

func UUIDStringToBytes

func UUIDStringToBytes(UUIDString string) ([]byte, error)

UUIDStringToBytes Given a UUID string, converts it to a byte slice for use with the DB

func UploadToS3

func UploadToS3(awsS3 AwsS3, filepath, filename string, f *os.File) (err error)

UploadToS3 uploads the file to the AwsS3 bucket AwsS3 is the credentials filepath is the path inside the S3 bucket to upload to filename is name of the file f is the file handle for the file to upload

func UploadToS3HashPath

func UploadToS3HashPath(awsS3 AwsS3, filename string, f *os.File) (err error)

UploadToS3HashPath given a filename that is a hex encoded hash, create a special directory structure for this file and upload to S3

Types

type AwsS3

type AwsS3 struct {
	BucketName string `json:"bucket_name"`
	AccessKey  string `json:"access_key"`
	SecretKey  string `json:"secret_key"`
	Region     string `json:"region"`
}

AwsS3 is used in config.json files

type AwsSes

type AwsSes struct {
	AccessKey string `json:"access_key"`
	SecretKey string `json:"secret_key"`
	RegionURL string `json:"region_url"`
}

AwsSes is used in config.json files

type PasswordResetEmailData

type PasswordResetEmailData struct {
	DatabaseID int64
	Nonce      []byte
}

PasswordResetEmailData is sent in password reset emails

Jump to

Keyboard shortcuts

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