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 Feb 21, 2023
1 parent 8278771 commit 9d21745
Show file tree
Hide file tree
Showing 8 changed files with 9,980 additions and 10,260 deletions.
9 changes: 4 additions & 5 deletions daikoku/app/domain/apiEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,15 @@ case class AuthorizedEntities(services: Set[OtoroshiServiceId] = Set.empty,
case class ApiWithAuthorizations(api: Api,
authorizations: Seq[AuthorizationApi] =
Seq.empty)
case class ApiWithCount(apis: Seq[ApiWithAuthorizations],
result: Long)
case class ApiWithCount(apis: Seq[ApiWithAuthorizations], result: Long)
case class SubscriptionsWithPlan(planId: String,
isPending: Boolean,
subscriptionsCount: Int)
case class ApiWithSubscriptions(api: Api,
subscriptionsWithPlan: Seq[SubscriptionsWithPlan])
case class ApiWithSubscriptions(
api: Api,
subscriptionsWithPlan: Seq[SubscriptionsWithPlan])

case class AccessibleApisWithNumberOfApis(apis: Seq[ApiWithSubscriptions],
nb: Long)

case class AuthorizationApi(team: String, authorized: Boolean, pending: Boolean)

116 changes: 71 additions & 45 deletions daikoku/app/jobs/OtoroshiVerifierJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import cats.data.EitherT
import cats.syntax.option._
import controllers.AppError
import fr.maif.otoroshi.daikoku.audit.{ApiKeyRotationEvent, JobEvent}
import fr.maif.otoroshi.daikoku.domain.NotificationAction.{OtoroshiSyncApiError, OtoroshiSyncSubscriptionError}
import fr.maif.otoroshi.daikoku.domain.NotificationAction.{
OtoroshiSyncApiError,
OtoroshiSyncSubscriptionError
}
import fr.maif.otoroshi.daikoku.domain._
import fr.maif.otoroshi.daikoku.domain.json.ApiSubscriptionyRotationFormat
import fr.maif.otoroshi.daikoku.env.Env
Expand Down Expand Up @@ -178,69 +181,91 @@ class OtoroshiVerifierJob(client: OtoroshiClient,
def checkEntities(entities: AuthorizedEntities,
otoroshi: OtoroshiSettings,
api: Api): Future[Unit] = {
Future.sequence(entities.groups.map(
group =>
client
.getServiceGroup(group.value)(otoroshi)
.map(_ => ())
.andThen {
case Failure(_) =>
AppLogger.error(s"Unable to fetch service group $group from otoroshi. Maybe it doesn't exists anymore")
sendErrorNotification(
NotificationAction.OtoroshiSyncApiError(
api,
s"Unable to fetch service group $group from otoroshi. Maybe it doesn't exists anymore"),
api.team,
api.tenant
)
}) ++
entities.services.map(service =>
client
.getServices()(otoroshi)
.andThen {
case Failure(_) =>
AppLogger.error(s"Unable to fetch service $service from otoroshi. Maybe it doesn't exists anymore")
sendErrorNotification(
NotificationAction.OtoroshiSyncApiError(
api,
s"Unable to fetch service $service from otoroshi. Maybe it doesn't exists anymore"),
api.team,
api.tenant)
}) ++
entities.routes.map(
route =>
Future
.sequence(
entities.groups.map(group =>
client
.getRoutes()(otoroshi)
.getServiceGroup(group.value)(otoroshi)
.map(_ => ())
.andThen {
case Failure(_) =>
AppLogger.error(s"Unable to fetch route $route from otoroshi. Maybe it doesn't exists anymore")
AppLogger.error(
s"Unable to fetch service group $group from otoroshi. Maybe it doesn't exists anymore")
sendErrorNotification(
NotificationAction.OtoroshiSyncApiError(
api,
s"Unable to fetch route $route from otoroshi. Maybe it doesn't exists anymore"),
s"Unable to fetch service group $group from otoroshi. Maybe it doesn't exists anymore"),
api.team,
api.tenant)
})).map(_ => ())
api.tenant
)
}) ++
entities.services.map(service =>
client
.getServices()(otoroshi)
.andThen {
case Failure(_) =>
AppLogger.error(
s"Unable to fetch service $service from otoroshi. Maybe it doesn't exists anymore")
sendErrorNotification(
NotificationAction.OtoroshiSyncApiError(
api,
s"Unable to fetch service $service from otoroshi. Maybe it doesn't exists anymore"),
api.team,
api.tenant)
}) ++
entities.routes.map(route =>
client
.getRoutes()(otoroshi)
.andThen {
case Failure(_) =>
AppLogger.error(
s"Unable to fetch route $route from otoroshi. Maybe it doesn't exists anymore")
sendErrorNotification(
NotificationAction.OtoroshiSyncApiError(
api,
s"Unable to fetch route $route from otoroshi. Maybe it doesn't exists anymore"),
api.team,
api.tenant)
}))
.map(_ => ())
}

