11import { createOtelLogger } from "@akashnetwork/logging/otel" ;
2+ import { createMongoAbility , type MongoAbility } from "@casl/ability" ;
23import { context , trace } from "@opentelemetry/api" ;
34import { Command } from "commander" ;
45import { once } from "lodash" ;
@@ -7,6 +8,7 @@ import { container } from "tsyringe";
78import { z } from "zod" ;
89
910import { WalletController } from "@src/billing/controllers/wallet/wallet.controller" ;
11+ import { ExecutionContextService } from "@src/core/services/execution-context/execution-context.service" ;
1012import { chainDb } from "@src/db/dbConnection" ;
1113import { TopUpDeploymentsController } from "@src/deployment/controllers/deployment/top-up-deployments.controller" ;
1214import { GpuBotController } from "@src/deployment/controllers/gpu-bot/gpu-bot.controller" ;
@@ -79,7 +81,30 @@ async function executeCliHandler(name: string, handler: () => Promise<unknown>,
7981 try {
8082 await Promise . all ( [ migratePG ( ) , chainDb . authenticate ( ) , ...container . resolveAll ( APP_INITIALIZER ) . map ( initializer => initializer [ ON_APP_START ] ( ) ) ] ) ;
8183
82- const result = await handler ( ) ;
84+ const executionContextService = container . resolve ( ExecutionContextService ) ;
85+ const result = await executionContextService . runWithContext ( async ( ) => {
86+ executionContextService . set ( "CURRENT_USER" , {
87+ id : "cli-user" ,
88+ bio : null ,
89+ email : null ,
90+ emailVerified : false ,
91+ stripeCustomerId : null ,
92+ subscribedToNewsletter : false ,
93+ createdAt : new Date ( ) ,
94+ lastActiveAt : new Date ( ) ,
95+ lastIp : null ,
96+ lastUserAgent : null ,
97+ lastFingerprint : null ,
98+ youtubeUsername : null ,
99+ twitterUsername : null ,
100+ githubUsername : null ,
101+ userId : "system:cli-user" ,
102+ username : "___cli_user___" ,
103+ trial : false
104+ } ) ;
105+ executionContextService . set ( "ABILITY" , createMongoAbility < MongoAbility > ( ) ) ;
106+ return await handler ( ) ;
107+ } ) ;
83108
84109 if ( result && result instanceof Err ) {
85110 logger . error ( { event : "COMMAND_ERROR" , name, result : result . val } ) ;
0 commit comments