file

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1000
	MB = 1000 * KB
)

Variables

View Source
var (
	// ErrDocumentNotFound is returned when the doc does not exist in the DB.
	ErrDocumentNotFound = "document not found"
	// ErrObjectNotFound is returned when an object does not exist in Obj storage.
	ErrObjectNotFound = errors.New("object not found")
)

Functions

func NewMiddleware added in v0.4.0

func NewMiddleware(service Service, logger log.Logger) middleware

NewMiddleware creates a new file Middleware.

func RegisterHandlers

func RegisterHandlers(g *echo.Group, service Service, logger log.Logger,
	maxFileSize int,
	requireLogin, optionalLogin, verifyHash, cacheResponse, modifyResponse echo.MiddlewareFunc)

Types

type Archiver added in v0.3.0

type Archiver interface {
	Archive(string, string, io.Reader) error
}

Archiver represents the archiving interface for files.

type CreateFileRequest

type CreateFileRequest struct {
	// contains filtered or unexported fields
}

CreateFileRequest represents a file creation request.

type DynFileScanCfg added in v0.3.0

type DynFileScanCfg struct {
	// Destination path where the sample will be located in the VM.
	DestPath string `json:"dest_path,omitempty" form:"dest_path"`
	// Arguments used to run the sample.
	Arguments string `json:"args,omitempty" form:"args"`
	// Timeout in seconds for how long to keep the VM running.
	Timeout int `json:"timeout,omitempty" form:"timeout"`
	// Country to route traffic through.
	Country string `json:"country,omitempty" form:"country"`
	// Operating System used to run the sample.
	OS string `json:"os,omitempty" form:"os"`
}

DynFileScanCfg represents the config used to detonate a file.

type File

type File struct {
	entity.File
}

File represents the data about a File.

type FileScanCfg added in v0.3.0

type FileScanCfg struct {
	// SHA256 hash of the file.
	SHA256 string `json:"sha256,omitempty"`
	// Represents the dynamic scan configuration plus some option fields.
	FileScanRequest
}

FileScanCfg represents a file scanning config. This map to a 1:1 mapping between the config stored in the main saferwall repo.

type FileScanRequest added in v0.7.0

type FileScanRequest struct {
	// Disable Sandbox
	SkipDetonation bool `json:"skip_detonation,omitempty" form:"skip_detonation"`
	// Dynamic scan config
	DynFileScanCfg `json:"scan_cfg,omitempty"`
}

FileScanRequest represents a File scan request.

type Producer

type Producer interface {
	Produce(string, []byte) error
}

Producer represents event stream message producer interface.

type Repository

type Repository interface {
	// Get returns the file with the specified file ID.
	Get(ctx context.Context, id string, fields []string) (entity.File, error)
	// Count returns the number of files.
	Count(ctx context.Context) (int, error)
	// Exists return true when the doc exists in the DB.
	Exists(ctx context.Context, id string) (bool, error)
	// Query returns the list of files with the given offset and limit.
	Query(ctx context.Context, offset, limit int, fields []string) ([]entity.File, error)
	// Create saves a new file in the storage.
	Create(ctx context.Context, id string, file entity.File) error
	// Update updates the whole file with given ID in the storage.
	Update(ctx context.Context, key string, file entity.File) error
	// Patch patches a sub entry in the file with given ID in the storage.
	Patch(ctx context.Context, key, path string, val interface{}) error
	// Delete removes the file with given ID from the storage.
	Delete(ctx context.Context, id string) error
	// Summary returns a summary of a file scan.
	Summary(ctx context.Context, id string) (interface{}, error)
	// Comments returns the list of comments over a file.
	Comments(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	CountStrings(ctx context.Context, id string, queryString string) (int, error)
	Strings(ctx context.Context, id, queryString string, offset, limit int) (
		interface{}, error)
	// MetaUI returns metadata required for the UI when loading an analysis report.
	MetaUI(ctx context.Context, id string) (interface{}, error)
}

Repository encapsulates the logic to access files from the data source.

func NewRepository

func NewRepository(db *dbcontext.DB, logger log.Logger) Repository

NewRepository creates a new file repository.

type Service

type Service interface {
	Get(ctx context.Context, id string, fields []string) (File, error)
	Count(ctx context.Context) (int, error)
	Exists(ctx context.Context, id string) (bool, error)
	Create(ctx context.Context, input CreateFileRequest) (File, error)
	Update(ctx context.Context, id string, input UpdateFileRequest) (File, error)
	Delete(ctx context.Context, id string) (File, error)
	Query(ctx context.Context, offset, limit int, fields []string) ([]File, error)
	Patch(ctx context.Context, key, path string, val interface{}) error
	Summary(ctx context.Context, id string) (interface{}, error)
	Like(ctx context.Context, id string) error
	Unlike(ctx context.Context, id string) error
	ReScan(ctx context.Context, id string, input FileScanRequest) error
	Comments(ctx context.Context, id string, offset, limit int) (
		[]interface{}, error)
	CountStrings(ctx context.Context, id string, queryString string) (int, error)
	CountComments(ctx context.Context, id string) (int, error)
	Strings(ctx context.Context, id string, queryString string, offset, limit int) (interface{}, error)
	Download(ctx context.Context, id string, zipFile *string) error
	GeneratePresignedURL(ctx context.Context, id string) (string, error)
	MetaUI(ctx context.Context, id string) (interface{}, error)
}

Service encapsulates use case logic for files.

func NewService

func NewService(repo Repository, logger log.Logger,
	updown UploadDownloader, producer Producer, topic, bucket, samplesZipPwd string,
	userSvc user.Service, actSvc activity.Service, commentSvc comment.Service, arch Archiver) Service

NewService creates a new File service.

type UpdateFileRequest

type UpdateFileRequest struct {
	MD5         string                 `json:"md5,omitempty"`
	SHA1        string                 `json:"sha1,omitempty"`
	SHA256      string                 `json:"sha256,omitempty"`
	SHA512      string                 `json:"sha512,omitempty"`
	Ssdeep      string                 `json:"ssdeep,omitempty"`
	TLSH        string                 `json:"tlsh,omitempty"`
	CRC32       string                 `json:"crc32,omitempty"`
	Magic       string                 `json:"magic,omitempty"`
	Size        uint64                 `json:"size,omitempty"`
	Exif        map[string]string      `json:"exif,omitempty"`
	Tags        map[string]interface{} `json:"tags,omitempty"`
	TriD        []string               `json:"trid,omitempty"`
	Packer      []string               `json:"packer,omitempty"`
	Strings     []interface{}          `json:"strings,omitempty"`
	MultiAV     map[string]interface{} `json:"multiav,omitempty"`
	PE          interface{}            `json:"pe,omitempty"`
	Histogram   []int                  `json:"histogram,omitempty"`
	ByteEntropy []int                  `json:"byte_entropy,omitempty"`
	Ml          map[string]interface{} `json:"ml,omitempty"`
	FileType    string                 `json:"filetype,omitempty"`
}

UpdateUserRequest represents a File update request.

type UploadDownloader

type UploadDownloader interface {
	Upload(ctx context.Context, bucket, key string, file io.Reader) error
	Download(ctx context.Context, bucket, key string, file io.Writer) error
	Exists(ctx context.Context, bucket, key string) (bool, error)
	GeneratePresignedURL(ctx context.Context, bucket, key string) (string, error)
}

Jump to

Keyboard shortcuts

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