Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VirusTotal Results to API #92

Open
wants to merge 11 commits into
base: staging
Choose a base branch
from
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 @@ -61,5 +61,6 @@ func (Version) Edges() []ent.Edge {
edge.To("dependencies", Mod.Type).
Through("version_dependencies", VersionDependency.Type),
edge.To("targets", VersionTarget.Type),
edge.To("virustotalResults", VirustotalResult.Type),
knightzac19 marked this conversation as resolved.
Show resolved Hide resolved
}
}
48 changes: 48 additions & 0 deletions db/schema/virustotal_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package schema

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

// YourTableName holds the schema definition for the YourTableName entity.
knightzac19 marked this conversation as resolved.
Show resolved Hide resolved
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("url").
NotEmpty(),
field.String("hash").Unique().NotEmpty(),
knightzac19 marked this conversation as resolved.
Show resolved Hide resolved
field.String("file_name").NotEmpty(),
field.String("version_id").NotEmpty(),
}
}

func (VirustotalResult) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "virustotal_results"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same name it would be using anyway? Why override it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generator was making the table virus_total_results

}
}

func (VirustotalResult) Edges() []ent.Edge {
return []ent.Edge{
edge.From("version", Version.Type).
Ref("virustotalResults").
knightzac19 marked this conversation as resolved.
Show resolved Hide resolved
Field("version_id").
Unique().
Required(),
}
}
1 change: 1 addition & 0 deletions generated/conv/version.go

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

45 changes: 45 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