Skip to content

Commit bc78720

Browse files
committed
started to implement the company enrich Aviato plugin handler
1 parent 4b03b61 commit bc78720

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright © by Jeff Foley 2017-2025. All rights reserved.
2+
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package aviato
6+
7+
import (
8+
"errors"
9+
"fmt"
10+
"log/slog"
11+
"time"
12+
13+
"github.com/owasp-amass/amass/v4/engine/plugins/support"
14+
et "github.com/owasp-amass/amass/v4/engine/types"
15+
dbt "github.com/owasp-amass/asset-db/types"
16+
oam "github.com/owasp-amass/open-asset-model"
17+
"github.com/owasp-amass/open-asset-model/general"
18+
"github.com/owasp-amass/open-asset-model/org"
19+
)
20+
21+
func (ce *companyEnrich) check(e *et.Event) error {
22+
_, ok := e.Entity.Asset.(*general.Identifier)
23+
if !ok {
24+
return errors.New("failed to extract the Identifier asset")
25+
}
26+
27+
ds := e.Session.Config().GetDataSourceConfig(ce.plugin.name)
28+
if ds == nil || len(ds.Creds) == 0 {
29+
return nil
30+
}
31+
32+
var keys []string
33+
for _, cr := range ds.Creds {
34+
if cr != nil && cr.Apikey != "" {
35+
keys = append(keys, cr.Apikey)
36+
}
37+
}
38+
if len(keys) == 0 {
39+
return nil
40+
}
41+
42+
since, err := support.TTLStartTime(e.Session.Config(),
43+
string(oam.Identifier), string(oam.Organization), ce.plugin.name)
44+
if err != nil {
45+
return err
46+
}
47+
48+
var o *dbt.Entity
49+
if support.AssetMonitoredWithinTTL(e.Session, e.Entity, ce.plugin.source, since) {
50+
o = ce.lookup(e, e.Entity, since)
51+
} else {
52+
o = ce.query(e, e.Entity, keys)
53+
support.MarkAssetMonitored(e.Session, e.Entity, ce.plugin.source)
54+
}
55+
56+
if o != nil {
57+
ce.process(e, e.Entity, o)
58+
}
59+
return nil
60+
}
61+
62+
func (ce *companyEnrich) lookup(e *et.Event, ident *dbt.Entity, since time.Time) *dbt.Entity {
63+
if edges, err := e.Session.Cache().IncomingEdges(ident, since, "id"); err == nil {
64+
for _, edge := range edges {
65+
if tags, err := e.Session.Cache().GetEdgeTags(edge, since, ce.plugin.source.Name); err != nil || len(tags) == 0 {
66+
continue
67+
}
68+
if a, err := e.Session.Cache().FindEntityById(edge.FromEntity.ID); err == nil && a != nil {
69+
if _, ok := a.Asset.(*org.Organization); ok {
70+
return a
71+
}
72+
}
73+
}
74+
}
75+
return nil
76+
}
77+
78+
func (ce *companyEnrich) process(e *et.Event, ident, orgent *dbt.Entity) {
79+
o := orgent.Asset.(*org.Organization)
80+
81+
_ = e.Dispatcher.DispatchEvent(&et.Event{
82+
Name: fmt.Sprintf("%s:%s", o.Name, o.ID),
83+
Entity: orgent,
84+
Session: e.Session,
85+
})
86+
87+
id := ident.Asset.(*general.Identifier)
88+
e.Session.Log().Info("relationship discovered", "from", id.UniqueID, "relation", "id",
89+
"to", o.Name, slog.Group("plugin", "name", ce.plugin.name, "handler", ce.name))
90+
}

engine/plugins/api/aviato/company_search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (cs *companySearch) check(e *et.Event) error {
4343
}
4444

4545
since, err := support.TTLStartTime(e.Session.Config(),
46-
string(oam.Organization), string(oam.Organization), cs.plugin.name)
46+
string(oam.Organization), string(oam.Identifier), cs.plugin.name)
4747
if err != nil {
4848
return err
4949
}

engine/plugins/api/aviato/employees.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (ae *employees) check(e *et.Event) error {
4646
}
4747

4848
since, err := support.TTLStartTime(e.Session.Config(),
49-
string(oam.Identifier), string(oam.Identifier), ae.plugin.name)
49+
string(oam.Identifier), string(oam.Person), ae.plugin.name)
5050
if err != nil {
5151
return err
5252
}

engine/plugins/api/aviato/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ type companySearchResult struct {
5252
} `json:"items"`
5353
}
5454

55+
type companyEnrich struct {
56+
name string
57+
plugin *aviato
58+
}
59+
5560
type companySearch struct {
5661
name string
5762
plugin *aviato

0 commit comments

Comments
 (0)