forked from TheHive-Project/Cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
202 lines (186 loc) · 8.21 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name := """cortex"""
lazy val cortex = (project in file("."))
.enablePlugins(PlayScala)
.settings(PublishToBinTray.settings)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
cache,
ws,
"net.codingwell" %% "scala-guice" % "4.0.1",
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)
// Add information in manifest
import Package.ManifestAttributes
import java.util.jar.Attributes.Name._
packageOptions ++= Seq(
ManifestAttributes(IMPLEMENTATION_TITLE -> name.value),
ManifestAttributes(IMPLEMENTATION_VERSION -> version.value),
ManifestAttributes(SPECIFICATION_VENDOR -> "TheHive Project"),
ManifestAttributes(SPECIFICATION_TITLE -> name.value),
ManifestAttributes(SPECIFICATION_VERSION -> "TheHive Project")
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
Release.releaseVersionUIFile := baseDirectory.value / "ui" / "package.json"
Release.changelogFile := baseDirectory.value / "CHANGELOG.md"
publishArtifact in (Compile, packageDoc) := false
publishArtifact in packageDoc := false
sources in (Compile,doc) := Seq.empty
// Front-end //
run := {
(run in Compile).evaluated
frontendDev.value
}
mappings in packageBin in Assets ++= frontendFiles.value
// Install files //
mappings in Universal ~= {
_.flatMap {
case (_, "conf/application.conf") => Nil
case (file, "conf/apllication.sample") => Seq(file -> "conf/application.conf")
case (_, "conf/logback.xml") => Nil
case other => Seq(other)
} ++ Seq(
file("package/cortex.service") -> "package/cortex.service",
file("package/cortex.conf") -> "package/cortex.conf",
file("package/cortex") -> "package/cortex",
file("package/logback.xml") -> "conf/logback.xml",
file("contrib/misp-modules-loader.py") -> "contrib/misp-modules-loader.py"
)
}
// Package //
maintainer := "TheHive Project <[email protected]>"
packageSummary := "Powerful Observable Analysis Engine"
packageDescription := """Cortex tries to solve a common problem frequently encountered by SOCs, CSIRTs and security
| researchers in the course of threat intelligence, digital forensics and incident response: how to analyze
| observables they have collected, at scale, by querying a single tool instead of several?
| Cortex, an open source and free software, has been created by TheHive Project for this very purpose. Observables,
| such as IP and email addresses, URLs, domain names, files or hashes, can be analyzed one by one or in bulk mode
| using a Web interface. Analysts can also automate these operations thanks to the Cortex REST API. """.stripMargin
defaultLinuxInstallLocation := "/opt"
linuxPackageMappings ~= { _.map { pm =>
val mappings = pm.mappings.filterNot {
case (_, path) => path.startsWith("/opt/cortex/package") || (path.startsWith("/opt/cortex/conf") && path != "/opt/cortex/conf/reference.conf")
}
com.typesafe.sbt.packager.linux.LinuxPackageMapping(mappings, pm.fileData).withConfig()
} :+ packageMapping(
file("package/cortex.service") -> "/etc/systemd/system/cortex.service",
file("package/cortex.conf") -> "/etc/init/cortex.conf",
file("package/cortex") -> "/etc/init.d/cortex",
file("conf/application.sample") -> "/etc/cortex/application.conf",
file("package/logback.xml") -> "/etc/cortex/logback.xml"
).withConfig()
}
packageBin := {
(packageBin in Debian).value
(packageBin in Rpm).value
(packageBin in Universal).value
}
// DEB //
version in Debian := version.value + "-1"
debianPackageDependencies += "openjdk-8-jre-headless"
maintainerScripts in Debian := maintainerScriptsFromDirectory(
baseDirectory.value / "package" / "debian",
Seq(DebianConstants.Postinst, DebianConstants.Prerm, DebianConstants.Postrm)
)
linuxEtcDefaultTemplate in Debian := (baseDirectory.value / "package" / "etc_default_cortex").asURL
linuxMakeStartScript in Debian := None
// RPM //
rpmRelease := "1"
rpmVendor := "TheHive Project"
rpmUrl := Some("http://thehive-project.org/")
rpmLicense := Some("AGPL")
rpmRequirements += "java-1.8.0-openjdk-headless"
maintainerScripts in Rpm := maintainerScriptsFromDirectory(
baseDirectory.value / "package" / "rpm",
Seq(RpmConstants.Pre, RpmConstants.Preun, RpmConstants.Postun)
)
linuxPackageSymlinks in Rpm := Nil
rpmPrefix := Some(defaultLinuxInstallLocation.value)
linuxEtcDefaultTemplate in Rpm := (baseDirectory.value / "package" / "etc_default_cortex").asURL
packageBin in Rpm := {
val rpmFile = (packageBin in Rpm).value
s"rpm --addsign $rpmFile".!!
rpmFile
}
// DOCKER //
import com.typesafe.sbt.packager.docker.{ Cmd, ExecCmd }
version in Docker := version.value + "-1"
defaultLinuxInstallLocation in Docker := "/opt/cortex"
dockerRepository := Some("certbdf")
dockerUpdateLatest := true
dockerEntrypoint := Seq("/opt/cortex/entrypoint")
dockerExposedPorts := Seq(9000)
mappings in Docker ++= Seq(
file("package/docker/entrypoint") -> "/opt/cortex/entrypoint",
file("conf/logback.xml") -> "/etc/cortex/logback.xml",
file("package/empty") -> "/var/log/cortex/application.log")
mappings in Docker ~= (_.filterNot {
case (_, filepath) => filepath == "/opt/cortex/conf/application.conf"
})
dockerCommands ~= { dc =>
val (dockerInitCmds, dockerTailCmds) = dc
.collect {
case ExecCmd("RUN", "chown", _*) => ExecCmd("RUN", "chown", "-R", "daemon:root", ".")
case other => other
}
.splitAt(4)
dockerInitCmds ++
Seq(
Cmd("USER", "root"),
ExecCmd("RUN", "bash", "-c",
"apt-get update && " +
"apt-get install -y --no-install-recommends python-pip python2.7-dev ssdeep libfuzzy-dev libfuzzy2 libimage-exiftool-perl libmagic1 build-essential git && " +
"cd /opt && " +
"git clone https://github.com/CERT-BDF/Cortex-Analyzers.git && " +
"pip install $(sort -u Cortex-Analyzers/analyzers/*/requirements.txt) && " +
"apt-get install -y --no-install-recommends python3-setuptools python3-dev zlib1g-dev libxslt1-dev libxml2-dev libpq5 libjpeg-dev && git clone https://github.com/MISP/misp-modules.git && " +
"easy_install3 pip && " +
"(cd misp-modules && pip3 install -I -r REQUIREMENTS && pip3 install -I .) && " +
"rm -rf misp_modules /var/lib/apt/lists/* /tmp/*"),
Cmd("ADD", "var", "/var"),
Cmd("ADD", "etc", "/etc"),
ExecCmd("RUN", "chown", "-R", "daemon:root", "/var/log/cortex"),
ExecCmd("RUN", "chmod", "+x", "/opt/cortex/bin/cortex", "/opt/cortex/entrypoint", "/opt/cortex/contrib/misp-modules-loader.py")) ++
dockerTailCmds
}
// Bintray //
bintrayOrganization := Some("cert-bdf")
bintrayRepository := "cortex"
publish := {
(publish in Docker).value
PublishToBinTray.publishRelease.value
PublishToBinTray.publishLatest.value
PublishToBinTray.publishRpm.value
PublishToBinTray.publishDebian.value
}
// Scalariform //
import scalariform.formatter.preferences._
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
ScalariformKeys.preferences in ThisBuild := ScalariformKeys.preferences.value
.setPreference(AlignParameters, false)
// .setPreference(FirstParameterOnNewline, Force)
.setPreference(AlignArguments, true)
// .setPreference(FirstArgumentOnNewline, true)
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 60)
.setPreference(CompactControlReadability, true)
.setPreference(CompactStringConcatenation, false)
.setPreference(DoubleIndentClassDeclaration, true)
// .setPreference(DoubleIndentMethodDeclaration, true)
.setPreference(FormatXml, true)
.setPreference(IndentLocalDefs, false)
.setPreference(IndentPackageBlocks, false)
.setPreference(IndentSpaces, 2)
.setPreference(IndentWithTabs, false)
.setPreference(MultilineScaladocCommentsStartOnFirstLine, false)
// .setPreference(NewlineAtEndOfFile, true)
.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, false)
.setPreference(PreserveSpaceBeforeArguments, false)
// .setPreference(PreserveDanglingCloseParenthesis, false)
.setPreference(DanglingCloseParenthesis, Prevent)
.setPreference(RewriteArrowSymbols, true)
.setPreference(SpaceBeforeColon, false)
// .setPreference(SpaceBeforeContextColon, false)
.setPreference(SpaceInsideBrackets, false)
.setPreference(SpaceInsideParentheses, false)
.setPreference(SpacesWithinPatternBinders, true)
.setPreference(SpacesAroundMultiImports, true)