Skip to content

Commit

Permalink
Import: post ok, unzip ok, unserialize ok, save todo
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Jun 30, 2022
1 parent 1533f51 commit 5933812
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 315 deletions.
Expand Up @@ -940,7 +940,9 @@ object JsonResponseObjectDecodes extends RudderJsonDecoders {

implicit lazy val decodeJRParentProperty: JsonDecoder[JRParentProperty] = DeriveJsonDecoder.gen
implicit lazy val decodeJRPropertyHierarchy: JsonDecoder[JRPropertyHierarchy] = DeriveJsonDecoder.gen
implicit lazy val decodePropertyProvider: JsonDecoder[PropertyProvider] = DeriveJsonDecoder.gen
implicit lazy val decodePropertyProvider: JsonDecoder[PropertyProvider] = JsonDecoder.string.map(s =>
PropertyProvider(s)
)
implicit lazy val decodeJRProperty: JsonDecoder[JRProperty] = DeriveJsonDecoder.gen

implicit lazy val decodeJRCriterium: JsonDecoder[JRCriterium] = DeriveJsonDecoder.gen
Expand Down
Expand Up @@ -85,7 +85,7 @@ object RudderJsonResponse {

//////////////////////////// Lift JSON response ////////////////////////////

final case class RudderJsonResponse[A](json: A, prettify: Boolean, code: Int)(implicit encoder: JsonEncoder[A]) extends LiftResponse {
final case class LiftJsonResponse[A](json: A, prettify: Boolean, code: Int)(implicit encoder: JsonEncoder[A]) extends LiftResponse {
def toResponse = {
val indent = if(prettify) Some(2) else None
val bytes = encoder.encodeJson(json, indent).toString.getBytes("UTF-8")
Expand All @@ -109,10 +109,10 @@ object RudderJsonResponse {

object generic {
// generic response, not in rudder normalized format - use it if you want an ad-hoc json response.
def success[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = RudderJsonResponse(json, prettify, 200)
def internalError[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = RudderJsonResponse(json, prettify, 500)
def notFoundError[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = RudderJsonResponse(json, prettify, 404)
def forbiddenError[A](json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = RudderJsonResponse(json, prettify, 404)
def success[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = LiftJsonResponse(json, prettify, 200)
def internalError[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = LiftJsonResponse(json, prettify, 500)
def notFoundError[A] (json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = LiftJsonResponse(json, prettify, 404)
def forbiddenError[A](json: A)(implicit prettify: Boolean, encoder: JsonEncoder[A]) = LiftJsonResponse(json, prettify, 404)
}

trait DataContainer[A] {
Expand Down
Expand Up @@ -253,9 +253,6 @@ class ArchiveApi(
*/
def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = {

println(s"***** req params: " + req.params)
println(s"***** uploaded files: " + req.uploadedFiles.map(_.name))

def parseArchive(archive: FileParamHolder): IOResult[PolicyArchive] = {
val originalFilename = archive.fileName

Expand Down Expand Up @@ -570,10 +567,10 @@ class ZipArchiveReaderImpl(
) extends ZipArchiveReader {
import com.softwaremill.quicklens._

val techniqueRegex = """.+/techniques/(.+)""".r
val directiveRegex = """.+/directives/(.+.json)""".r
val groupRegex = """.+/groups/(.+.json)""".r
val ruleRegex = """.+/rules/(.+.json)""".r
val techniqueRegex = """.*techniques/(.+)""".r
val directiveRegex = """.*directives/(.+.json)""".r
val groupRegex = """.*groups/(.+.json)""".r
val ruleRegex = """.*rules/(.+.json)""".r

/*
* For technique, we are only looking for metadata.xml and parse it, other files are kept
Expand Down Expand Up @@ -650,12 +647,20 @@ class ZipArchiveReaderImpl(

// sort files in rules, directives, groups, techniques
val sortedEntries = zipEntries.foldLeft(SortedEntries.empty) { case (arch, (e, optContent)) => (e.getName, optContent) match {
case (techniqueRegex(x), Some(content)) => arch.modify(_.techniques).using( _ :+ (x, content))
case (directiveRegex(x), Some(content)) => arch.modify(_.directives).using( _ :+ (x, content))
case (groupRegex(x), Some(content)) => arch.modify(_.groups).using( _ :+ (x, content))
case (ruleRegex(x), Some(content)) => arch.modify(_.rules).using( _ :+ (x, content))
case (techniqueRegex(x), Some(content)) =>
ApplicationLoggerPure.Archive.logEffect.trace(s"Archive '${archiveName}': found technique file ${x}")
arch.modify(_.techniques).using( _ :+ (x, content))
case (directiveRegex(x), Some(content)) =>
ApplicationLoggerPure.Archive.logEffect.trace(s"Archive '${archiveName}': found directive file ${x}")
arch.modify(_.directives).using( _ :+ (x, content))
case (groupRegex(x), Some(content)) =>
ApplicationLoggerPure.Archive.logEffect.trace(s"Archive '${archiveName}': found group file ${x}")
arch.modify(_.groups).using( _ :+ (x, content))
case (ruleRegex(x), Some(content)) =>
ApplicationLoggerPure.Archive.logEffect.trace(s"Archive '${archiveName}': found rule file ${x}")
arch.modify(_.rules).using( _ :+ (x, content))
case (name, Some(_)) =>
ApplicationLoggerPure.Archive.logEffect.debug(s"Ignoring file '${name}' in archive '${archiveName}'")
ApplicationLoggerPure.Archive.logEffect.debug(s"Archive '${archiveName}': file does not matches a known category: ${name}")
arch
case (name, None) =>
ApplicationLoggerPure.Archive.logEffect.trace(s"Directory '${name}' in archive '${archiveName}': looking for entries")
Expand Down

0 comments on commit 5933812

Please sign in to comment.