Skip to content

Commit

Permalink
fix: Make AssetDB service public
Browse files Browse the repository at this point in the history
  • Loading branch information
rynmrtn committed Jun 13, 2023
1 parent 03c5dc3 commit 8764805
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions assetdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
oam "github.com/owasp-amass/open-asset-model"
)

// assetDB represents the asset database service.
type assetDB struct {
// AssetDB represents the asset database service.
type AssetDB struct {
repository repository.Repository
}

// New creates a new assetDB instance.
// It initializes the asset database with the specified database type and DSN.
func New(dbType repository.DBType, dsn string) *assetDB {
func New(dbType repository.DBType, dsn string) *AssetDB {
database := repository.New(dbType, dsn)
return &assetDB{
return &AssetDB{
repository: database,
}
}
Expand All @@ -25,7 +25,7 @@ func New(dbType repository.DBType, dsn string) *assetDB {
// If source is nil, the discovered asset will be created and relation will be ignored
// If source and relation are provided, the asset is created and linked to the source asset using the specified relation.
// It returns the newly created asset and an error, if any.
func (as *assetDB) Create(source *types.Asset, relation *string, discovered oam.Asset) (*types.Asset, error) {
func (as *AssetDB) Create(source *types.Asset, relation *string, discovered oam.Asset) (*types.Asset, error) {
if source == nil || relation == nil {
return as.repository.CreateAsset(discovered)
}
Expand All @@ -45,24 +45,24 @@ func (as *assetDB) Create(source *types.Asset, relation *string, discovered oam.

// FindByContent finds assets in the database based on their content.
// It returns a list of matching assets and an error, if any.
func (as *assetDB) FindByContent(asset oam.Asset) ([]*types.Asset, error) {
func (as *AssetDB) FindByContent(asset oam.Asset) ([]*types.Asset, error) {
return as.repository.FindAssetByContent(asset)
}

// FindById finds an asset in the database by its ID.
// It returns the matching asset and an error, if any.
func (as *assetDB) FindById(id string) (*types.Asset, error) {
func (as *AssetDB) FindById(id string) (*types.Asset, error) {
return as.repository.FindAssetById(id)
}

// IncomingRelations finds all relations pointing to `asset“ for the specified `relationTypes`, if any.
// If no `relationTypes` are specified, all incoming relations are returned.
func (as *assetDB) IncomingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, error) {
func (as *AssetDB) IncomingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, error) {
return as.repository.IncomingRelations(asset, relationTypes...)
}

// OutgoingRelations finds all relations from `asset“ to another asset for the specified `relationTypes`, if any.
// If no `relationTypes` are specified, all outgoing relations are returned.
func (as *assetDB) OutgoingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, error) {
func (as *AssetDB) OutgoingRelations(asset *types.Asset, relationTypes ...string) ([]*types.Relation, error) {
return as.repository.OutgoingRelations(asset, relationTypes...)
}
10 changes: 5 additions & 5 deletions assetdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestAssetDB(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mockAssetDB := new(mockAssetDB)
adb := assetDB{
adb := AssetDB{
repository: mockAssetDB,
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func TestAssetDB(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mockAssetDB := new(mockAssetDB)
adb := assetDB{
adb := AssetDB{
repository: mockAssetDB,
}

Expand Down Expand Up @@ -153,7 +153,7 @@ func TestAssetDB(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mockAssetDB := new(mockAssetDB)
adb := assetDB{
adb := AssetDB{
repository: mockAssetDB,
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func TestAssetDB(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mockAssetDB := new(mockAssetDB)
adb := assetDB{
adb := AssetDB{
repository: mockAssetDB,
}

Expand Down Expand Up @@ -265,7 +265,7 @@ func TestAssetDB(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mockAssetDB := new(mockAssetDB)
adb := assetDB{
adb := AssetDB{
repository: mockAssetDB,
}

Expand Down

0 comments on commit 8764805

Please sign in to comment.