Skip to content

Commit

Permalink
Format sources before release
Browse files Browse the repository at this point in the history
  • Loading branch information
daikoku-github-actions committed Sep 13, 2024
1 parent ef1ed18 commit 836dfe4
Show file tree
Hide file tree
Showing 15 changed files with 652 additions and 434 deletions.
4 changes: 3 additions & 1 deletion daikoku/app/controllers/AdminApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ class StateAdminApiController(
AppError.SecurityError("Action not avalaible")
)
_ <- EitherT.liftF[Future, AppError, Unit](env.dataStore.clear())
_ <- EitherT.liftF[Future, AppError, Done](env.initDatastore(ctx.request.getQueryString("path")))
_ <- EitherT.liftF[Future, AppError, Done](
env.initDatastore(ctx.request.getQueryString("path"))
)
} yield Ok(Json.obj("done" -> true)))
.leftMap(_.render())
.merge
Expand Down
25 changes: 13 additions & 12 deletions daikoku/app/controllers/AppError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,19 @@ object AppError {
case ApiNotLinked => BadRequest(toJson(error))
case UserNotTeamAdmin(userId, teamId) =>
play.api.mvc.Results.Unauthorized(toJson(error))
case OtoroshiError(e) => BadRequest(e)
case PaymentError(_) => BadRequest(toJson(error))
case SubscriptionConflict => Conflict(toJson(error))
case ApiKeyRotationConflict => Conflict(toJson(error))
case EntityConflict(_) => Conflict(toJson(error))
case ApiKeyRotationError(e) => BadRequest(e)
case ForbiddenAction => Forbidden(toJson(error))
case ApiKeyCustomMetadataNotPrivided => BadRequest(toJson(error))
case SubscriptionNotFound => NotFound(toJson(error))
case SubscriptionParentExisted => Conflict(toJson(error))
case SubscriptionAggregationDisabled => BadRequest(toJson(error))
case EnvironmentSubscriptionAggregationDisabled => BadRequest(toJson(error))
case OtoroshiError(e) => BadRequest(e)
case PaymentError(_) => BadRequest(toJson(error))
case SubscriptionConflict => Conflict(toJson(error))
case ApiKeyRotationConflict => Conflict(toJson(error))
case EntityConflict(_) => Conflict(toJson(error))
case ApiKeyRotationError(e) => BadRequest(e)
case ForbiddenAction => Forbidden(toJson(error))
case ApiKeyCustomMetadataNotPrivided => BadRequest(toJson(error))
case SubscriptionNotFound => NotFound(toJson(error))
case SubscriptionParentExisted => Conflict(toJson(error))
case SubscriptionAggregationDisabled => BadRequest(toJson(error))
case EnvironmentSubscriptionAggregationDisabled =>
BadRequest(toJson(error))
case SubscriptionAggregationTeamConflict => Conflict(toJson(error))
case SubscriptionAggregationOtoroshiConflict => Conflict(toJson(error))
case MissingParentSubscription => NotFound(toJson(error))
Expand Down
42 changes: 25 additions & 17 deletions daikoku/app/domain/CommonServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,17 @@ object CommonServices {
ec: ExecutionContext
) = {

val typeFilter = if (ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> Json.obj("$ne" ->TeamType.Personal.name)
)
} else {
Json.obj()
}
val typeFilter =
if (
ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)
) {
Json.obj(
"type" -> Json.obj("$ne" -> TeamType.Personal.name)
)
} else {
Json.obj()
}
_UberPublicUserAccess(
AuditTrailEvent("@{user.name} has accessed his team list")
)(ctx) {
Expand All @@ -667,7 +670,9 @@ object CommonServices {
else
env.dataStore.teamRepo
.forTenant(ctx.tenant)
.findNotDeleted(Json.obj("users.userId" -> ctx.user.id.value) ++ typeFilter))
.findNotDeleted(
Json.obj("users.userId" -> ctx.user.id.value) ++ typeFilter
))
.map(teams =>
teams
.sortWith((a, b) => a.name.compareToIgnoreCase(b.name) < 0)
Expand All @@ -683,14 +688,17 @@ object CommonServices {
_TenantAdminAccessTenant(
AuditTrailEvent("@{user.name} has accessed to all teams list")
)(ctx) {
val typeFilter = if (ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> TeamType.Organization.name
)
} else {
Json.obj()
}
val typeFilter =
if (
ctx.tenant.subscriptionSecurity.isDefined
&& ctx.tenant.subscriptionSecurity.exists(identity)
) {
Json.obj(
"type" -> TeamType.Organization.name
)
} else {
Json.obj()
}
for {
teams <-
env.dataStore.teamRepo
Expand Down
3 changes: 2 additions & 1 deletion daikoku/app/domain/SchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ object SchemaDefinition {
Field(
"environmentAggregationApiKeysSecurity",
OptionType(BooleanType),
resolve = _.value.environmentAggregationApiKeysSecurity),
resolve = _.value.environmentAggregationApiKeysSecurity
),
Field(
"display",
OptionType(StringType),
Expand Down
3 changes: 2 additions & 1 deletion daikoku/app/domain/apikeyEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ case class ApiSubscriptionTransfer(
token: String,
subscription: ApiSubscriptionId,
date: DateTime,
by: UserId) extends CanJson[ApiSubscriptionTransfer] {
by: UserId
) extends CanJson[ApiSubscriptionTransfer] {
override def asJson: JsValue = json.ApiSubscriptionTransferFormat.writes(this)
}
50 changes: 28 additions & 22 deletions daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ object json {
otoroshiTarget =
(json \ "otoroshiTarget").asOpt(OtoroshiTargetFormat),
aggregationApiKeysSecurity =
(json \ "aggregationApiKeysSecurity").asOpt[Boolean],
(json \ "aggregationApiKeysSecurity").asOpt[Boolean]
)
)
} recover {
Expand Down Expand Up @@ -2202,8 +2202,9 @@ object json {
tenantMode = (json \ "tenantMode").asOpt(TenantModeFormat),
aggregationApiKeysSecurity = (json \ "aggregationApiKeysSecurity")
.asOpt[Boolean],
environmentAggregationApiKeysSecurity = (json \ "environmentAggregationApiKeysSecurity")
.asOpt[Boolean],
environmentAggregationApiKeysSecurity =
(json \ "environmentAggregationApiKeysSecurity")
.asOpt[Boolean],
robotTxt = (json \ "robotTxt").asOpt[String],
thirdPartyPaymentSettings = (json \ "thirdPartyPaymentSettings")
.asOpt(SeqThirdPartyPaymentSettingsFormat)
Expand Down Expand Up @@ -3219,7 +3220,8 @@ object json {
case "NewIssueOpen" => NewIssueOpenFormat.reads(json)
case "NewCommentOnIssue" => NewCommentOnIssueFormat.reads(json)
case "TransferApiOwnership" => TransferApiOwnershipFormat.reads(json)
case "ApiSubscriptionTransferSuccess" => ApiSubscriptionTransferSuccessFormat.reads(json)
case "ApiSubscriptionTransferSuccess" =>
ApiSubscriptionTransferSuccessFormat.reads(json)
case "CheckoutForSubscription" =>
CheckoutForSubscriptionFormat.reads(json)
case str => JsError(s"Bad notification value: $str")
Expand All @@ -3240,9 +3242,10 @@ object json {
"type" -> "ApiSubscription"
)
case p: ApiSubscriptionTransferSuccess =>
ApiSubscriptionTransferSuccessFormat.writes(p).as[JsObject] ++ Json.obj(
"type" -> "ApiSubscriptionTransferSuccess"
)
ApiSubscriptionTransferSuccessFormat.writes(p).as[JsObject] ++ Json
.obj(
"type" -> "ApiSubscriptionTransferSuccess"
)
case p: ApiSubscriptionReject =>
ApiSubscriptionRejectFormat.writes(p).as[JsObject] ++ Json.obj(
"type" -> "ApiSubscriptionReject"
Expand Down Expand Up @@ -3486,24 +3489,27 @@ object json {
.as[JsValue]
)
}
val ApiSubscriptionTransferSuccessFormat = new Format[ApiSubscriptionTransferSuccess] {
val ApiSubscriptionTransferSuccessFormat =
new Format[ApiSubscriptionTransferSuccess] {

override def reads(json: JsValue): JsResult[ApiSubscriptionTransferSuccess] =
Try {
JsSuccess(
ApiSubscriptionTransferSuccess(
subscription = (json \ "subscription").as(ApiSubscriptionIdFormat)
override def reads(
json: JsValue
): JsResult[ApiSubscriptionTransferSuccess] =
Try {
JsSuccess(
ApiSubscriptionTransferSuccess(
subscription = (json \ "subscription").as(ApiSubscriptionIdFormat)
)
)
)
} recover {
case e => JsError(e.getMessage)
} get
} recover {
case e => JsError(e.getMessage)
} get

override def writes(o: ApiSubscriptionTransferSuccess): JsValue =
Json.obj(
"subscription" -> o.subscription.asJson
)
}
override def writes(o: ApiSubscriptionTransferSuccess): JsValue =
Json.obj(
"subscription" -> o.subscription.asJson
)
}
val ApiSubscriptionRejectFormat = new Format[ApiSubscriptionReject] {
override def reads(json: JsValue): JsResult[ApiSubscriptionReject] =
Try {
Expand Down
2 changes: 1 addition & 1 deletion daikoku/app/domain/teamEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ object NotificationAction {
) extends NotificationAction

case class ApiSubscriptionTransferSuccess(
subscription: ApiSubscriptionId,
subscription: ApiSubscriptionId
) extends NotificationAction

case class OtoroshiSyncSubscriptionError(
Expand Down
10 changes: 7 additions & 3 deletions daikoku/app/env/env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ sealed trait Env {

def getDaikokuUrl(tenant: Tenant, path: String): String

def initDatastore(path: Option[String]= None)(implicit ec: ExecutionContext): Future[Done]
def initDatastore(path: Option[String] = None)(implicit
ec: ExecutionContext
): Future[Done]
}

class DaikokuEnv(
Expand Down Expand Up @@ -376,14 +378,16 @@ class DaikokuEnv(
}
}

override def initDatastore(path: Option[String]=None)(implicit ec: ExecutionContext): Future[Done] = {
override def initDatastore(
path: Option[String] = None
)(implicit ec: ExecutionContext): Future[Done] = {
def run(isEmpty: Boolean): Future[Unit] = {
if (isEmpty) {
(dataStore match {
case store: PostgresDataStore => store.checkDatabase()
case _ => FastFuture.successful(None)
}).map { _ =>
path.orElse(config.init.data.from) match {
path.orElse(config.init.data.from) match {
case Some(path)
if path.startsWith("http://") || path
.startsWith("https://") =>
Expand Down
25 changes: 14 additions & 11 deletions daikoku/app/storage/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,32 @@ trait UserRepo extends Repo[User, UserId]
trait EvolutionRepo extends Repo[Evolution, DatastoreId]
trait ReportsInfoRepo extends Repo[ReportsInfo, DatastoreId]

trait ApiSubscriptionTransferRepo extends TenantCapableRepo[ApiSubscriptionTransfer, DatastoreId]
trait ApiSubscriptionTransferRepo
extends TenantCapableRepo[ApiSubscriptionTransfer, DatastoreId]

trait TeamRepo extends TenantCapableRepo[Team, TeamId] {
def myTeams(tenant: Tenant, user: User)(implicit
env: Env,
ec: ExecutionContext
): Future[Seq[Team]] = {
val typeFilter = if (tenant.subscriptionSecurity.isDefined
&& tenant.subscriptionSecurity.exists(identity)) {
Json.obj(
"type" -> Json.obj("$ne" -> TeamType.Personal.name)
)
} else {
Json.obj()
}
val typeFilter =
if (
tenant.subscriptionSecurity.isDefined
&& tenant.subscriptionSecurity.exists(identity)
) {
Json.obj(
"type" -> Json.obj("$ne" -> TeamType.Personal.name)
)
} else {
Json.obj()
}
if (user.isDaikokuAdmin) {
env.dataStore.teamRepo
.forTenant(tenant.id)
.findNotDeleted(
typeFilter
typeFilter
)


} else {
env.dataStore.teamRepo
.forTenant(tenant.id)
Expand Down
39 changes: 29 additions & 10 deletions daikoku/app/storage/drivers/postgres/PostgresDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,14 @@ case class PostgresTenantCapableUsagePlanRepo(

case class PostgresTenantCapableApiSubscriptionTransferRepo(
_repo: () => PostgresRepo[ApiSubscriptionTransfer, DatastoreId],
_tenantRepo: TenantId => PostgresTenantAwareRepo[ApiSubscriptionTransfer, DatastoreId]
_tenantRepo: TenantId => PostgresTenantAwareRepo[
ApiSubscriptionTransfer,
DatastoreId
]
) extends PostgresTenantCapableRepo[ApiSubscriptionTransfer, DatastoreId]
with ApiSubscriptionTransferRepo {
override def repo(): PostgresRepo[ApiSubscriptionTransfer, DatastoreId] = _repo()
override def repo(): PostgresRepo[ApiSubscriptionTransfer, DatastoreId] =
_repo()

override def tenantRepo(
tenant: TenantId
Expand Down Expand Up @@ -686,7 +690,8 @@ class PostgresDataStore(configuration: Configuration, env: Env, pgPool: PgPool)

override def usagePlanRepo: UsagePlanRepo = _usagePlanRepo

override def apiSubscriptionTransferRepo: ApiSubscriptionTransferRepo = _apiSubscriptionTransferRepo
override def apiSubscriptionTransferRepo: ApiSubscriptionTransferRepo =
_apiSubscriptionTransferRepo

override def start(): Future[Unit] = {
Future.successful(())
Expand Down Expand Up @@ -1135,14 +1140,23 @@ class PostgresTenantUsagePlanRepo(
override def extractId(value: UsagePlan): String = value.id.value
}

class PostgresTenantApiSubscriptionTransferRepo(env: Env, reactivePg: ReactivePg, tenant: TenantId)
extends PostgresTenantAwareRepo[ApiSubscriptionTransfer, DatastoreId](env, reactivePg, tenant) {
class PostgresTenantApiSubscriptionTransferRepo(
env: Env,
reactivePg: ReactivePg,
tenant: TenantId
) extends PostgresTenantAwareRepo[ApiSubscriptionTransfer, DatastoreId](
env,
reactivePg,
tenant
) {

override def tableName: String = "api_subscription_transfers"

override def format: Format[ApiSubscriptionTransfer] = json.ApiSubscriptionTransferFormat
override def format: Format[ApiSubscriptionTransfer] =
json.ApiSubscriptionTransferFormat

override def extractId(value: ApiSubscriptionTransfer): String = value.id.value
override def extractId(value: ApiSubscriptionTransfer): String =
value.id.value
}

class PostgresTenantCmsPageRepo(
Expand Down Expand Up @@ -1410,12 +1424,17 @@ class PostgresUsagePlanRepo(env: Env, reactivePg: ReactivePg)
}

class PostgresApiSubscriptionTransferRepo(env: Env, reactivePg: ReactivePg)
extends PostgresRepo[ApiSubscriptionTransfer, DatastoreId](env, reactivePg) {
extends PostgresRepo[ApiSubscriptionTransfer, DatastoreId](
env,
reactivePg
) {
override def tableName: String = "api_subscription_transfers"

override def format: Format[ApiSubscriptionTransfer] = json.ApiSubscriptionTransferFormat
override def format: Format[ApiSubscriptionTransfer] =
json.ApiSubscriptionTransferFormat

override def extractId(value: ApiSubscriptionTransfer): String = value.id.value
override def extractId(value: ApiSubscriptionTransfer): String =
value.id.value
}

class PostgresApiRepo(env: Env, reactivePg: ReactivePg)
Expand Down
Loading

0 comments on commit 836dfe4

Please sign in to comment.