Skip to content

Commit fea5bc3

Browse files
authored
feat: add VirusTotal Results to API (#92)
* feat: add virustotal results to api * fix: add missing files from commit, fix migration * fix: remove unused vars * cleanup commented out code * fix comments, naming of functions, bulk saving * add newline back to gqlgrn * fix lint errors * fix generated.go being out of sync * fix migration sum * switch to virustotal_results output * update migration to remove url * reorganized code around virus total * resolved conflicts from staging * redo migrations/schema, fix formatting issues * fix migration hash * use devbox to generate files
1 parent e0e42f8 commit fea5bc3

38 files changed

+5334
-238
lines changed

conversion/ent_to_graphql.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type Mod interface {
9999
// goverter:extend TimeToString UIntToInt Int64ToInt
100100
type Version interface {
101101
// goverter:map Edges.Targets Targets
102-
// goverter:ignore Link Mod Dependencies SmlVersion
102+
// goverter:ignore Link Mod Dependencies SmlVersion VirustotalResults
103103
Convert(source *ent.Version) *generated.Version
104104
ConvertSlice(source []*ent.Version) []*generated.Version
105105

@@ -118,6 +118,15 @@ type VersionDependency interface {
118118
ConvertSlice(source []*ent.VersionDependency) []*generated.VersionDependency
119119
}
120120

121+
// goverter:converter
122+
// goverter:output:file ../generated/conv/virustotal_result.go
123+
// goverter:output:package conv
124+
// goverter:extend TimeToString UIntToInt Int64ToInt
125+
type VirustotalResult interface {
126+
Convert(source *ent.VirustotalResult) *generated.VirustotalResult
127+
ConvertSlice(source []*ent.VirustotalResult) []*generated.VirustotalResult
128+
}
129+
121130
func TimeToString(i time.Time) string {
122131
return i.Format(time.RFC3339)
123132
}

db/schema/version.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ func (Version) Edges() []ent.Edge {
6262
edge.To("dependencies", Mod.Type).
6363
Through("version_dependencies", VersionDependency.Type),
6464
edge.To("targets", VersionTarget.Type),
65+
edge.To("virustotal_results", VirustotalResult.Type),
6566
}
6667
}

db/schema/virustotal_result.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package schema
2+
3+
import (
4+
"entgo.io/ent"
5+
"entgo.io/ent/schema/edge"
6+
"entgo.io/ent/schema/field"
7+
"entgo.io/ent/schema/index"
8+
)
9+
10+
type VirustotalResult struct {
11+
ent.Schema
12+
}
13+
14+
func (VirustotalResult) Mixin() []ent.Mixin {
15+
return []ent.Mixin{
16+
IDMixin{},
17+
TimeMixin{},
18+
}
19+
}
20+
21+
func (VirustotalResult) Fields() []ent.Field {
22+
return []ent.Field{
23+
field.Bool("safe").Default(false),
24+
field.String("hash").MaxLen(64).NotEmpty(),
25+
field.String("file_name").NotEmpty(),
26+
field.String("version_id").MaxLen(14).NotEmpty(),
27+
}
28+
}
29+
30+
func (VirustotalResult) Indexes() []ent.Index {
31+
return []ent.Index{
32+
index.Fields("safe"),
33+
index.Fields("hash", "version_id").Unique(),
34+
index.Fields("file_name"),
35+
}
36+
}
37+
38+
func (VirustotalResult) Edges() []ent.Edge {
39+
return []ent.Edge{
40+
edge.From("version", Version.Type).
41+
Ref("virustotal_results").
42+
Field("version_id").
43+
Unique().
44+
Required(),
45+
}
46+
}

generated/conv/virustotal_result.go

+44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/ent/client.go

+179-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)