@@ -5,9 +5,10 @@ import javax.inject.{ Inject, Singleton }
5
5
6
6
import models .JsonFormat .alertStatusFormat
7
7
import org .elastic4play .controllers .JsonInputValue
8
- import org .elastic4play .{ AttributeCheckingError , InvalidFormatAttributeError }
9
- import org .elastic4play .models .{ Attribute , AttributeDef , BaseEntity , EntityDef , HiveEnumeration , ModelDef , AttributeFormat ⇒ F , AttributeOption ⇒ O }
8
+ import org .elastic4play .models .{ Attribute , AttributeDef , BaseEntity , EntityDef , HiveEnumeration , ModelDef , MultiAttributeFormat , OptionalAttributeFormat , AttributeFormat ⇒ F , AttributeOption ⇒ O }
9
+ import org .elastic4play .services . DBLists
10
10
import org .elastic4play .utils .Hasher
11
+ import org .elastic4play .{ AttributeCheckingError , InvalidFormatAttributeError }
11
12
import play .api .Logger
12
13
import play .api .libs .json ._
13
14
import services .AuditedModel
@@ -43,7 +44,7 @@ trait AlertAttributes {
43
44
}
44
45
45
46
@ Singleton
46
- class AlertModel @ Inject () (artifactModel : ArtifactModel )
47
+ class AlertModel @ Inject () (dblists : DBLists )
47
48
extends ModelDef [AlertModel , Alert ](" alert" )
48
49
with AlertAttributes
49
50
with AuditedModel {
@@ -52,17 +53,34 @@ class AlertModel @Inject() (artifactModel: ArtifactModel)
52
53
override val defaultSortBy : Seq [String ] = Seq (" -date" )
53
54
override val removeAttribute : JsObject = Json .obj(" status" → AlertStatus .Ignored )
54
55
55
- override def artifactAttributes : Seq [Attribute [_]] = artifactModel
56
- .attributes
57
- .filter(_.isForm)
56
+ override def artifactAttributes : Seq [Attribute [_]] = {
57
+ val remoteAttachmentAttributes = Seq (
58
+ Attribute (" alert" , " reference" , F .stringFmt, Nil , None , " " ),
59
+ Attribute (" alert" , " filename" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ),
60
+ Attribute (" alert" , " contentType" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ),
61
+ Attribute (" alert" , " size" , OptionalAttributeFormat (F .numberFmt), Nil , None , " " ),
62
+ Attribute (" alert" , " hash" , MultiAttributeFormat (F .stringFmt), Nil , None , " " ),
63
+ Attribute (" alert" , " type" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ))
64
+
65
+ Seq (
66
+ Attribute (" alert" , " data" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ),
67
+ Attribute (" alert" , " dataType" , F .stringFmt, Nil , None , " " ),
68
+ Attribute (" alert" , " message" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ),
69
+ Attribute (" alert" , " startDate" , OptionalAttributeFormat (F .dateFmt), Nil , None , " " ),
70
+ Attribute (" alert" , " attachment" , OptionalAttributeFormat (F .attachmentFmt), Nil , None , " " ),
71
+ Attribute (" alert" , " remoteAttachment" , OptionalAttributeFormat (F .objectFmt(remoteAttachmentAttributes)), Nil , None , " " ),
72
+ Attribute (" alert" , " tlp" , OptionalAttributeFormat (F .numberFmt), Nil , None , " " ),
73
+ Attribute (" alert" , " tags" , MultiAttributeFormat (F .stringFmt), Nil , None , " " ),
74
+ Attribute (" alert" , " ioc" , OptionalAttributeFormat (F .stringFmt), Nil , None , " " ))
75
+ }
58
76
59
77
override def creationHook (parent : Option [BaseEntity ], attrs : JsObject ): Future [JsObject ] = {
60
78
// check if data attribute is present on all artifacts
61
79
val missingDataErrors = (attrs \ " artifacts" )
62
80
.asOpt[Seq [JsValue ]]
63
81
.getOrElse(Nil )
64
82
.filter { a ⇒
65
- (a \ " data" ).toOption.isEmpty ||
83
+ (( a \ " data" ).toOption.isEmpty && (a \ " attachment " ).toOption.isEmpty && (a \ " remoteAttachment " ).toOption.isEmpty) ||
66
84
((a \ " tags" ).toOption.isEmpty && (a \ " message" ).toOption.isEmpty)
67
85
}
68
86
.map(v ⇒ InvalidFormatAttributeError (" artifacts" , " artifact" , JsonInputValue (v)))
0 commit comments