Skip to content

Commit

Permalink
started to implement the new Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Nov 15, 2024
1 parent 61a3735 commit ac0327f
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 263 deletions.
135 changes: 125 additions & 10 deletions engine/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,133 @@
package cache

import (
"errors"
"sync"
"time"

assetdb "github.com/owasp-amass/asset-db"

Check failure on line 12 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Coverage

missing go.sum entry for module providing package github.com/owasp-amass/asset-db (imported by github.com/owasp-amass/amass/v4/cmd/oam_assoc); to add:

Check failure on line 12 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 1.23.1)

missing go.sum entry for module providing package github.com/owasp-amass/asset-db (imported by github.com/owasp-amass/amass/v4/cmd/oam_assoc); to add:
"github.com/owasp-amass/asset-db/repository"

Check failure on line 13 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Coverage

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/repository (imported by github.com/owasp-amass/amass/v4/engine/cache); to add:

Check failure on line 13 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 1.23.1)

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/repository (imported by github.com/owasp-amass/amass/v4/engine/cache); to add:
"github.com/owasp-amass/asset-db/repository/sqlrepo"

Check failure on line 14 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Coverage

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/repository/sqlrepo (imported by github.com/owasp-amass/amass/v4/engine/cache); to add:

Check failure on line 14 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 1.23.1)

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/repository/sqlrepo (imported by github.com/owasp-amass/amass/v4/engine/cache); to add:
"github.com/owasp-amass/asset-db/types"

Check failure on line 15 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Coverage

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/types (imported by github.com/owasp-amass/amass/v4/cmd/oam_assoc); to add:

Check failure on line 15 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, 1.23.1)

missing go.sum entry for module providing package github.com/owasp-amass/asset-db/types (imported by github.com/owasp-amass/amass/v4/cmd/oam_assoc); to add:
oam "github.com/owasp-amass/open-asset-model"
)

type Cache interface {
GetAsset(a oam.Asset) (*types.Asset, bool)
GetAssetsByType(t oam.AssetType) ([]*types.Asset, bool)
SetAsset(a *types.Asset)
GetRelations(r *types.Relation) ([]*types.Relation, bool)
GetRelationsByType(rtype string) ([]*types.Relation, bool)
GetIncomingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, bool)
GetOutgoingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, bool)
SetRelation(r *types.Relation)
Close()
type Cache struct {
sync.Mutex
cache repository.Repository
db repository.Repository
}

func New(database repository.Repository) (repository.Repository, error) {
if c := assetdb.New(sqlrepo.SQLiteMemory, ""); c != nil {
return &Cache{
cache: c,
db: database,
}, nil
}
return nil, errors.New("failed to create the cache repository")
}

// Close implements the Repository interface.
func (c *Cache) Close() error {
c.Lock()
defer c.Unlock()

if c.cache != nil {
if err := c.cache.Close(); err != nil {
return err
}
}

return nil
}

// GetDBType implements the Repository interface.
func (c *Cache) GetDBType() string {
return c.db.GetDBType()
}

// CreateEntity implements the Repository interface.
func (c *Cache) CreateEntity(asset oam.Asset) (*types.Entity, error) {

}

Check failure on line 57 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint (macos-latest, 1.23.1)

missing return (typecheck)

// UpdateEntityLastSeen implements the Repository interface.
func (c *Cache) UpdateEntityLastSeen(id string) error {

}

Check failure on line 62 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint (macos-latest, 1.23.1)

missing return (typecheck)

// DeleteEntity implements the Repository interface.
func (c *Cache) DeleteEntity(id string) error {

}

Check failure on line 67 in engine/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint (macos-latest, 1.23.1)

missing return (typecheck)

// DeleteEdge implements the Repository interface.
func (c *Cache) DeleteEdge(id string) error {

}

// FindEntityById implements the Repository interface.
func (c *Cache) FindEntityById(id string) (*types.Entity, error) {

}

// FindEntityByContent implements the Repository interface.
func (c *Cache) FindEntityByContent(asset oam.Asset, since time.Time) ([]*types.Entity, error) {

}

// FindEntitiesByType implements the Repository interface.
func (c *Cache) FindEntitiesByType(atype oam.AssetType, since time.Time) ([]*types.Entity, error) {

}

// FindEntitiesByScope implements the Repository interface.
func (c *Cache) FindEntitiesByScope(constraints []oam.Asset, since time.Time) ([]*types.Entity, error) {

}

// Link implements the Repository interface.
func (c *Cache) Link(edge *types.Edge) (*types.Edge, error) {

}

// IncomingEdges implements the Repository interface.
func (c *Cache) IncomingEdges(entity *types.Entity, since time.Time, labels ...string) ([]*types.Edge, error) {

}

// OutgoingEdges implements the Repository interface.
func (c *Cache) OutgoingEdges(entity *types.Entity, since time.Time, labels ...string) ([]*types.Edge, error) {

}

// CreateEntityTag implements the Repository interface.
func (c *Cache) CreateEntityTag(entity *types.Entity, property oam.Property) (*types.EntityTag, error) {

}

// GetEntityTags implements the Repository interface.
func (c *Cache) GetEntityTags(entity *types.Entity, since time.Time, names ...string) ([]*types.EntityTag, error) {

}

// DeleteEntityTag implements the Repository interface.
func (c *Cache) DeleteEntityTag(id string) error {

}

// CreateEdgeTag implements the Repository interface.
func (c *Cache) CreateEdgeTag(edge *types.Edge, property oam.Property) (*types.EdgeTag, error) {

}

// GetEdgeTags implements the Repository interface.
func (c *Cache) GetEdgeTags(edge *types.Edge, since time.Time, names ...string) ([]*types.EdgeTag, error) {

}

// DeleteEdgeTag implements the Repository interface.
func (c *Cache) DeleteEdgeTag(id string) error {

}
251 changes: 0 additions & 251 deletions engine/cache/oam_cache.go

This file was deleted.

Loading

0 comments on commit ac0327f

Please sign in to comment.