Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions apps/cluster/src/Ingress/Labeling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { JanitorApi } from "@janitor/domain/Api"
import { describeCatalog } from "@janitor/domain/Labeling/Policy/Facts"
import * as Effect from "effect/Effect"
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"
import { ActivityReader } from "../Labeling/Activity.ts"
import { AiConsentService } from "../Labeling/Classifier.ts"
import { LabelingConfiguration } from "../Labeling/Configuration.ts"
import { LabelingOverview } from "../Labeling/Overview.ts"
import { LabelingRules } from "../Labeling/Rules.ts"
import { CurrentAccessIdentity } from "./Middleware.ts"

const catalog = describeCatalog()

/**
* Labeling across repositories. The services fail with `RepositoryNotFound`
* where an endpoint declares it; their infrastructure failures die.
*/
export const LabelingGroupLayer = HttpApiBuilder.group(JanitorApi, "labeling", (handlers) =>
handlers
.handle("listRepositories", () =>
LabelingOverview.use((overview) => overview.repositories).pipe(
Effect.catchTag("LabelingOverviewError", Effect.die),
),
)
.handle("getCatalog", () => Effect.succeed(catalog))
.handle("getConfiguration", ({ params }) =>
LabelingConfiguration.use((configuration) => configuration.view(params.repositoryId)).pipe(
Effect.catchTag("LabelingConfigurationError", Effect.die),
),
)
.handle("listActivity", ({ params, query }) =>
ActivityReader.use((reader) =>
reader.page(params.repositoryId, {
search: query.search ?? "",
target: query.target ?? "all",
cursor: query.cursor ?? null,
}),
).pipe(
Effect.catchTags({
LabelingConfigurationError: Effect.die,
SchemaError: Effect.die,
SqlError: Effect.die,
}),
),
)
.handle("listReconciliations", ({ params }) =>
LabelingOverview.use((overview) => overview.reconciliations(params.repositoryId)).pipe(
Effect.catchTag("LabelingOverviewError", Effect.die),
),
)
.handle("listAudit", ({ params }) =>
LabelingRules.use((rules) => rules.audit(params.repositoryId)),
)
.handle("getAiConsent", ({ params }) =>
Effect.gen(function* () {
yield* (yield* LabelingConfiguration).requireRepository(params.repositoryId)
return yield* (yield* AiConsentService).get(params.repositoryId)
}).pipe(
Effect.catchTags({ LabelingConfigurationError: Effect.die, AiConsentError: Effect.die }),
),
)
.handle("updateAiConsent", ({ params, payload }) =>
Effect.gen(function* () {
yield* (yield* LabelingConfiguration).requireRepository(params.repositoryId)
const identity = yield* CurrentAccessIdentity
return yield* (yield* AiConsentService).set(params.repositoryId, payload.enabled, {
issuer: identity.issuer,
subject: identity.subject,
})
}).pipe(
Effect.catchTags({ LabelingConfigurationError: Effect.die, AiConsentError: Effect.die }),
),
),
)
195 changes: 0 additions & 195 deletions apps/cluster/src/Ingress/LabelingRoutes.ts

This file was deleted.

7 changes: 3 additions & 4 deletions apps/cluster/src/Ingress/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RateLimitMiddlewareLayer,
} from "./Middleware.ts"
import { AccountGroupLayer } from "./Account.ts"
import { LabelingRoutesLayer } from "./LabelingRoutes.ts"
import { LabelingGroupLayer } from "./Labeling.ts"
import { ConnectionsGroupLayer } from "./Connections.ts"
import { SyncGroupLayer } from "./Sync.ts"
import { ReadinessRoutesLayer } from "./Readiness.ts"
Expand Down Expand Up @@ -44,6 +44,7 @@ const makeHttpApiLayer = (middleware: AccessMiddlewareOptions) =>
PoliciesGroupLayer,
RulesGroupLayer,
TestBenchGroupLayer,
LabelingGroupLayer,
),
),
Layer.provide(makeApiMiddlewareLayer(middleware)),
Expand All @@ -59,9 +60,7 @@ export const makeRoutesLayer = (secrets: IngressSecrets, middleware: AccessMiddl
Layer.mergeAll(
Layer.mergeAll(
makeGitHubWebHookRoutesLayer(secrets),
Layer.mergeAll(LiveRoutesLayer, LabelingRoutesLayer).pipe(
Layer.provide(makeAuthenticatedMiddlewareLayer(middleware)),
),
LiveRoutesLayer.pipe(Layer.provide(makeAuthenticatedMiddlewareLayer(middleware))),
ReadinessRoutesLayer.pipe(Layer.provide(makeAccessMiddlewareLayer(middleware))),
).pipe(Layer.provide(ApiRouterLayer)),
makeHttpApiLayer(middleware),
Expand Down
Loading