func (db *Database) StoreFileInfo(sample map[string]interface{}) (elastic.IndexResponse, error) {

	if len(db.Plugins) == 0 {
		return elastic.IndexResponse{}, errors.New("Database.Plugins is empty (you must set this field to use this function)")
	}

	// Test connection to ElasticSearch
	err := db.TestConnection()
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to connect to database")
	}

	client, err := elastic.NewSimpleClient(
		elastic.SetURL(db.URL),
		elastic.SetBasicAuth(
			utils.Getopts(db.Username, "MALICE_ELASTICSEARCH_USERNAME", ""),
			utils.Getopts(db.Password, "MALICE_ELASTICSEARCH_PASSWORD", ""),
		),
	)
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to create elasticsearch simple client")
	}

	// NOTE: I am not setting ID because I want to be able to re-scan files with updated signatures in the future
	fInfo := map[string]interface{}{
		// "id":      sample.SHA256,
		"file":      sample,
		"plugins":   db.Plugins,
		"scan_date": time.Now().Format(time.RFC3339Nano),
	}

	newScan, err := client.Index().
		Index(db.Index).
		Type(db.Type).
		OpType("index").
		// Id("1").
		BodyJson(fInfo).
		Do(context.Background())
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to index file info")
	}

	log.WithFields(log.Fields{
		"id":    newScan.Id,
		"index": newScan.Index,
		"type":  newScan.Type,
	}).Debug("indexed sample")

	return *newScan, nil
}
func (db *Database) StoreFileInfo(sample map[string]interface{}) (elastic.IndexResponse, error) {

	if len(db.Plugins) == 0 {
		return elastic.IndexResponse{}, errors.New("Database.Plugins is empty (you must set this field to use this function)")
	}

	// Test connection to ElasticSearch
	err := db.TestConnection()
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to connect to database")
	}

	client, err := elastic.NewSimpleClient(
		elastic.SetURL(db.URL),
		elastic.SetBasicAuth(
			utils.Getopts(db.Username, "MALICE_ELASTICSEARCH_USERNAME", ""),
			utils.Getopts(db.Password, "MALICE_ELASTICSEARCH_PASSWORD", ""),
		),
	)
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to create elasticsearch simple client")
	}

	// NOTE: I am not setting ID because I want to be able to re-scan files with updated signatures in the future
	fInfo := map[string]interface{}{
		// "id":      sample.SHA256,
		"file":      sample,
		"plugins":   db.Plugins,
		"scan_date": time.Now().Format(time.RFC3339Nano),
	}

	newScan, err := client.Index().
		Index(db.Index).
		Type(db.Type).
		OpType("index").
		// Id("1").
		BodyJson(fInfo).
		Do(context.Background())
	if err != nil {
		return elastic.IndexResponse{}, errors.Wrap(err, "failed to index file info")
	}

	log.WithFields(log.Fields{
		"id":    newScan.Id,
		"index": newScan.Index,
		"type":  newScan.Type,
	}).Debug("indexed sample")

	return *newScan, nil
}
// StoreFileInfo inserts initial sample info into database creating a placeholder for it