val par = 10
env.dataStore.apiRepo.forAllTenant().streamAllRawFormatted(Json.obj("_deleted" -> false) ++ query)
.mapAsync(par)(api => env.dataStore.tenantRepo.findByIdNotDeleted(api.tenant).map(tenant => (tenant, api)))
env.dataStore.apiRepo
.forAllTenant()
.streamAllRawFormatted(Json.obj("_deleted" -> false) ++ query)
.mapAsync(par)(api =>
env.dataStore.tenantRepo
.findByIdNotDeleted(api.tenant)
.map(tenant => (tenant, api)))
.collect {
case (Some(tenant), api) => (tenant, api)
}
.flatMapConcat {
case (tenant, api) => Source(api.possibleUsagePlans.map(plan => (tenant, api, plan)))
case (tenant, api) =>
Source(api.possibleUsagePlans.map(plan => (tenant, api, plan)))
}
.map {
case (tenant, api, plan) => (tenant, api, plan, tenant.otoroshiSettings.find(os => plan.otoroshiTarget.exists(ot => ot.otoroshiSettings == os.id)))
case (tenant, api, plan) =>
(tenant,
api,
plan,
tenant.otoroshiSettings.find(os =>
plan.otoroshiTarget.exists(ot => ot.otoroshiSettings == os.id)))
}
.collect {
case (tenant, api, plan, Some(settings)) if plan.otoroshiTarget.exists(_.authorizedEntities.exists(!_.isEmpty)) => (tenant, api, plan, settings)
case (tenant, api, plan, Some(settings))
if plan.otoroshiTarget.exists(
_.authorizedEntities.exists(!_.isEmpty)) =>
(tenant, api, plan, settings)
}
.mapAsync(par) {
case (_, api, plan, settings) => checkEntities(plan.otoroshiTarget.get.authorizedEntities.get, settings, api)
}.runWith(Sink.ignore)(env.defaultMaterializer)
case (_, api, plan, settings) =>
checkEntities(plan.otoroshiTarget.get.authorizedEntities.get,
settings,
api)
}
.runWith(Sink.ignore)(env.defaultMaterializer)
}

/**
Expand Down Expand Up @@ -393,7 +418,8 @@ class OtoroshiVerifierJob(client: OtoroshiClient,
api.team,
tenant.id)
)
user <- EitherT.fromOptionF(env.dataStore.userRepo.findById(sub.by), ())
user <- EitherT
.fromOptionF(env.dataStore.userRepo.findById(sub.by), ())
} yield {
val ctx: Map[String, String] = Map(
"user.id" -> user.id.value,
Expand Down
2 changes: 1 addition & 1 deletion daikoku/app/storage/api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait Repo[Of, Id <: ValueType] {
implicit ec: ExecutionContext): Source[JsValue, NotUsed]

def streamAllRawFormatted(query: JsObject = Json.obj())(
implicit ec: ExecutionContext): Source[Of, NotUsed]
implicit ec: ExecutionContext): Source[Of, NotUsed]

def find(query: JsObject, sort: Option[JsObject] = None, maxDocs: Int = -1)(
implicit ec: ExecutionContext): Future[Seq[Of]]
Expand Down
3 changes: 2 additions & 1 deletion daikoku/app/storage/drivers/mongo/MongoDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,8 @@ abstract class CommonMongoRepo[Of, Id <: ValueType](
.cursor[JsObject](ReadPreference.primaryPreferred)
.collect[Seq](maxDocs = -1, Cursor.FailOnError[Seq[JsObject]]())
})
.flatMapConcat(res => Source(res.toList.map(format.reads).filter(_.isSuccess).map(_.get)))
.flatMapConcat(res =>
Source(res.toList.map(format.reads).filter(_.isSuccess).map(_.get)))

override def findOne(query: JsObject)(
implicit ec: ExecutionContext): Future[Option[Of]] = collection.flatMap {
Expand Down
8 changes: 5 additions & 3 deletions daikoku/app/storage/drivers/postgres/PostgresDataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1390,8 +1390,9 @@ abstract class CommonRepo[Of, Id <: ValueType](env: Env, reactivePg: ReactivePg)
}

override def streamAllRawFormatted(query: JsObject = Json.obj())(
implicit ec: ExecutionContext): Source[Of, NotUsed] = {
logger.debug(s"$tableName.streamAllRawFormatted(${Json.prettyPrint(query)})")
implicit ec: ExecutionContext): Source[Of, NotUsed] = {
logger.debug(
s"$tableName.streamAllRawFormatted(${Json.prettyPrint(query)})")

Source
.future(
Expand All @@ -1400,7 +1401,8 @@ abstract class CommonRepo[Of, Id <: ValueType](env: Env, reactivePg: ReactivePg)
row.optJsObject("content")
}
)
.flatMapConcat(res => Source(res.toList.map(format.reads).filter(_.isSuccess).map(_.get)))
.flatMapConcat(res =>
Source(res.toList.map(format.reads).filter(_.isSuccess).map(_.get)))
}

override def findOne(query: JsObject)(
Expand Down
11 changes: 4 additions & 7 deletions daikoku/javascript/src/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { IFastTeam } from './team';

interface IBaseApi {
Expand Down Expand Up @@ -60,7 +59,7 @@ export interface IApi extends IBaseApi {
}*/

export interface IApiWithAuthorization {
api: IApiWithSimpleTeam
api: IApiWithSimpleTeam;
authorizations: Array<{
team: string;
authorized: boolean;
Expand All @@ -69,12 +68,10 @@ export interface IApiWithAuthorization {
}

export interface IApiAuthoWithCount {
apis: Array<IApiWithAuthorization>
result: number

apis: Array<IApiWithAuthorization>;
result: number;
}


export interface ITesting {
enabled: boolean;
auth: {
Expand Down Expand Up @@ -124,7 +121,7 @@ export interface IBaseUsagePlan {
customDescription?: string;
customName?: string;
subscriptionProcess: 'Automatic' | 'manual';
currency: ICurrency
currency: ICurrency;
otoroshiTarget?: IOtoroshiTarget;
}

Expand Down
Loading

0 comments on commit 9d21745

Please sign in to comment.