refactor(automate): logs api can get the projectId from the path
This commit is contained in:
Родитель
42db2f6b82
Коммит
ad95362146
|
@ -1,12 +1,10 @@
|
|||
import { db } from '@/db/knex'
|
||||
import { getAutomationRunLogs } from '@/modules/automate/clients/executionEngine'
|
||||
import { ExecutionEngineFailedResponseError } from '@/modules/automate/errors/executionEngine'
|
||||
import {
|
||||
getAutomationProjectFactory,
|
||||
getAutomationRunWithTokenFactory
|
||||
} from '@/modules/automate/repositories/automations'
|
||||
import { getAutomationRunWithTokenFactory } from '@/modules/automate/repositories/automations'
|
||||
import { corsMiddleware } from '@/modules/core/configs/cors'
|
||||
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
||||
import { getProjectDbClient } from '@/modules/multiregion/dbSelector'
|
||||
import {
|
||||
validateRequiredStreamFactory,
|
||||
validateResourceAccess,
|
||||
|
@ -21,7 +19,7 @@ import { Application } from 'express'
|
|||
|
||||
export default (app: Application) => {
|
||||
app.get(
|
||||
'/api/automate/automations/:automationId/runs/:runId/logs',
|
||||
'/api/v1/projects/:projectId/automations/:automationId/runs/:runId/logs',
|
||||
corsMiddleware(),
|
||||
authMiddlewareCreator([
|
||||
validateServerRoleBuilderFactory({
|
||||
|
@ -29,8 +27,7 @@ export default (app: Application) => {
|
|||
})({ requiredRole: Roles.Server.Guest }),
|
||||
validateScope({ requiredScope: Scopes.Streams.Read }),
|
||||
validateRequiredStreamFactory({
|
||||
getStream: getStreamFactory({ db }),
|
||||
getAutomationProject: getAutomationProjectFactory({ db })
|
||||
getStream: getStreamFactory({ db })
|
||||
}),
|
||||
validateStreamRoleBuilderFactory({ getRoles: getRolesFactory({ db }) })({
|
||||
requiredRole: Roles.Stream.Owner
|
||||
|
@ -38,10 +35,14 @@ export default (app: Application) => {
|
|||
validateResourceAccess
|
||||
]),
|
||||
async (req, res) => {
|
||||
// get the projecDb this way
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.projectId })
|
||||
const automationId = req.params.automationId
|
||||
const runId = req.params.runId
|
||||
|
||||
const getAutomationRunWithToken = getAutomationRunWithTokenFactory({ db })
|
||||
const getAutomationRunWithToken = getAutomationRunWithTokenFactory({
|
||||
db: projectDb
|
||||
})
|
||||
const run = await getAutomationRunWithToken({
|
||||
automationId,
|
||||
automationRunId: runId
|
||||
|
|
|
@ -42,13 +42,11 @@ import {
|
|||
fullyDeleteBlobFactory
|
||||
} from '@/modules/blobstorage/services/management'
|
||||
import { getRolesFactory } from '@/modules/shared/repositories/roles'
|
||||
import { getAutomationProjectFactory } from '@/modules/automate/repositories/automations'
|
||||
import { adminOverrideEnabled } from '@/modules/shared/helpers/envHelper'
|
||||
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
||||
import { Request, Response } from 'express'
|
||||
import { ensureError } from '@speckle/shared'
|
||||
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
|
||||
import { Knex } from 'knex'
|
||||
import { getProjectDbClient } from '@/modules/multiregion/dbSelector'
|
||||
|
||||
const ensureConditions = async () => {
|
||||
|
@ -89,26 +87,23 @@ const errorHandler: ErrorHandler = async (req, res, callback) => {
|
|||
|
||||
export const init: SpeckleModule['init'] = async (app) => {
|
||||
await ensureConditions()
|
||||
const createStreamWritePermissions = ({ projectDb }: { projectDb: Knex }) =>
|
||||
const createStreamWritePermissions = () =>
|
||||
streamWritePermissionsPipelineFactory({
|
||||
getRoles: getRolesFactory({ db }),
|
||||
getStream: getStreamFactory({ db }),
|
||||
getAutomationProject: getAutomationProjectFactory({ db: projectDb })
|
||||
getStream: getStreamFactory({ db })
|
||||
})
|
||||
const createStreamReadPermissions = ({ projectDb }: { projectDb: Knex }) =>
|
||||
const createStreamReadPermissions = () =>
|
||||
streamReadPermissionsPipelineFactory({
|
||||
adminOverrideEnabled,
|
||||
getRoles: getRolesFactory({ db }),
|
||||
getStream: getStreamFactory({ db }),
|
||||
getAutomationProject: getAutomationProjectFactory({ db: projectDb })
|
||||
getStream: getStreamFactory({ db })
|
||||
})
|
||||
|
||||
app.post(
|
||||
'/api/stream/:streamId/blob',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator([
|
||||
...createStreamWritePermissions({ projectDb }),
|
||||
...createStreamWritePermissions(),
|
||||
// todo should we add public comments upload escape hatch?
|
||||
allowForAllRegisteredUsersOnPublicStreamsWithPublicComments
|
||||
])(req, res, next)
|
||||
|
@ -243,9 +238,8 @@ export const init: SpeckleModule['init'] = async (app) => {
|
|||
app.post(
|
||||
'/api/stream/:streamId/blob/diff',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator([
|
||||
...createStreamReadPermissions({ projectDb }),
|
||||
...createStreamReadPermissions(),
|
||||
allowForAllRegisteredUsersOnPublicStreamsWithPublicComments,
|
||||
allowForRegisteredUsersOnPublicStreamsEvenWithoutRole,
|
||||
allowAnonymousUsersOnPublicStreams
|
||||
|
@ -272,9 +266,8 @@ export const init: SpeckleModule['init'] = async (app) => {
|
|||
app.get(
|
||||
'/api/stream/:streamId/blob/:blobId',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator([
|
||||
...createStreamReadPermissions({ projectDb }),
|
||||
...createStreamReadPermissions(),
|
||||
allowForAllRegisteredUsersOnPublicStreamsWithPublicComments,
|
||||
allowForRegisteredUsersOnPublicStreamsEvenWithoutRole,
|
||||
allowAnonymousUsersOnPublicStreams
|
||||
|
@ -307,12 +300,7 @@ export const init: SpeckleModule['init'] = async (app) => {
|
|||
app.delete(
|
||||
'/api/stream/:streamId/blob/:blobId',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator(createStreamReadPermissions({ projectDb }))(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
)
|
||||
await authMiddlewareCreator(createStreamReadPermissions())(req, res, next)
|
||||
},
|
||||
async (req, res) => {
|
||||
errorHandler(req, res, async (req, res) => {
|
||||
|
@ -335,12 +323,7 @@ export const init: SpeckleModule['init'] = async (app) => {
|
|||
app.get(
|
||||
'/api/stream/:streamId/blobs',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator(createStreamReadPermissions({ projectDb }))(
|
||||
req,
|
||||
res,
|
||||
next
|
||||
)
|
||||
await authMiddlewareCreator(createStreamReadPermissions())(req, res, next)
|
||||
},
|
||||
async (req, res) => {
|
||||
let fileName = req.query.fileName
|
||||
|
|
|
@ -17,7 +17,6 @@ import { publish } from '@/modules/shared/utils/subscriptions'
|
|||
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
|
||||
import { streamWritePermissionsPipelineFactory } from '@/modules/shared/authz'
|
||||
import { getRolesFactory } from '@/modules/shared/repositories/roles'
|
||||
import { getAutomationProjectFactory } from '@/modules/automate/repositories/automations'
|
||||
import { getStreamBranchByNameFactory } from '@/modules/core/repositories/branches'
|
||||
import { getStreamFactory } from '@/modules/core/repositories/streams'
|
||||
import { addBranchCreatedActivityFactory } from '@/modules/activitystream/services/branchActivity'
|
||||
|
@ -37,12 +36,10 @@ export const init: SpeckleModule['init'] = async (app, isInitial) => {
|
|||
app.post(
|
||||
'/api/file/:fileType/:streamId/:branchName?',
|
||||
async (req, res, next) => {
|
||||
const projectDb = await getProjectDbClient({ projectId: req.params.streamId })
|
||||
await authMiddlewareCreator(
|
||||
streamWritePermissionsPipelineFactory({
|
||||
getRoles: getRolesFactory({ db }),
|
||||
getStream: getStreamFactory({ db }),
|
||||
getAutomationProject: getAutomationProjectFactory({ db: projectDb })
|
||||
getStream: getStreamFactory({ db })
|
||||
})
|
||||
)(req, res, next)
|
||||
},
|
||||
|
|
|
@ -19,7 +19,6 @@ import {
|
|||
import { isResourceAllowed } from '@/modules/core/helpers/token'
|
||||
import { UserRoleData } from '@/modules/shared/domain/rolesAndScopes/types'
|
||||
import db from '@/db/knex'
|
||||
import { GetAutomationProject } from '@/modules/automate/domain/operations'
|
||||
import {
|
||||
AuthContext,
|
||||
AuthParams,
|
||||
|
@ -209,7 +208,6 @@ type StreamGetter = (params: {
|
|||
|
||||
type ValidateRequiredStreamDeps = {
|
||||
getStream: StreamGetter
|
||||
getAutomationProject: GetAutomationProject
|
||||
}
|
||||
|
||||
// this doesn't do any checks on the scopes, its sole responsibility is to add the
|
||||
|
@ -219,9 +217,9 @@ export const validateRequiredStreamFactory =
|
|||
// stream getter is an async func over { streamId, userId } returning a stream object
|
||||
// IoC baby...
|
||||
async ({ context, authResult, params }) => {
|
||||
const { getStream, getAutomationProject } = deps
|
||||
const { getStream } = deps
|
||||
|
||||
if (!params?.streamId && !params?.automationId)
|
||||
if (!params?.streamId)
|
||||
return authFailed(
|
||||
context,
|
||||
new ContextError("The context doesn't have a streamId or automationId")
|
||||
|
@ -234,15 +232,10 @@ export const validateRequiredStreamFactory =
|
|||
// cause stream getter could throw, its not a safe function if we want to
|
||||
// keep the pipeline rolling
|
||||
try {
|
||||
const stream = params.streamId
|
||||
? await getStream({
|
||||
streamId: params.streamId,
|
||||
userId: context?.userId
|
||||
})
|
||||
: await getAutomationProject({
|
||||
automationId: params.automationId!,
|
||||
userId: context?.userId
|
||||
})
|
||||
const stream = await getStream({
|
||||
streamId: params.streamId,
|
||||
userId: context?.userId
|
||||
})
|
||||
|
||||
if (!stream)
|
||||
return authFailed(
|
||||
|
|
|
@ -27,7 +27,6 @@ export interface AuthResult {
|
|||
|
||||
export interface AuthParams {
|
||||
streamId?: string
|
||||
automationId?: string
|
||||
}
|
||||
|
||||
export interface AuthData {
|
||||
|
|
|
@ -97,6 +97,7 @@
|
|||
"Encryptor",
|
||||
"Insertable",
|
||||
"mjml",
|
||||
"multiregion",
|
||||
"OIDC",
|
||||
"Prorotation"
|
||||
],
|
||||
|
|
Загрузка…
Ссылка в новой задаче