Add option to skip notification at the very first analysis of an image (#10)

This commit is contained in:
CrazyMax
2019-12-22 16:32:27 +01:00
parent b288673a33
commit 7a8b4677fc
10 changed files with 51 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package db
import (
"bytes"
"encoding/json"
"fmt"
"time"
@@ -53,6 +54,23 @@ func (c *Client) Close() error {
return c.DB.Close()
}
// First checks if a Docker image has ever been analyzed
func (c *Client) First(image registry.Image) (bool, error) {
found := false
err := c.View(func(tx *bolt.Tx) error {
c := tx.Bucket([]byte(bucket)).Cursor()
name := []byte(image.Name())
for k, _ := c.Seek(name); k != nil && bytes.HasPrefix(k, name); k, _ = c.Next() {
found = true
return nil
}
return nil
})
return !found, err
}
// GetManifest returns Docker image manifest
func (c *Client) GetManifest(image registry.Image) (docker.Manifest, error) {
var manifest docker.Manifest