Skip to content

Commit

Permalink
Update documentation before release
Browse files Browse the repository at this point in the history
  • Loading branch information
daikoku-github-actions committed Dec 2, 2021
1 parent 64c6a17 commit 27f7139
Show file tree
Hide file tree
Showing 81 changed files with 1,241 additions and 1,026 deletions.
11 changes: 7 additions & 4 deletions daikoku/app/actions/actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ object tenantSecurity {

}

case class DaikokuTenantActionContext[A](request: Request[A], tenant: Tenant, ctx: TrieMap[String, String] = new TrieMap[String, String]()) {
case class DaikokuTenantActionContext[A](request: Request[A],
tenant: Tenant,
ctx: TrieMap[String, String] =
new TrieMap[String, String]()) {
def setCtxValue(key: String, value: Any): Unit = {
if (value != null) {
ctx.put(key, value.toString)
Expand Down Expand Up @@ -337,9 +340,9 @@ class DaikokuTenantAction(val parser: BodyParser[AnyContent], env: Env)
implicit lazy val ec: ExecutionContext = env.defaultExecutionContext

override def invokeBlock[A](
request: Request[A],
block: DaikokuTenantActionContext[A] => Future[Result])
: Future[Result] = {
request: Request[A],
block: DaikokuTenantActionContext[A] => Future[Result])
: Future[Result] = {
request.attrs.get(IdentityAttrs.TenantKey) match {
case Some(tenant) => block(DaikokuTenantActionContext[A](request, tenant))
case None =>
Expand Down
44 changes: 27 additions & 17 deletions daikoku/app/controllers/AssetsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import akka.http.scaladsl.util.FastFuture
import akka.stream.alpakka.s3.ObjectMetadata
import akka.stream.scaladsl.Source
import akka.util.ByteString
import fr.maif.otoroshi.daikoku.actions.{DaikokuAction, DaikokuActionMaybeWithGuest, DaikokuTenantAction}
import fr.maif.otoroshi.daikoku.actions.{
DaikokuAction,
DaikokuActionMaybeWithGuest,
DaikokuTenantAction
}
import fr.maif.otoroshi.daikoku.audit.AuditTrailEvent
import fr.maif.otoroshi.daikoku.ctrls.authorizations.async._
import fr.maif.otoroshi.daikoku.domain.AssetId
Expand All @@ -14,7 +18,12 @@ import fr.maif.otoroshi.daikoku.utils.IdGenerator
import play.api.http.HttpEntity
import play.api.libs.json.{JsArray, Json}
import play.api.libs.streams.Accumulator
import play.api.mvc.{AbstractController, Action, BodyParser, ControllerComponents}
import play.api.mvc.{
AbstractController,
Action,
BodyParser,
ControllerComponents
}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration.DurationInt
Expand Down Expand Up @@ -476,34 +485,35 @@ class TenantAssetsController(DaikokuAction: DaikokuAction,
.getOrElse("asset.txt")

Ok.sendEntity(
HttpEntity.Streamed(
source,
None,
meta.contentType
.map(Some.apply)
.getOrElse(Some("application/octet-stream"))))
HttpEntity.Streamed(
source,
None,
meta.contentType
.map(Some.apply)
.getOrElse(Some("application/octet-stream"))))
.withHeaders(
"Content-Disposition" -> s"""attachment; filename="$filename"""")
}
case Some(url) =>
env.wsClient.url(url)
env.wsClient
.url(url)
.withRequestTimeout(10.minutes)
.get()
.map(resp => {
resp.status match {
case 200 => Ok.sendEntity(
HttpEntity.Streamed(
resp.bodyAsSource,
None,
Option(resp.contentType)))
case _ => NotFound(Json.obj("error" -> "Asset not found!"))
case 200 =>
Ok.sendEntity(
HttpEntity.Streamed(resp.bodyAsSource,
None,
Option(resp.contentType)))
case _ => NotFound(Json.obj("error" -> "Asset not found!"))
}
})
.recover {
case err => InternalServerError(Json.obj("error" -> err.getMessage))
case err =>
InternalServerError(Json.obj("error" -> err.getMessage))
}


}
}
}
Expand Down
193 changes: 110 additions & 83 deletions daikoku/app/controllers/EntitiesController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,91 +177,118 @@ class EntitiesController(DaikokuAction: DaikokuAction,
}
}

def newPlan(planType: String): Action[AnyContent] = DaikokuAction.async { ctx =>
PublicUserAccess(
AuditTrailEvent(s"@{user.name} has asked for a template entity of type Plan"))(ctx) {
def newPlan(planType: String): Action[AnyContent] = DaikokuAction.async {
ctx =>
PublicUserAccess(
AuditTrailEvent(
s"@{user.name} has asked for a template entity of type Plan"))(ctx) {
planType match {
case "Admin" => Ok(UsagePlan.Admin(id = UsagePlanId(BSONObjectID.generate().stringify), otoroshiTarget = None).asJson)
case "PayPerUse" => Ok(UsagePlan.PayPerUse(
id = UsagePlanId(BSONObjectID.generate().stringify),
BigDecimal(0),
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
visibility = Private,
autoRotation = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey
).asJson)
case "FreeWithQuotas" => Ok(UsagePlan.FreeWithQuotas(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
).asJson)
case "FreeWithoutQuotas" => Ok(UsagePlan.FreeWithoutQuotas(
id = UsagePlanId(BSONObjectID.generate().stringify),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
).asJson)
case "QuotasWithLimits" => Ok(UsagePlan.QuotasWithLimits(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
).asJson)
case "QuotasWithoutLimits" => Ok(UsagePlan.QuotasWithoutLimits(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
BigDecimal(0),
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(true),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
).asJson)
case "Admin" =>
Ok(
UsagePlan
.Admin(id = UsagePlanId(BSONObjectID.generate().stringify),
otoroshiTarget = None)
.asJson)
case "PayPerUse" =>
Ok(
UsagePlan
.PayPerUse(
id = UsagePlanId(BSONObjectID.generate().stringify),
BigDecimal(0),
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
visibility = Private,
autoRotation = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey
)
.asJson)
case "FreeWithQuotas" =>
Ok(
UsagePlan
.FreeWithQuotas(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
)
.asJson)
case "FreeWithoutQuotas" =>
Ok(
UsagePlan
.FreeWithoutQuotas(
id = UsagePlanId(BSONObjectID.generate().stringify),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
)
.asJson)
case "QuotasWithLimits" =>
Ok(
UsagePlan
.QuotasWithLimits(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(false),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
)
.asJson)
case "QuotasWithoutLimits" =>
Ok(
UsagePlan
.QuotasWithoutLimits(
id = UsagePlanId(BSONObjectID.generate().stringify),
0,
0,
0,
BigDecimal(0),
BigDecimal(0),
billingDuration = BillingDuration(1, BillingTimeUnit.Month),
trialPeriod = None,
currency = Currency("EUR"),
customName = None,
customDescription = None,
otoroshiTarget = None,
allowMultipleKeys = Some(true),
subscriptionProcess = SubscriptionProcess.Automatic,
integrationProcess = IntegrationProcess.ApiKey,
autoRotation = Some(false)
)
.asJson)
case _ => BadRequest(Json.obj("error" -> "Unrecognized type of plan"))
}
}
}
}
}
2 changes: 1 addition & 1 deletion daikoku/app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HomeController(
case _ if ctx.request.uri.startsWith("/robot.txt") =>
ctx.tenant.robotTxt match {
case Some(robotTxt) => Ok(views.txt.robot.render(robotTxt));
case None => NotFound(Json.obj("error" -> "robot.txt not found"))
case None => NotFound(Json.obj("error" -> "robot.txt not found"))
}
case Some(_) =>
Ok(
Expand Down
Loading

0 comments on commit 27f7139

Please sign in to comment.