Skip to content

Commit

Permalink
Merge branch 'ust_24475/api_account_ui_needs_to_provide_a_configurati…
Browse files Browse the repository at this point in the history
…on_for_tenants_pr' into branches/rudder/8.1
  • Loading branch information
Jenkins CI committed Mar 19, 2024
2 parents 1c83c9c + 9005f94 commit 25666ee
Show file tree
Hide file tree
Showing 15 changed files with 1,128 additions and 630 deletions.
Expand Up @@ -59,5 +59,6 @@ final case class ModifyApiAccountDiff(
modExpirationDate: Option[SimpleDiff[Option[DateTime]]] = None,
modAPIKind: Option[SimpleDiff[String]] = None,
modAccountKind: Option[SimpleDiff[String]] = None,
modAccountAcl: Option[SimpleDiff[List[ApiAclElement]]] = None
modAccountAcl: Option[SimpleDiff[List[ApiAclElement]]] = None,
modAPITenants: Option[SimpleDiff[String]] = None
) extends ApiAccountDiff
Expand Up @@ -683,7 +683,8 @@ object ApiAccountSerialisation {
(expirationDate.map(DateFormaterService.getDisplayDateTimePicker), Some(authz.kind.name), acl)
}
}
("id" -> account.id.value) ~

("id" -> account.id.value) ~
("name" -> account.name.value) ~
("token" -> account.token.value) ~
("tokenGenerationDate" -> DateFormaterService.serialize(account.tokenGenerationDate)) ~
Expand All @@ -694,7 +695,8 @@ object ApiAccountSerialisation {
("expirationDate" -> expirationDate) ~
("expirationDateDefined" -> expirationDate.isDefined) ~
("authorizationType" -> authzType) ~
("acl" -> acl.map(x => Extraction.decompose(x)))
("acl" -> acl.map(x => Extraction.decompose(x))) ~
("tenants" -> account.tenants.serialize)
}
}
}
Expand Up @@ -653,6 +653,10 @@ class LDAPDiffMapper(
} yield {
d.copy(modAccountAcl = Some(SimpleDiff(oldAcl, acl)))
}
case A_API_TENANT =>
diff.map(
_.copy(modAPITenants = Some(SimpleDiff(oldAccount.tenants.serialize, mod.getOptValueDefault("-"))))
)

case x => Left(Err.UnexpectedObject("Unknown diff attribute: " + x))
}
Expand Down
Expand Up @@ -1144,6 +1144,7 @@ class LDAPEntityMapper(
mod.resetValuesTo(A_DESCRIPTION, principal.description)
mod.resetValuesTo(A_IS_ENABLED, principal.isEnabled.toLDAPString)
mod.resetValuesTo(A_API_KIND, principal.kind.kind.name)
mod.resetValuesTo(A_API_TENANT, principal.tenants.serialize)

principal.kind match {
case ApiAccountKind.PublicApi(authz, exp) =>
Expand Down
Expand Up @@ -1059,8 +1059,7 @@ final case class RestExtractorService(
expirationValue <- extractJsonString(json, "expirationDate", DateFormaterService.parseDateTimePicker(_).toBox)
authType <- extractJsonString(json, "authorizationType", ApiAuthorizationKind.parse)
tenants <- extractJsonString(json, "tenants", s => NodeSecurityContext.parse(Some(s)).toBox)

acl <- extractJsonArray(json, "acl")((extractApiACLFromJSON _)).map(_.getOrElse(Nil))
acl <- extractJsonArray(json, "acl")((extractApiACLFromJSON _)).map(_.getOrElse(Nil))
} yield {

val auth = authType match {
Expand Down
Expand Up @@ -302,15 +302,16 @@ final case class RestApiAccount(

// Id cannot change if already defined
def update(account: ApiAccount): ApiAccount = {
val nameUpdate = name.getOrElse(account.name)
val enableUpdate = enabled.getOrElse(account.isEnabled)
val descUpdate = description.getOrElse(account.description)
val kind = account.kind match {
val nameUpdate = name.getOrElse(account.name)
val enableUpdate = enabled.getOrElse(account.isEnabled)
val descUpdate = description.getOrElse(account.description)
val tenantsUpdate = tenants.getOrElse(account.tenants)
val kind = account.kind match {
case ApiAccountKind.PublicApi(a, e) =>
ApiAccountKind.PublicApi(authz.getOrElse(a), expiration.getOrElse(e))
case x => x
}

account.copy(name = nameUpdate, isEnabled = enableUpdate, description = descUpdate, kind = kind)
account.copy(name = nameUpdate, isEnabled = enableUpdate, description = descUpdate, kind = kind, tenants = tenantsUpdate)
}
}
Expand Up @@ -181,15 +181,18 @@ trait TraitTestApiFromYamlFiles extends Specification with BoxSpecMatcher with J
// file are copier directly into destDir
def copyTransform(orig: Path, destDir: File): IOResult[(String, IOManaged[InputStream])] = {
// for now, nothing more
val name = orig.getFileName.toString
val dest = destDir / name
for {
f <- IOResult
.attempt(Resource.asString(orig.toString).map(s => dest.write(transform(name, s))))
.notOptional(s"Missing source file: ${orig}")
} yield {
(name, ZIO.acquireRelease(IOResult.attempt(f.newInputStream))(is => effectUioUnit(is.close())))
}
val name = orig.getFileName.toString
val dest = destDir / name
val emptyManaged = IOManaged.make("".inputStream)(is => effectUioUnit(is.close()))

IOResult
.attempt(Resource.asString(orig.toString).map(s => dest.write(transform(name, s))))
.option
.flatMap {
case Some(Some(f)) =>
(name, ZIO.acquireRelease(IOResult.attempt(f.newInputStream))(is => effectUioUnit(is.close()))).succeed
case _ => effectUioUnit(println(s"Ignoring missing file: ${orig}")) *> (name, emptyManaged).succeed
}
}

// the list anyref here is Yaml objects
Expand Down

0 comments on commit 25666ee

Please sign in to comment.