From 8764805831c57a6094bb9560b29839bfdf93e33a Mon Sep 17 00:00:00 2001 From: Ryan Morton Date: Tue, 13 Jun 2023 09:22:44 -0400 Subject: [PATCH] fix: Make AssetDB service public --- assetdb.go | 18 +++++++++--------- assetdb_test.go | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/assetdb.go b/assetdb.go index 1f46b13..326e6fa 100644 --- a/assetdb.go +++ b/assetdb.go @@ -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, } } @@ -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) } @@ -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...) } diff --git a/assetdb_test.go b/assetdb_test.go index f993b69..80c6f40 100644 --- a/assetdb_test.go +++ b/assetdb_test.go @@ -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, } @@ -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, } @@ -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, } @@ -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, } @@ -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, }