Documentation
¶
Index ¶
- Constants
- Variables
- func ClassifyWithPlugins(services []ClassifierService, filename, ext string) string
- func EnrichWithPlugins(services []MetadataService, sample models.FileSample) models.FileMetadata
- func SampleFromFile(file models.File) models.FileSample
- type ClassifierPluginRPC
- type ClassifierRPCClient
- type ClassifierRPCServer
- type ClassifierService
- type Manager
- func (m *Manager) GetInfo(name string) (*Manifest, error)
- func (m *Manager) GetPluginDir() string
- func (m *Manager) Install(sourcePath string) (*Manifest, error)
- func (m *Manager) List() ([]Manifest, error)
- func (m *Manager) LoadAllClassifiers() ([]ClassifierService, []models.Rule, func())
- func (m *Manager) LoadAllMetadata() ([]MetadataService, func())
- func (m *Manager) LoadClassifier(name string) (ClassifierService, func(), error)
- func (m *Manager) LoadMetadata(name string) (MetadataService, func(), error)
- func (m *Manager) Remove(name string) error
- type Manifest
- type MetadataPluginRPC
- type MetadataRPCClient
- type MetadataRPCServer
- type MetadataService
Constants ¶
const MetadataCapability = "metadata"
MetadataCapability is the manifest capability string that enables the metadata protocol. Plugins declaring it must serve the "metadata" plugin from their Serve config.
Variables ¶
var HandshakeConfig = hplugin.HandshakeConfig{
ProtocolVersion: 2,
MagicCookieKey: "CHEST_PLUGIN",
MagicCookieValue: "CHEST_IN_A_CHEST",
}
HandshakeConfig ensures plugin and host agree on protocol. ProtocolVersion 2 adds the metadata capability (Inspect RPC); plugins built against protocol 1 must be recompiled.
var MetadataPluginMap = map[string]hplugin.Plugin{ "metadata": &MetadataPluginRPC{}, }
MetadataPluginMap is the plugin-map entry hosts and plugins merge into their Serve config to expose the metadata protocol alongside the classifier protocol.
var PluginMap = map[string]hplugin.Plugin{ "classifier": &ClassifierPluginRPC{}, }
PluginMap maps plugin types to implementations
Functions ¶
func ClassifyWithPlugins ¶
func ClassifyWithPlugins(services []ClassifierService, filename, ext string) string
ClassifyWithPlugins tries each loaded plugin service to classify a file. Returns the first non-empty, non-"Other" result, or empty string if no plugin matched.
func EnrichWithPlugins ¶ added in v0.4.1
func EnrichWithPlugins(services []MetadataService, sample models.FileSample) models.FileMetadata
EnrichWithPlugins runs a file sample through each loaded metadata plugin in order, merging the first non-empty value produced for every field. Fields set by an earlier plugin win; later plugins only fill gaps. The returned models.FileMetadata reports only values that came from plugins, so callers can distinguish plugin output from built-in detection. Plugin errors are ignored — enrichment is best-effort by design.
func SampleFromFile ¶ added in v0.4.1
func SampleFromFile(file models.File) models.FileSample
SampleFromFile builds a bounded models.FileSample for a scanned file, reading the first pluginSampleHeadBytes and last pluginSampleTailBytes of file content so plugins can sniff signatures. Read errors are non-fatal: the sample is returned without content bytes if the file cannot be read.
Types ¶
type ClassifierPluginRPC ¶
type ClassifierPluginRPC struct {
Impl ClassifierService
}
type ClassifierRPCClient ¶
type ClassifierRPCClient struct {
// contains filtered or unexported fields
}
RPC Server/Client implementation
func (*ClassifierRPCClient) Classify ¶
func (c *ClassifierRPCClient) Classify(filename string, ext string) (string, error)
func (*ClassifierRPCClient) GetCustomRules ¶
func (c *ClassifierRPCClient) GetCustomRules() ([]models.Rule, error)
func (*ClassifierRPCClient) GetInfo ¶
func (c *ClassifierRPCClient) GetInfo() (Manifest, error)
type ClassifierRPCServer ¶
type ClassifierRPCServer struct {
Impl ClassifierService
}
func (*ClassifierRPCServer) Classify ¶
func (s *ClassifierRPCServer) Classify(args []string, resp *string) error
func (*ClassifierRPCServer) GetCustomRules ¶
func (s *ClassifierRPCServer) GetCustomRules(args interface{}, resp *[]models.Rule) error
func (*ClassifierRPCServer) GetInfo ¶
func (s *ClassifierRPCServer) GetInfo(args interface{}, resp *Manifest) error
type ClassifierService ¶
type ClassifierService interface {
GetInfo() (Manifest, error)
Classify(filename string, ext string) (string, error)
GetCustomRules() ([]models.Rule, error)
}
ClassifierService is the interface exposed by plugins
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager discovers and manages local plugins
func NewManager ¶
NewManager creates a plugin manager pointing to target directory (default ~/.chest/plugins)
func (*Manager) GetPluginDir ¶
GetPluginDir returns plugin storage folder
func (*Manager) Install ¶
Install installs a plugin from a local directory containing manifest.toml or manifest.json
func (*Manager) List ¶
List installed plugins by reading manifest.toml or manifest.json in each plugin folder
func (*Manager) LoadAllClassifiers ¶
func (m *Manager) LoadAllClassifiers() ([]ClassifierService, []models.Rule, func())
LoadAllClassifiers discovers all installed plugins with "classifier" capability, spawns each one, collects custom rules via GetCustomRules(), and returns:
- services: slice of active ClassifierService instances
- rules: aggregated custom rules from all plugins
- cleanup: function to kill all spawned plugin processes
func (*Manager) LoadAllMetadata ¶ added in v0.4.1
func (m *Manager) LoadAllMetadata() ([]MetadataService, func())
LoadAllMetadata spawns every installed plugin declaring the "metadata" capability and returns ready-to-use services plus a single cleanup that kills all spawned plugin processes. Broken plugins are skipped silently so one bad install never blocks a sort or search run.
func (*Manager) LoadClassifier ¶
func (m *Manager) LoadClassifier(name string) (ClassifierService, func(), error)
LoadClassifier spawns external plugin process and returns client
func (*Manager) LoadMetadata ¶ added in v0.4.1
func (m *Manager) LoadMetadata(name string) (MetadataService, func(), error)
LoadMetadata spawns a single metadata plugin process and returns its client plus a cleanup function that terminates the process.
type Manifest ¶
type Manifest struct {
Name string `json:"name" toml:"name"`
Version string `json:"version" toml:"version"`
Description string `json:"description" toml:"description"`
Author string `json:"author,omitempty" toml:"author,omitempty"`
Capabilities []string `json:"capabilities" toml:"capabilities"` // e.g. ["classifier", "metadata", "preset", "rule"]
Binary string `json:"binary" toml:"binary"` // executable filename
}
Manifest represents plugin metadata stored in manifest.json, manifest.toml, or returned by plugin
type MetadataPluginRPC ¶ added in v0.4.1
type MetadataPluginRPC struct {
Impl MetadataService
}
MetadataPluginRPC adapts MetadataService to the go-plugin machinery.
type MetadataRPCClient ¶ added in v0.4.1
type MetadataRPCClient struct {
// contains filtered or unexported fields
}
MetadataRPCClient is the host-side RPC implementation of MetadataService.
func (*MetadataRPCClient) GetInfo ¶ added in v0.4.1
func (c *MetadataRPCClient) GetInfo() (Manifest, error)
func (*MetadataRPCClient) Inspect ¶ added in v0.4.1
func (c *MetadataRPCClient) Inspect(sample models.FileSample) (models.FileMetadata, error)
type MetadataRPCServer ¶ added in v0.4.1
type MetadataRPCServer struct {
Impl MetadataService
}
MetadataRPCServer is the plugin-side RPC server wrapping a MetadataService.
func (*MetadataRPCServer) GetInfo ¶ added in v0.4.1
func (s *MetadataRPCServer) GetInfo(args interface{}, resp *Manifest) error
func (*MetadataRPCServer) Inspect ¶ added in v0.4.1
func (s *MetadataRPCServer) Inspect(sample models.FileSample, resp *models.FileMetadata) error
type MetadataService ¶ added in v0.4.1
type MetadataService interface {
GetInfo() (Manifest, error)
Inspect(sample models.FileSample) (models.FileMetadata, error)
}
MetadataService is the interface exposed by plugins with the "metadata" capability. GetInfo mirrors ClassifierService.GetInfo so hosts can verify identity over RPC; Inspect enriches a bounded file sample with format, MIME, category, embedded dates and arbitrary metadata fields.