Skip to content

Commit fb14be8

Browse files
committed
updated the framework to use the new asset-db repository interface
1 parent 63a2f09 commit fb14be8

File tree

15 files changed

+78
-68
lines changed

15 files changed

+78
-68
lines changed

engine/api/server/server.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © by Jeff Foley 2017-2025. All rights reserved.
1+
// Copyright © by Jeff Foley 2017-2026. All rights reserved.
22
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
33
// SPDX-License-Identifier: Apache-2.0
44

@@ -184,8 +184,11 @@ func (s *Server) PutAsset(ctx context.Context, sess et.Session, asset oam.Asset)
184184
return "", err
185185
}
186186

187-
entity, err := sess.DB().FindOneEntityByContent(ctx, asset.AssetType(), time.Time{}, filter)
188-
if err != nil {
187+
var entity *dbt.Entity
188+
ents, err := sess.DB().FindEntitiesByContent(ctx, asset.AssetType(), time.Time{}, 1, filter)
189+
if err == nil {
190+
entity = ents[0]
191+
} else {
189192
entity, err = sess.DB().CreateAsset(ctx, asset)
190193
if err != nil {
191194
return entity.ID, err

engine/plugins/dns/plugin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,13 @@ func (d *dnsPlugin) lookupWithinTTL(session et.Session, name string, atype oam.A
181181
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
182182
defer cancel()
183183

184-
entity, err := session.DB().FindOneEntityByContent(ctx, oam.FQDN, time.Time{}, dbt.ContentFilters{
184+
ents, err := session.DB().FindEntitiesByContent(ctx, oam.FQDN, time.Time{}, 1, dbt.ContentFilters{
185185
"name": name,
186186
})
187-
if err != nil || entity == nil {
187+
if err != nil {
188188
return results
189189
}
190+
entity := ents[0]
190191

191192
if edges, err := session.DB().OutgoingEdges(ctx, entity, since, "dns_record"); err == nil && len(edges) > 0 {
192193
for _, edge := range edges {

engine/plugins/dns/subs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,13 @@ func (d *dnsSubs) lookup(e *et.Event, subdomain string, since time.Time) []*relS
164164
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
165165
defer cancel()
166166

167-
fqdn, err := e.Session.DB().FindOneEntityByContent(ctx, oam.FQDN, time.Time{}, dbt.ContentFilters{
167+
ents, err := e.Session.DB().FindEntitiesByContent(ctx, oam.FQDN, time.Time{}, 1, dbt.ContentFilters{
168168
"name": subdomain,
169169
})
170-
if err != nil || fqdn == nil {
170+
if err != nil {
171171
return alias
172172
}
173+
fqdn := ents[0]
173174

174175
n := fqdn.Asset.Key()
175176
// Check for NS records within the since period

engine/plugins/horizontals/contact.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © by Jeff Foley 2017-2025. All rights reserved.
1+
// Copyright © by Jeff Foley 2017-2026. All rights reserved.
22
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
33
// SPDX-License-Identifier: Apache-2.0
44

engine/plugins/horizontals/fqdn.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © by Jeff Foley 2017-2025. All rights reserved.
1+
// Copyright © by Jeff Foley 2017-2026. All rights reserved.
22
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
33
// SPDX-License-Identifier: Apache-2.0
44

@@ -88,9 +88,9 @@ func (h *horfqdn) check(e *et.Event) error {
8888

8989
var assets []*dbt.Entity
9090
for _, im := range impacted {
91-
if a, err := e.Session.DB().FindOneEntityByContent(ctx,
92-
im.Asset.AssetType(), since, assetToContentFilters(im.Asset)); err == nil && a != nil {
93-
assets = append(assets, a)
91+
if ents, err := e.Session.DB().FindEntitiesByContent(ctx,
92+
im.Asset.AssetType(), since, 1, assetToContentFilters(im.Asset)); err == nil {
93+
assets = append(assets, ents[0])
9494
} else if n := h.store(e, im.Asset); n != nil {
9595
assets = append(assets, n)
9696
}

engine/plugins/horizontals/plugin.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ func (h *horizPlugin) addAssociatedRelationship(e *et.Event, since time.Time, as
108108
}
109109

110110
if match, result := e.Session.Scope().IsAssetInScope(impacted.Asset, conf); result >= conf && match != nil {
111-
if a, err := e.Session.DB().FindOneEntityByContent(ctx,
112-
match.AssetType(), since, assetToContentFilters(match)); err == nil && a != nil {
113-
for _, assoc2 := range e.Session.Scope().AssetsWithAssociation(e.Session.DB(), a) {
111+
if ents, err := e.Session.DB().FindEntitiesByContent(ctx,
112+
match.AssetType(), since, 1, assetToContentFilters(match)); err == nil {
113+
for _, assoc2 := range e.Session.Scope().AssetsWithAssociation(e.Session.DB(), ents[0]) {
114114
h.makeAssocRelationshipEntries(e, assoc.Match, assoc2)
115115
}
116116
}
@@ -185,9 +185,11 @@ func (h *horizPlugin) process(e *et.Event, since time.Time, assets []*dbt.Entity
185185
h.sweepAroundIPs(ctx, e, asset, since)
186186
//h.sweepNetblock(e, v, src)
187187
case *oamreg.IPNetRecord:
188-
if a, err := e.Session.DB().FindOneEntityByContent(ctx, oam.Netblock, since, dbt.ContentFilters{
188+
if ents, err := e.Session.DB().FindEntitiesByContent(ctx, oam.Netblock, since, 1, dbt.ContentFilters{
189189
"cidr": v.CIDR.String(),
190-
}); err == nil && a != nil {
190+
}); err == nil {
191+
a := ents[0]
192+
191193
if _, ok := a.Asset.(*oamnet.Netblock); ok {
192194
h.ipPTRTargetsInScope(ctx, e, a, since)
193195
h.sweepAroundIPs(ctx, e, a, since)
@@ -222,10 +224,10 @@ func (h *horizPlugin) ipPTRTargetsInScope(ctx context.Context, e *et.Event, nb *
222224
continue
223225
}
224226

225-
if a, err := e.Session.DB().FindOneEntityByContent(ctx, oam.FQDN, since, dbt.ContentFilters{
227+
if ents, err := e.Session.DB().FindEntitiesByContent(ctx, oam.FQDN, since, 1, dbt.ContentFilters{
226228
"name": utils.RemoveLastDot(reverse),
227-
}); err == nil && a != nil {
228-
if edges, err := e.Session.DB().OutgoingEdges(ctx, a, since, "dns_record"); err == nil && len(edges) > 0 {
229+
}); err == nil {
230+
if edges, err := e.Session.DB().OutgoingEdges(ctx, ents[0], since, "dns_record"); err == nil && len(edges) > 0 {
229231
for _, edge := range edges {
230232
if rel, ok := edge.Relation.(*oamdns.BasicDNSRelation); !ok || rel.Header.RRType != 12 {
231233
continue

engine/plugins/support/database.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ func SourceToAssetsWithinTTL(session et.Session, name, atype string, src *et.Sou
3333

3434
switch atype {
3535
case string(oam.FQDN):
36-
root, err := session.DB().FindOneEntityByContent(ctx, oam.FQDN, since, dbt.ContentFilters{
36+
ents, err := session.DB().FindEntitiesByContent(ctx, oam.FQDN, since, 1, dbt.ContentFilters{
3737
"name": name,
3838
})
39-
if err != nil || root == nil {
39+
if err != nil {
4040
return nil
4141
}
4242

43-
entities, _ = db.FindByFQDNScope(ctx, session.DB(), root, since)
43+
entities, _ = db.FindByFQDNScope(ctx, session.DB(), ents[0], since)
4444
case string(oam.Identifier):
4545
if parts := strings.Split(name, ":"); len(parts) == 2 {
46-
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.Identifier, since, dbt.ContentFilters{
46+
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.Identifier, since, 1, dbt.ContentFilters{
4747
"unique_id": name,
4848
})
4949
}
@@ -53,7 +53,7 @@ func SourceToAssetsWithinTTL(session et.Session, name, atype string, src *et.Sou
5353
return nil
5454
}
5555

56-
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.AutnumRecord, since, dbt.ContentFilters{
56+
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.AutnumRecord, since, 1, dbt.ContentFilters{
5757
"number": num,
5858
})
5959
case string(oam.IPNetRecord):
@@ -62,11 +62,11 @@ func SourceToAssetsWithinTTL(session et.Session, name, atype string, src *et.Sou
6262
return nil
6363
}
6464

65-
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.IPNetRecord, since, dbt.ContentFilters{
65+
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.IPNetRecord, since, 0, dbt.ContentFilters{
6666
"cidr": prefix,
6767
})
6868
case string(oam.Service):
69-
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.Service, since, dbt.ContentFilters{
69+
entities, _ = session.DB().FindEntitiesByContent(ctx, oam.Service, since, 1, dbt.ContentFilters{
7070
"unique_id": name,
7171
})
7272
}

engine/plugins/support/org/match.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func orgsWithSameNames(session et.Session, names []string) ([]*dbt.Entity, error
158158
name := strings.ToLower(n)
159159

160160
// check for known organization name identifiers
161-
if assets, err := session.DB().FindEntitiesByContent(ctx, oam.Identifier, time.Time{}, dbt.ContentFilters{
161+
if assets, err := session.DB().FindEntitiesByContent(ctx, oam.Identifier, time.Time{}, 0, dbt.ContentFilters{
162162
"unique_id": fmt.Sprintf("%s:%s", general.OrganizationName, name),
163163
}); err == nil {
164164
for _, a := range assets {
@@ -169,7 +169,7 @@ func orgsWithSameNames(session et.Session, names []string) ([]*dbt.Entity, error
169169
}
170170

171171
// check for known legal name identifiers
172-
if assets, err := session.DB().FindEntitiesByContent(ctx, oam.Identifier, time.Time{}, dbt.ContentFilters{
172+
if assets, err := session.DB().FindEntitiesByContent(ctx, oam.Identifier, time.Time{}, 0, dbt.ContentFilters{
173173
"unique_id": fmt.Sprintf("%s:%s", general.LegalName, name),
174174
}); err == nil {
175175
for _, a := range assets {

engine/plugins/support/support.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func IPAddressSweep(e *et.Event, addr *oamnet.IPAddress, src *et.Source, size in
174174
defer cancel()
175175

176176
// ensure we do not work on an IP address that was processed previously
177-
_, err := e.Session.DB().FindEntitiesByContent(ctx, oam.IPAddress, time.Time{}, dbt.ContentFilters{
177+
_, err := e.Session.DB().FindEntitiesByContent(ctx, oam.IPAddress, e.Session.StartTime(), 1, dbt.ContentFilters{
178178
"address": addr.Address.String(),
179179
})
180180
if err == nil {
@@ -211,14 +211,14 @@ func IsCNAME(session et.Session, name *oamdns.FQDN) (*oamdns.FQDN, bool) {
211211
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
212212
defer cancel()
213213

214-
fqdn, err := session.DB().FindOneEntityByContent(ctx, oam.FQDN, time.Time{}, dbt.ContentFilters{
214+
ents, err := session.DB().FindEntitiesByContent(ctx, oam.FQDN, time.Time{}, 1, dbt.ContentFilters{
215215
"name": name.Name,
216216
})
217-
if err != nil || fqdn == nil {
217+
if err != nil {
218218
return nil, false
219219
}
220220

221-
if edges, err := session.DB().OutgoingEdges(ctx, fqdn, time.Time{}, "dns_record"); err == nil && len(edges) > 0 {
221+
if edges, err := session.DB().OutgoingEdges(ctx, ents[0], time.Time{}, "dns_record"); err == nil && len(edges) > 0 {
222222
for _, edge := range edges {
223223
if rec, ok := edge.Relation.(*oamdns.BasicDNSRelation); ok && rec.Header.RRType == 5 {
224224
if to, err := session.DB().FindEntityById(ctx, edge.ToEntity.ID); err == nil {
@@ -236,12 +236,13 @@ func NameIPAddresses(session et.Session, name *oamdns.FQDN) []*oamnet.IPAddress
236236
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
237237
defer cancel()
238238

239-
fqdn, err := session.DB().FindOneEntityByContent(ctx, oam.FQDN, time.Time{}, dbt.ContentFilters{
239+
ents, err := session.DB().FindEntitiesByContent(ctx, oam.FQDN, time.Time{}, 1, dbt.ContentFilters{
240240
"name": name.Name,
241241
})
242-
if err != nil || fqdn == nil {
242+
if err != nil {
243243
return nil
244244
}
245+
fqdn := ents[0]
245246

246247
since, err := TTLStartTime(session.Config(), string(oam.FQDN), string(oam.IPAddress), "")
247248
if err != nil {

engine/sessions/scope/assoc.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © by Jeff Foley 2017-2025. All rights reserved.
1+
// Copyright © by Jeff Foley 2017-2026. All rights reserved.
22
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
33
// SPDX-License-Identifier: Apache-2.0
44

@@ -99,16 +99,16 @@ func (s *Scope) reviewAndUpdate(c repository.Repository, req *Association) []*db
9999
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
100100
defer cancel()
101101

102-
if drs, err := c.FindEntitiesByType(ctx, oam.DomainRecord, s.startTime); err == nil && len(drs) > 0 {
102+
if drs, err := c.FindEntitiesByType(ctx, oam.DomainRecord, s.startTime, 0); err == nil && len(drs) > 0 {
103103
assocs = append(assocs, drs...)
104104
}
105-
if iprecs, err := c.FindEntitiesByType(ctx, oam.IPNetRecord, s.startTime); err == nil && len(iprecs) > 0 {
105+
if iprecs, err := c.FindEntitiesByType(ctx, oam.IPNetRecord, s.startTime, 0); err == nil && len(iprecs) > 0 {
106106
assocs = append(assocs, iprecs...)
107107
}
108-
if autnums, err := c.FindEntitiesByType(ctx, oam.AutnumRecord, s.startTime); err == nil && len(autnums) > 0 {
108+
if autnums, err := c.FindEntitiesByType(ctx, oam.AutnumRecord, s.startTime, 0); err == nil && len(autnums) > 0 {
109109
assocs = append(assocs, autnums...)
110110
}
111-
if certs, err := c.FindEntitiesByType(ctx, oam.TLSCertificate, s.startTime); err == nil && len(certs) > 0 {
111+
if certs, err := c.FindEntitiesByType(ctx, oam.TLSCertificate, s.startTime, 0); err == nil && len(certs) > 0 {
112112
assocs = append(assocs, certs...)
113113
}
114114

@@ -388,12 +388,13 @@ func (s *Scope) IsAddressInScope(c repository.Repository, ip *oamnet.IPAddress)
388388
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
389389
defer cancel()
390390

391-
addr, err := c.FindOneEntityByContent(ctx, oam.IPAddress, s.startTime, dbt.ContentFilters{
391+
ents, err := c.FindEntitiesByContent(ctx, oam.IPAddress, s.startTime, 1, dbt.ContentFilters{
392392
"address": ip.Address.String(),
393393
})
394394
if err != nil {
395395
return false
396396
}
397+
addr := ents[0]
397398

398399
rtype := 1
399400
if ip.Type == "IPv6" {

0 commit comments

Comments
 (0)