Skip to content

Commit

Permalink
feat: add VirusTotal Results to API (#92)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
knightzac19 authored Oct 3, 2024
1 parent e0e42f8 commit fea5bc3
Show file tree
Hide file tree
Showing 38 changed files with 5,334 additions and 238 deletions.
11 changes: 10 additions & 1 deletion conversion/ent_to_graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Mod interface {
// goverter:extend TimeToString UIntToInt Int64ToInt
type Version interface {
// goverter:map Edges.Targets Targets
// goverter:ignore Link Mod Dependencies SmlVersion
// goverter:ignore Link Mod Dependencies SmlVersion VirustotalResults
Convert(source *ent.Version) *generated.Version
ConvertSlice(source []*ent.Version) []*generated.Version

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

// goverter:converter
// goverter:output:file ../generated/conv/virustotal_result.go
// goverter:output:package conv
// goverter:extend TimeToString UIntToInt Int64ToInt
type VirustotalResult interface {
Convert(source *ent.VirustotalResult) *generated.VirustotalResult
ConvertSlice(source []*ent.VirustotalResult) []*generated.VirustotalResult
}

func TimeToString(i time.Time) string {
return i.Format(time.RFC3339)
}
Expand Down
1 change: 1 addition & 0 deletions db/schema/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ func (Version) Edges() []ent.Edge {
edge.To("dependencies", Mod.Type).
Through("version_dependencies", VersionDependency.Type),
edge.To("targets", VersionTarget.Type),
edge.To("virustotal_results", VirustotalResult.Type),
}
}
46 changes: 46 additions & 0 deletions db/schema/virustotal_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package schema

import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)

type VirustotalResult struct {
ent.Schema
}

func (VirustotalResult) Mixin() []ent.Mixin {
return []ent.Mixin{
IDMixin{},
TimeMixin{},
}
}

func (VirustotalResult) Fields() []ent.Field {
return []ent.Field{
field.Bool("safe").Default(false),
field.String("hash").MaxLen(64).NotEmpty(),
field.String("file_name").NotEmpty(),
field.String("version_id").MaxLen(14).NotEmpty(),
}
}

func (VirustotalResult) Indexes() []ent.Index {
return []ent.Index{
index.Fields("safe"),
index.Fields("hash", "version_id").Unique(),
index.Fields("file_name"),
}
}

func (VirustotalResult) Edges() []ent.Edge {
return []ent.Edge{
edge.From("version", Version.Type).
Ref("virustotal_results").
Field("version_id").
Unique().
Required(),
}
}
44 changes: 44 additions & 0 deletions generated/conv/virustotal_result.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

185 changes: 179 additions & 6 deletions generated/ent/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fea5bc3

Please sign in to comment.