Skip to content

Commit

Permalink
Use image-analyzer library (#196)
Browse files Browse the repository at this point in the history
* Use image-analyzer library
  • Loading branch information
damejeras authored Nov 30, 2023
1 parent b11a684 commit 4cbac0e
Show file tree
Hide file tree
Showing 78 changed files with 44 additions and 8,669 deletions.
19 changes: 5 additions & 14 deletions blobscache/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,15 @@ package blobscache
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"time"

ia "github.com/castai/image-analyzer"
json "github.com/json-iterator/go"
)

var (
ErrCacheNotFound = errors.New("blob not found in cache")
)

type Client interface {
PutBlob(ctx context.Context, key string, blob []byte) error
GetBlob(ctx context.Context, key string) ([]byte, error)
}

func NewRemoteBlobsCacheClient(serverURL string) Client {
func NewRemoteBlobsCacheClient(serverURL string) ia.CacheClient {
return &remoteBlobsCache{
url: serverURL,
client: &http.Client{
Expand Down Expand Up @@ -75,7 +66,7 @@ func (c *remoteBlobsCache) GetBlob(ctx context.Context, key string) ([]byte, err
defer resp.Body.Close()
if st := resp.StatusCode; st != http.StatusOK {
if st == http.StatusNotFound {
return nil, ErrCacheNotFound
return nil, ia.ErrCacheNotFound
}
return nil, fmt.Errorf("put blob failed, response status=%d", st)
}
Expand All @@ -87,7 +78,7 @@ func (c *remoteBlobsCache) GetBlob(ctx context.Context, key string) ([]byte, err
return res.Blob, nil
}

func NewMockBlobsCacheClient() Client {
func NewMockBlobsCacheClient() ia.CacheClient {
return &mockBlobsCacheClient{}
}

Expand All @@ -99,5 +90,5 @@ func (m mockBlobsCacheClient) PutBlob(ctx context.Context, key string, blob []by
}

func (m mockBlobsCacheClient) GetBlob(ctx context.Context, key string) ([]byte, error) {
return nil, ErrCacheNotFound
return nil, ia.ErrCacheNotFound
}
4 changes: 2 additions & 2 deletions blobscache/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mock
import (
"context"

"github.com/castai/kvisor/blobscache"
ia "github.com/castai/image-analyzer"
)

type MockClient struct{}
Expand All @@ -13,5 +13,5 @@ func (m MockClient) PutBlob(ctx context.Context, key string, blob []byte) error
}

func (m MockClient) GetBlob(ctx context.Context, key string) ([]byte, error) {
return nil, blobscache.ErrCacheNotFound
return nil, ia.ErrCacheNotFound
}
3 changes: 2 additions & 1 deletion blobscache/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

ia "github.com/castai/image-analyzer"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)
Expand All @@ -31,7 +32,7 @@ func TestBlobsCacheServer(t *testing.T) {
// Wait unti server is ready.
r.Eventually(func() bool {
_, err := client.GetBlob(ctx, "noop")
return errors.Is(err, ErrCacheNotFound)
return errors.Is(err, ia.ErrCacheNotFound)
}, 3*time.Second, 10*time.Millisecond)

blob := []byte(`{"some": "json"}`)
Expand Down
230 changes: 0 additions & 230 deletions cmd/imgcollector/analyzer/pkg/apk/apk.go

This file was deleted.

Loading

0 comments on commit 4cbac0e

Please sign in to comment.