go: add HIBPSchema + adjust ent model fields
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-08-20 23:16:12 +02:00
parent e7849b5443
commit 3077eb80c6
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI
9 changed files with 368 additions and 159 deletions

@ -22,6 +22,8 @@ type HIBP struct {
ID uuid.UUID `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
// Domain holds the value of the "domain" field.
Domain string `json:"domain,omitempty"`
// BreachDate holds the value of the "breach_date" field.
@ -32,7 +34,7 @@ type HIBP struct {
ModifiedDate time.Time `json:"modified_date,omitempty"`
// PwnCount holds the value of the "pwn_count" field.
PwnCount int `json:"pwn_count,omitempty"`
// May contain HTML markup.
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// Dataclasses holds the value of the "dataclasses" field.
Dataclasses []string `json:"dataclasses,omitempty"`
@ -48,8 +50,8 @@ type HIBP struct {
IsSpamList bool `json:"is_spamList,omitempty"`
// IsMalware holds the value of the "is_malware" field.
IsMalware bool `json:"is_malware,omitempty"`
// Always in PNG format.
Logo *string `json:"logo,omitempty"`
// LogoPath holds the value of the "logo_path" field.
LogoPath *string `json:"logo_path,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the HIBPQuery when eager-loading is set.
Edges HIBPEdges `json:"edges"`
@ -90,7 +92,7 @@ func (*HIBP) scanValues(columns []string) ([]any, error) {
values[i] = new(sql.NullBool)
case hibp.FieldPwnCount:
values[i] = new(sql.NullInt64)
case hibp.FieldName, hibp.FieldDomain, hibp.FieldDescription, hibp.FieldLogo:
case hibp.FieldName, hibp.FieldTitle, hibp.FieldDomain, hibp.FieldDescription, hibp.FieldLogoPath:
values[i] = new(sql.NullString)
case hibp.FieldBreachDate, hibp.FieldAddedDate, hibp.FieldModifiedDate:
values[i] = new(sql.NullTime)
@ -125,6 +127,12 @@ func (h *HIBP) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.Name = value.String
}
case hibp.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
h.Title = value.String
}
case hibp.FieldDomain:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field domain", values[i])
@ -206,12 +214,12 @@ func (h *HIBP) assignValues(columns []string, values []any) error {
} else if value.Valid {
h.IsMalware = value.Bool
}
case hibp.FieldLogo:
case hibp.FieldLogoPath:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field logo", values[i])
return fmt.Errorf("unexpected type %T for field logo_path", values[i])
} else if value.Valid {
h.Logo = new(string)
*h.Logo = value.String
h.LogoPath = new(string)
*h.LogoPath = value.String
}
case hibp.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
@ -264,6 +272,9 @@ func (h *HIBP) String() string {
builder.WriteString("name=")
builder.WriteString(h.Name)
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(h.Title)
builder.WriteString(", ")
builder.WriteString("domain=")
builder.WriteString(h.Domain)
builder.WriteString(", ")
@ -305,8 +316,8 @@ func (h *HIBP) String() string {
builder.WriteString("is_malware=")
builder.WriteString(fmt.Sprintf("%v", h.IsMalware))
builder.WriteString(", ")
if v := h.Logo; v != nil {
builder.WriteString("logo=")
if v := h.LogoPath; v != nil {
builder.WriteString("logo_path=")
builder.WriteString(*v)
}
builder.WriteByte(')')

@ -14,6 +14,8 @@ const (
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldTitle holds the string denoting the title field in the database.
FieldTitle = "title"
// FieldDomain holds the string denoting the domain field in the database.
FieldDomain = "domain"
// FieldBreachDate holds the string denoting the breach_date field in the database.
@ -40,8 +42,8 @@ const (
FieldIsSpamList = "is_spam_list"
// FieldIsMalware holds the string denoting the is_malware field in the database.
FieldIsMalware = "is_malware"
// FieldLogo holds the string denoting the logo field in the database.
FieldLogo = "logo"
// FieldLogoPath holds the string denoting the logo_path field in the database.
FieldLogoPath = "logo_path"
// EdgeTrackedBreaches holds the string denoting the tracked_breaches edge name in mutations.
EdgeTrackedBreaches = "tracked_breaches"
// Table holds the table name of the hibp in the database.
@ -59,6 +61,7 @@ const (
var Columns = []string{
FieldID,
FieldName,
FieldTitle,
FieldDomain,
FieldBreachDate,
FieldAddedDate,
@ -72,7 +75,7 @@ var Columns = []string{
FieldIsRetired,
FieldIsSpamList,
FieldIsMalware,
FieldLogo,
FieldLogoPath,
}
// ForeignKeys holds the SQL foreign-keys that are owned by the "hib_ps"
@ -97,6 +100,8 @@ func ValidColumn(column string) bool {
}
var (
// NameValidator is a validator for the "name" field. It is called by the builders before save.
NameValidator func(string) error
// DefaultIsVerified holds the default value on creation for the "is_verified" field.
DefaultIsVerified bool
// DefaultIsFabricated holds the default value on creation for the "is_fabricated" field.
@ -124,6 +129,11 @@ func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByTitle orders the results by the title field.
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTitle, opts...).ToFunc()
}
// ByDomain orders the results by the domain field.
func ByDomain(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDomain, opts...).ToFunc()
@ -184,9 +194,9 @@ func ByIsMalware(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIsMalware, opts...).ToFunc()
}
// ByLogo orders the results by the logo field.
func ByLogo(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLogo, opts...).ToFunc()
// ByLogoPath orders the results by the logo_path field.
func ByLogoPath(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLogoPath, opts...).ToFunc()
}
// ByTrackedBreachesField orders the results by tracked_breaches field.

@ -61,6 +61,11 @@ func Name(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldName, v))
}
// Title applies equality check predicate on the "title" field. It's identical to TitleEQ.
func Title(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldTitle, v))
}
// Domain applies equality check predicate on the "domain" field. It's identical to DomainEQ.
func Domain(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDomain, v))
@ -121,9 +126,9 @@ func IsMalware(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsMalware, v))
}
// Logo applies equality check predicate on the "logo" field. It's identical to LogoEQ.
func Logo(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogo, v))
// LogoPath applies equality check predicate on the "logo_path" field. It's identical to LogoPathEQ.
func LogoPath(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogoPath, v))
}
// NameEQ applies the EQ predicate on the "name" field.
@ -191,6 +196,71 @@ func NameContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldName, v))
}
// TitleEQ applies the EQ predicate on the "title" field.
func TitleEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldTitle, v))
}
// TitleNEQ applies the NEQ predicate on the "title" field.
func TitleNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldTitle, v))
}
// TitleIn applies the In predicate on the "title" field.
func TitleIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldTitle, vs...))
}
// TitleNotIn applies the NotIn predicate on the "title" field.
func TitleNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldTitle, vs...))
}
// TitleGT applies the GT predicate on the "title" field.
func TitleGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldTitle, v))
}
// TitleGTE applies the GTE predicate on the "title" field.
func TitleGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldTitle, v))
}
// TitleLT applies the LT predicate on the "title" field.
func TitleLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldTitle, v))
}
// TitleLTE applies the LTE predicate on the "title" field.
func TitleLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldTitle, v))
}
// TitleContains applies the Contains predicate on the "title" field.
func TitleContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldTitle, v))
}
// TitleHasPrefix applies the HasPrefix predicate on the "title" field.
func TitleHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldTitle, v))
}
// TitleHasSuffix applies the HasSuffix predicate on the "title" field.
func TitleHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldTitle, v))
}
// TitleEqualFold applies the EqualFold predicate on the "title" field.
func TitleEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldTitle, v))
}
// TitleContainsFold applies the ContainsFold predicate on the "title" field.
func TitleContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldTitle, v))
}
// DomainEQ applies the EQ predicate on the "domain" field.
func DomainEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDomain, v))
@ -551,79 +621,79 @@ func IsMalwareNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsMalware, v))
}
// LogoEQ applies the EQ predicate on the "logo" field.
func LogoEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogo, v))
// LogoPathEQ applies the EQ predicate on the "logo_path" field.
func LogoPathEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogoPath, v))
}
// LogoNEQ applies the NEQ predicate on the "logo" field.
func LogoNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldLogo, v))
// LogoPathNEQ applies the NEQ predicate on the "logo_path" field.
func LogoPathNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldLogoPath, v))
}
// LogoIn applies the In predicate on the "logo" field.
func LogoIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldLogo, vs...))
// LogoPathIn applies the In predicate on the "logo_path" field.
func LogoPathIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldLogoPath, vs...))
}
// LogoNotIn applies the NotIn predicate on the "logo" field.
func LogoNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldLogo, vs...))
// LogoPathNotIn applies the NotIn predicate on the "logo_path" field.
func LogoPathNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldLogoPath, vs...))
}
// LogoGT applies the GT predicate on the "logo" field.
func LogoGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldLogo, v))
// LogoPathGT applies the GT predicate on the "logo_path" field.
func LogoPathGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldLogoPath, v))
}
// LogoGTE applies the GTE predicate on the "logo" field.
func LogoGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldLogo, v))
// LogoPathGTE applies the GTE predicate on the "logo_path" field.
func LogoPathGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldLogoPath, v))
}
// LogoLT applies the LT predicate on the "logo" field.
func LogoLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldLogo, v))
// LogoPathLT applies the LT predicate on the "logo_path" field.
func LogoPathLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldLogoPath, v))
}
// LogoLTE applies the LTE predicate on the "logo" field.
func LogoLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldLogo, v))
// LogoPathLTE applies the LTE predicate on the "logo_path" field.
func LogoPathLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldLogoPath, v))
}
// LogoContains applies the Contains predicate on the "logo" field.
func LogoContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldLogo, v))
// LogoPathContains applies the Contains predicate on the "logo_path" field.
func LogoPathContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldLogoPath, v))
}
// LogoHasPrefix applies the HasPrefix predicate on the "logo" field.
func LogoHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldLogo, v))
// LogoPathHasPrefix applies the HasPrefix predicate on the "logo_path" field.
func LogoPathHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldLogoPath, v))
}
// LogoHasSuffix applies the HasSuffix predicate on the "logo" field.
func LogoHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldLogo, v))
// LogoPathHasSuffix applies the HasSuffix predicate on the "logo_path" field.
func LogoPathHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldLogoPath, v))
}
// LogoIsNil applies the IsNil predicate on the "logo" field.
func LogoIsNil() predicate.HIBP {
return predicate.HIBP(sql.FieldIsNull(FieldLogo))
// LogoPathIsNil applies the IsNil predicate on the "logo_path" field.
func LogoPathIsNil() predicate.HIBP {
return predicate.HIBP(sql.FieldIsNull(FieldLogoPath))
}
// LogoNotNil applies the NotNil predicate on the "logo" field.
func LogoNotNil() predicate.HIBP {
return predicate.HIBP(sql.FieldNotNull(FieldLogo))
// LogoPathNotNil applies the NotNil predicate on the "logo_path" field.
func LogoPathNotNil() predicate.HIBP {
return predicate.HIBP(sql.FieldNotNull(FieldLogoPath))
}
// LogoEqualFold applies the EqualFold predicate on the "logo" field.
func LogoEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldLogo, v))
// LogoPathEqualFold applies the EqualFold predicate on the "logo_path" field.
func LogoPathEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldLogoPath, v))
}
// LogoContainsFold applies the ContainsFold predicate on the "logo" field.
func LogoContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldLogo, v))
// LogoPathContainsFold applies the ContainsFold predicate on the "logo_path" field.
func LogoPathContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldLogoPath, v))
}
// HasTrackedBreaches applies the HasEdge predicate on the "tracked_breaches" edge.

@ -28,6 +28,12 @@ func (hc *HIBPCreate) SetName(s string) *HIBPCreate {
return hc
}
// SetTitle sets the "title" field.
func (hc *HIBPCreate) SetTitle(s string) *HIBPCreate {
hc.mutation.SetTitle(s)
return hc
}
// SetDomain sets the "domain" field.
func (hc *HIBPCreate) SetDomain(s string) *HIBPCreate {
hc.mutation.SetDomain(s)
@ -162,16 +168,16 @@ func (hc *HIBPCreate) SetNillableIsMalware(b *bool) *HIBPCreate {
return hc
}
// SetLogo sets the "logo" field.
func (hc *HIBPCreate) SetLogo(s string) *HIBPCreate {
hc.mutation.SetLogo(s)
// SetLogoPath sets the "logo_path" field.
func (hc *HIBPCreate) SetLogoPath(s string) *HIBPCreate {
hc.mutation.SetLogoPath(s)
return hc
}
// SetNillableLogo sets the "logo" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableLogo(s *string) *HIBPCreate {
// SetNillableLogoPath sets the "logo_path" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableLogoPath(s *string) *HIBPCreate {
if s != nil {
hc.SetLogo(*s)
hc.SetLogoPath(*s)
}
return hc
}
@ -267,6 +273,14 @@ func (hc *HIBPCreate) check() error {
if _, ok := hc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "HIBP.name"`)}
}
if v, ok := hc.mutation.Name(); ok {
if err := hibp.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "HIBP.name": %w`, err)}
}
}
if _, ok := hc.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "HIBP.title"`)}
}
if _, ok := hc.mutation.Domain(); !ok {
return &ValidationError{Name: "domain", err: errors.New(`ent: missing required field "HIBP.domain"`)}
}
@ -342,6 +356,10 @@ func (hc *HIBPCreate) createSpec() (*HIBP, *sqlgraph.CreateSpec) {
_spec.SetField(hibp.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := hc.mutation.Title(); ok {
_spec.SetField(hibp.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := hc.mutation.Domain(); ok {
_spec.SetField(hibp.FieldDomain, field.TypeString, value)
_node.Domain = value
@ -394,9 +412,9 @@ func (hc *HIBPCreate) createSpec() (*HIBP, *sqlgraph.CreateSpec) {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
_node.IsMalware = value
}
if value, ok := hc.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
_node.Logo = &value
if value, ok := hc.mutation.LogoPath(); ok {
_spec.SetField(hibp.FieldLogoPath, field.TypeString, value)
_node.LogoPath = &value
}
if nodes := hc.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
edge := &sqlgraph.EdgeSpec{

@ -31,9 +31,9 @@ func (hu *HIBPUpdate) Where(ps ...predicate.HIBP) *HIBPUpdate {
return hu
}
// SetName sets the "name" field.
func (hu *HIBPUpdate) SetName(s string) *HIBPUpdate {
hu.mutation.SetName(s)
// SetTitle sets the "title" field.
func (hu *HIBPUpdate) SetTitle(s string) *HIBPUpdate {
hu.mutation.SetTitle(s)
return hu
}
@ -184,23 +184,23 @@ func (hu *HIBPUpdate) SetNillableIsMalware(b *bool) *HIBPUpdate {
return hu
}
// SetLogo sets the "logo" field.
func (hu *HIBPUpdate) SetLogo(s string) *HIBPUpdate {
hu.mutation.SetLogo(s)
// SetLogoPath sets the "logo_path" field.
func (hu *HIBPUpdate) SetLogoPath(s string) *HIBPUpdate {
hu.mutation.SetLogoPath(s)
return hu
}
// SetNillableLogo sets the "logo" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableLogo(s *string) *HIBPUpdate {
// SetNillableLogoPath sets the "logo_path" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableLogoPath(s *string) *HIBPUpdate {
if s != nil {
hu.SetLogo(*s)
hu.SetLogoPath(*s)
}
return hu
}
// ClearLogo clears the value of the "logo" field.
func (hu *HIBPUpdate) ClearLogo() *HIBPUpdate {
hu.mutation.ClearLogo()
// ClearLogoPath clears the value of the "logo_path" field.
func (hu *HIBPUpdate) ClearLogoPath() *HIBPUpdate {
hu.mutation.ClearLogoPath()
return hu
}
@ -270,8 +270,8 @@ func (hu *HIBPUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
}
}
if value, ok := hu.mutation.Name(); ok {
_spec.SetField(hibp.FieldName, field.TypeString, value)
if value, ok := hu.mutation.Title(); ok {
_spec.SetField(hibp.FieldTitle, field.TypeString, value)
}
if value, ok := hu.mutation.BreachDate(); ok {
_spec.SetField(hibp.FieldBreachDate, field.TypeTime, value)
@ -320,11 +320,11 @@ func (hu *HIBPUpdate) sqlSave(ctx context.Context) (n int, err error) {
if value, ok := hu.mutation.IsMalware(); ok {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
}
if value, ok := hu.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
if value, ok := hu.mutation.LogoPath(); ok {
_spec.SetField(hibp.FieldLogoPath, field.TypeString, value)
}
if hu.mutation.LogoCleared() {
_spec.ClearField(hibp.FieldLogo, field.TypeString)
if hu.mutation.LogoPathCleared() {
_spec.ClearField(hibp.FieldLogoPath, field.TypeString)
}
if hu.mutation.TrackedBreachesCleared() {
edge := &sqlgraph.EdgeSpec{
@ -375,9 +375,9 @@ type HIBPUpdateOne struct {
mutation *HIBPMutation
}
// SetName sets the "name" field.
func (huo *HIBPUpdateOne) SetName(s string) *HIBPUpdateOne {
huo.mutation.SetName(s)
// SetTitle sets the "title" field.
func (huo *HIBPUpdateOne) SetTitle(s string) *HIBPUpdateOne {
huo.mutation.SetTitle(s)
return huo
}
@ -528,23 +528,23 @@ func (huo *HIBPUpdateOne) SetNillableIsMalware(b *bool) *HIBPUpdateOne {
return huo
}
// SetLogo sets the "logo" field.
func (huo *HIBPUpdateOne) SetLogo(s string) *HIBPUpdateOne {
huo.mutation.SetLogo(s)
// SetLogoPath sets the "logo_path" field.
func (huo *HIBPUpdateOne) SetLogoPath(s string) *HIBPUpdateOne {
huo.mutation.SetLogoPath(s)
return huo
}
// SetNillableLogo sets the "logo" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableLogo(s *string) *HIBPUpdateOne {
// SetNillableLogoPath sets the "logo_path" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableLogoPath(s *string) *HIBPUpdateOne {
if s != nil {
huo.SetLogo(*s)
huo.SetLogoPath(*s)
}
return huo
}
// ClearLogo clears the value of the "logo" field.
func (huo *HIBPUpdateOne) ClearLogo() *HIBPUpdateOne {
huo.mutation.ClearLogo()
// ClearLogoPath clears the value of the "logo_path" field.
func (huo *HIBPUpdateOne) ClearLogoPath() *HIBPUpdateOne {
huo.mutation.ClearLogoPath()
return huo
}
@ -644,8 +644,8 @@ func (huo *HIBPUpdateOne) sqlSave(ctx context.Context) (_node *HIBP, err error)
}
}
}
if value, ok := huo.mutation.Name(); ok {
_spec.SetField(hibp.FieldName, field.TypeString, value)
if value, ok := huo.mutation.Title(); ok {
_spec.SetField(hibp.FieldTitle, field.TypeString, value)
}
if value, ok := huo.mutation.BreachDate(); ok {
_spec.SetField(hibp.FieldBreachDate, field.TypeTime, value)
@ -694,11 +694,11 @@ func (huo *HIBPUpdateOne) sqlSave(ctx context.Context) (_node *HIBP, err error)
if value, ok := huo.mutation.IsMalware(); ok {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
}
if value, ok := huo.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
if value, ok := huo.mutation.LogoPath(); ok {
_spec.SetField(hibp.FieldLogoPath, field.TypeString, value)
}
if huo.mutation.LogoCleared() {
_spec.ClearField(hibp.FieldLogo, field.TypeString)
if huo.mutation.LogoPathCleared() {
_spec.ClearField(hibp.FieldLogoPath, field.TypeString)
}
if huo.mutation.TrackedBreachesCleared() {
edge := &sqlgraph.EdgeSpec{

@ -34,6 +34,7 @@ var (
HibPsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
{Name: "name", Type: field.TypeString, Unique: true},
{Name: "title", Type: field.TypeString, Unique: true},
{Name: "domain", Type: field.TypeString},
{Name: "breach_date", Type: field.TypeTime},
{Name: "added_date", Type: field.TypeTime},
@ -47,7 +48,7 @@ var (
{Name: "is_retired", Type: field.TypeBool, Default: false},
{Name: "is_spam_list", Type: field.TypeBool, Default: false},
{Name: "is_malware", Type: field.TypeBool, Default: false},
{Name: "logo", Type: field.TypeString, Nullable: true},
{Name: "logo_path", Type: field.TypeString, Nullable: true},
{Name: "tracked_breaches_hibp", Type: field.TypeUUID, Nullable: true},
}
// HibPsTable holds the schema information for the "hib_ps" table.
@ -58,7 +59,7 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "hib_ps_tracked_breaches_hibp",
Columns: []*schema.Column{HibPsColumns[16]},
Columns: []*schema.Column{HibPsColumns[17]},
RefColumns: []*schema.Column{TrackedBreachesColumns[0]},
OnDelete: schema.SetNull,
},

@ -610,6 +610,7 @@ type HIBPMutation struct {
typ string
id *uuid.UUID
name *string
title *string
domain *string
breach_date *time.Time
added_date *time.Time
@ -625,7 +626,7 @@ type HIBPMutation struct {
is_retired *bool
is_spamList *bool
is_malware *bool
logo *string
logo_path *string
clearedFields map[string]struct{}
tracked_breaches *uuid.UUID
clearedtracked_breaches bool
@ -774,6 +775,42 @@ func (m *HIBPMutation) ResetName() {
m.name = nil
}
// SetTitle sets the "title" field.
func (m *HIBPMutation) SetTitle(s string) {
m.title = &s
}
// Title returns the value of the "title" field in the mutation.
func (m *HIBPMutation) Title() (r string, exists bool) {
v := m.title
if v == nil {
return
}
return *v, true
}
// OldTitle returns the old "title" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldTitle(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTitle is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTitle requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTitle: %w", err)
}
return oldValue.Title, nil
}
// ResetTitle resets all changes to the "title" field.
func (m *HIBPMutation) ResetTitle() {
m.title = nil
}
// SetDomain sets the "domain" field.
func (m *HIBPMutation) SetDomain(s string) {
m.domain = &s
@ -1290,53 +1327,53 @@ func (m *HIBPMutation) ResetIsMalware() {
m.is_malware = nil
}
// SetLogo sets the "logo" field.
func (m *HIBPMutation) SetLogo(s string) {
m.logo = &s
// SetLogoPath sets the "logo_path" field.
func (m *HIBPMutation) SetLogoPath(s string) {
m.logo_path = &s
}
// Logo returns the value of the "logo" field in the mutation.
func (m *HIBPMutation) Logo() (r string, exists bool) {
v := m.logo
// LogoPath returns the value of the "logo_path" field in the mutation.
func (m *HIBPMutation) LogoPath() (r string, exists bool) {
v := m.logo_path
if v == nil {
return
}
return *v, true
}
// OldLogo returns the old "logo" field's value of the HIBP entity.
// OldLogoPath returns the old "logo_path" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldLogo(ctx context.Context) (v *string, err error) {
func (m *HIBPMutation) OldLogoPath(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLogo is only allowed on UpdateOne operations")
return v, errors.New("OldLogoPath is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLogo requires an ID field in the mutation")
return v, errors.New("OldLogoPath requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLogo: %w", err)
return v, fmt.Errorf("querying old value for OldLogoPath: %w", err)
}
return oldValue.Logo, nil
return oldValue.LogoPath, nil
}
// ClearLogo clears the value of the "logo" field.
func (m *HIBPMutation) ClearLogo() {
m.logo = nil
m.clearedFields[hibp.FieldLogo] = struct{}{}
// ClearLogoPath clears the value of the "logo_path" field.
func (m *HIBPMutation) ClearLogoPath() {
m.logo_path = nil
m.clearedFields[hibp.FieldLogoPath] = struct{}{}
}
// LogoCleared returns if the "logo" field was cleared in this mutation.
func (m *HIBPMutation) LogoCleared() bool {
_, ok := m.clearedFields[hibp.FieldLogo]
// LogoPathCleared returns if the "logo_path" field was cleared in this mutation.
func (m *HIBPMutation) LogoPathCleared() bool {
_, ok := m.clearedFields[hibp.FieldLogoPath]
return ok
}
// ResetLogo resets all changes to the "logo" field.
func (m *HIBPMutation) ResetLogo() {
m.logo = nil
delete(m.clearedFields, hibp.FieldLogo)
// ResetLogoPath resets all changes to the "logo_path" field.
func (m *HIBPMutation) ResetLogoPath() {
m.logo_path = nil
delete(m.clearedFields, hibp.FieldLogoPath)
}
// SetTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by id.
@ -1412,10 +1449,13 @@ func (m *HIBPMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *HIBPMutation) Fields() []string {
fields := make([]string, 0, 15)
fields := make([]string, 0, 16)
if m.name != nil {
fields = append(fields, hibp.FieldName)
}
if m.title != nil {
fields = append(fields, hibp.FieldTitle)
}
if m.domain != nil {
fields = append(fields, hibp.FieldDomain)
}
@ -1455,8 +1495,8 @@ func (m *HIBPMutation) Fields() []string {
if m.is_malware != nil {
fields = append(fields, hibp.FieldIsMalware)
}
if m.logo != nil {
fields = append(fields, hibp.FieldLogo)
if m.logo_path != nil {
fields = append(fields, hibp.FieldLogoPath)
}
return fields
}
@ -1468,6 +1508,8 @@ func (m *HIBPMutation) Field(name string) (ent.Value, bool) {
switch name {
case hibp.FieldName:
return m.Name()
case hibp.FieldTitle:
return m.Title()
case hibp.FieldDomain:
return m.Domain()
case hibp.FieldBreachDate:
@ -1494,8 +1536,8 @@ func (m *HIBPMutation) Field(name string) (ent.Value, bool) {
return m.IsSpamList()
case hibp.FieldIsMalware:
return m.IsMalware()
case hibp.FieldLogo:
return m.Logo()
case hibp.FieldLogoPath:
return m.LogoPath()
}
return nil, false
}
@ -1507,6 +1549,8 @@ func (m *HIBPMutation) OldField(ctx context.Context, name string) (ent.Value, er
switch name {
case hibp.FieldName:
return m.OldName(ctx)
case hibp.FieldTitle:
return m.OldTitle(ctx)
case hibp.FieldDomain:
return m.OldDomain(ctx)
case hibp.FieldBreachDate:
@ -1533,8 +1577,8 @@ func (m *HIBPMutation) OldField(ctx context.Context, name string) (ent.Value, er
return m.OldIsSpamList(ctx)
case hibp.FieldIsMalware:
return m.OldIsMalware(ctx)
case hibp.FieldLogo:
return m.OldLogo(ctx)
case hibp.FieldLogoPath:
return m.OldLogoPath(ctx)
}
return nil, fmt.Errorf("unknown HIBP field %s", name)
}
@ -1551,6 +1595,13 @@ func (m *HIBPMutation) SetField(name string, value ent.Value) error {
}
m.SetName(v)
return nil
case hibp.FieldTitle:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTitle(v)
return nil
case hibp.FieldDomain:
v, ok := value.(string)
if !ok {
@ -1642,12 +1693,12 @@ func (m *HIBPMutation) SetField(name string, value ent.Value) error {
}
m.SetIsMalware(v)
return nil
case hibp.FieldLogo:
case hibp.FieldLogoPath:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLogo(v)
m.SetLogoPath(v)
return nil
}
return fmt.Errorf("unknown HIBP field %s", name)
@ -1697,8 +1748,8 @@ func (m *HIBPMutation) ClearedFields() []string {
if m.FieldCleared(hibp.FieldDescription) {
fields = append(fields, hibp.FieldDescription)
}
if m.FieldCleared(hibp.FieldLogo) {
fields = append(fields, hibp.FieldLogo)
if m.FieldCleared(hibp.FieldLogoPath) {
fields = append(fields, hibp.FieldLogoPath)
}
return fields
}
@ -1717,8 +1768,8 @@ func (m *HIBPMutation) ClearField(name string) error {
case hibp.FieldDescription:
m.ClearDescription()
return nil
case hibp.FieldLogo:
m.ClearLogo()
case hibp.FieldLogoPath:
m.ClearLogoPath()
return nil
}
return fmt.Errorf("unknown HIBP nullable field %s", name)
@ -1731,6 +1782,9 @@ func (m *HIBPMutation) ResetField(name string) error {
case hibp.FieldName:
m.ResetName()
return nil
case hibp.FieldTitle:
m.ResetTitle()
return nil
case hibp.FieldDomain:
m.ResetDomain()
return nil
@ -1770,8 +1824,8 @@ func (m *HIBPMutation) ResetField(name string) error {
case hibp.FieldIsMalware:
m.ResetIsMalware()
return nil
case hibp.FieldLogo:
m.ResetLogo()
case hibp.FieldLogoPath:
m.ResetLogoPath()
return nil
}
return fmt.Errorf("unknown HIBP field %s", name)

@ -41,28 +41,32 @@ func init() {
agekey.DefaultID = agekeyDescID.Default.(func() uuid.UUID)
hibpFields := schema.HIBP{}.Fields()
_ = hibpFields
// hibpDescName is the schema descriptor for name field.
hibpDescName := hibpFields[1].Descriptor()
// hibp.NameValidator is a validator for the "name" field. It is called by the builders before save.
hibp.NameValidator = hibpDescName.Validators[0].(func(string) error)
// hibpDescIsVerified is the schema descriptor for is_verified field.
hibpDescIsVerified := hibpFields[9].Descriptor()
hibpDescIsVerified := hibpFields[10].Descriptor()
// hibp.DefaultIsVerified holds the default value on creation for the is_verified field.
hibp.DefaultIsVerified = hibpDescIsVerified.Default.(bool)
// hibpDescIsFabricated is the schema descriptor for is_fabricated field.
hibpDescIsFabricated := hibpFields[10].Descriptor()
hibpDescIsFabricated := hibpFields[11].Descriptor()
// hibp.DefaultIsFabricated holds the default value on creation for the is_fabricated field.
hibp.DefaultIsFabricated = hibpDescIsFabricated.Default.(bool)
// hibpDescIsSensitive is the schema descriptor for is_sensitive field.
hibpDescIsSensitive := hibpFields[11].Descriptor()
hibpDescIsSensitive := hibpFields[12].Descriptor()
// hibp.DefaultIsSensitive holds the default value on creation for the is_sensitive field.
hibp.DefaultIsSensitive = hibpDescIsSensitive.Default.(bool)
// hibpDescIsRetired is the schema descriptor for is_retired field.
hibpDescIsRetired := hibpFields[12].Descriptor()
hibpDescIsRetired := hibpFields[13].Descriptor()
// hibp.DefaultIsRetired holds the default value on creation for the is_retired field.
hibp.DefaultIsRetired = hibpDescIsRetired.Default.(bool)
// hibpDescIsSpamList is the schema descriptor for is_spamList field.
hibpDescIsSpamList := hibpFields[13].Descriptor()
hibpDescIsSpamList := hibpFields[14].Descriptor()
// hibp.DefaultIsSpamList holds the default value on creation for the is_spamList field.
hibp.DefaultIsSpamList = hibpDescIsSpamList.Default.(bool)
// hibpDescIsMalware is the schema descriptor for is_malware field.
hibpDescIsMalware := hibpFields[14].Descriptor()
hibpDescIsMalware := hibpFields[15].Descriptor()
// hibp.DefaultIsMalware holds the default value on creation for the is_malware field.
hibp.DefaultIsMalware = hibpDescIsMalware.Default.(bool)
localbreachFields := schema.LocalBreach{}.Fields()

@ -4,6 +4,8 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
@ -15,6 +17,43 @@ type HIBP struct {
ent.Schema
}
// HIBPSchema is modeled after the HIBP model (ref:
// https://haveibeenpwned.com/API/v3#BreachModel).
type HIBPSchema struct {
// A Pascal-cased name representing the breach which is unique across all other breaches. This value never changes and may be used to name dependent assets (such as images) but should not be shown directly to end users (see the "Title" attribute instead).
Name string `json:"Name" validate:"required,Name"`
// A Pascal-cased name representing the breach which is unique across all other breaches. This value never changes and may be used to name dependent assets (such as images) but should not be shown directly to end users (see the "Title" attribute instead).
Title string `json:"Title"`
// The domain of the primary website the breach occurred on. This may be used for identifying other assets external systems may have for the site.
Domain string `json:"Domain"`
// The date (with no time) the breach originally occurred on in ISO 8601 format. This is not always accurate — frequently breaches are discovered and reported long after the original incident. Use this attribute as a guide only.
BreachDate time.Time `json:"BreachDate"`
// The date and time (precision to the minute) the breach was added to the system in ISO 8601 format.
AddedDate time.Time `json:"AddedDate"`
// The date and time (precision to the minute) the breach was modified in ISO 8601 format. This will only differ from the AddedDate attribute if other attributes represented here are changed or data in the breach itself is changed (i.e. additional data is identified and loaded). It is always either equal to or greater then the AddedDate attribute, never less than.
ModifiedDate time.Time `json:"ModifiedDate"`
// The total number of accounts loaded into the system. This is usually less than the total number reported by the media due to duplication or other data integrity issues in the source data.
PwnCount int `json:"PwnCount"`
// Contains an overview of the breach represented in HTML markup. The description may include markup such as emphasis and strong tags as well as hyperlinks.
Description string `json:"Description"`
// This attribute describes the nature of the data compromised in the breach and contains an alphabetically ordered string array of impacted data classes.
DataClasses []string `json:"DataClasses"`
// Indicates that the breach is considered unverified. An unverified breach may not have been hacked from the indicated website. An unverified breach is still loaded into HIBP when there's sufficient confidence that a significant portion of the data is legitimate.
IsVerified bool `json:"IsVerified"`
// Indicates that the breach is considered fabricated. A fabricated breach is unlikely to have been hacked from the indicated website and usually contains a large amount of manufactured data. However, it still contains legitimate email addresses and asserts that the account owners were compromised in the alleged breach.
IsFabricated bool `json:"IsFabricated"`
// Indicates if the breach is considered sensitive. The public API will not return any accounts for a breach flagged as sensitive.
IsSensitive bool `json:"IsSensitive"`
// Indicates if the breach has been retired. This data has been permanently removed and will not be returned by the API.
IsRetired bool `json:"IsRetired"`
// Indicates if the breach is considered a spam list. This flag has no impact on any other attributes but it means that the data has not come as a result of a security compromise.
IsSpamList bool `json:"IsSpamList"`
// Indicates if the breach is sourced from malware. This flag has no impact on any other attributes, it merely flags that the data was sourced from a malware campaign rather than a security compromise of an online service.
IsMalware bool `json:"IsMalware"`
// A URI that specifies where a logo for the breached service can be found. Logos are always in PNG format.
LogoPath string `json:"LogoPath"`
}
// Fields of the HIBP that model the HIBP API v3, ref:
// https://haveibeenpwned.com/API/v3.
func (HIBP) Fields() []ent.Field {
@ -24,6 +63,10 @@ func (HIBP) Fields() []ent.Field {
Immutable(),
// Unique but may change.
field.String("name").
NotEmpty().
Unique().
Immutable(),
field.String("title").
Unique(),
field.String("domain").
Immutable(),
@ -33,7 +76,6 @@ func (HIBP) Fields() []ent.Field {
field.Time("modified_date"),
field.Int("pwn_count"),
field.String("description").
Comment("May contain HTML markup.").
Optional().
Nillable(),
field.Strings("dataclasses"),
@ -49,8 +91,7 @@ func (HIBP) Fields() []ent.Field {
Default(false),
field.Bool("is_malware").
Default(false),
field.String("logo").
Comment("Always in PNG format.").
field.String("logo_path").
Optional().
Nillable(),
}