@@ -2529,6 +2529,108 @@ public function action_restart(Request $request)
2529
2529
2530
2530
}
2531
2531
2532
+ #[OA \Post(
2533
+ summary: 'Execute Command ' ,
2534
+ description: "Execute a command on the application's current container. " ,
2535
+ path: '/applications/{uuid}/execute ' ,
2536
+ operationId: 'execute-command-application ' ,
2537
+ security: [
2538
+ ['bearerAuth ' => []],
2539
+ ],
2540
+ tags: ['Applications ' ],
2541
+ parameters: [
2542
+ new OA \Parameter (
2543
+ name: 'uuid ' ,
2544
+ in: 'path ' ,
2545
+ description: 'UUID of the application. ' ,
2546
+ required: true ,
2547
+ schema: new OA \Schema (
2548
+ type: 'string ' ,
2549
+ format: 'uuid ' ,
2550
+ )
2551
+ ),
2552
+ ],
2553
+ requestBody: new OA \RequestBody (
2554
+ required: true ,
2555
+ description: 'Command to execute. ' ,
2556
+ content: new OA \MediaType (
2557
+ mediaType: 'application/json ' ,
2558
+ schema: new OA \Schema (
2559
+ type: 'object ' ,
2560
+ properties: [
2561
+ 'command ' => ['type ' => 'string ' , 'description ' => 'Command to execute. ' ],
2562
+ ],
2563
+ ),
2564
+ ),
2565
+ ),
2566
+ responses: [
2567
+ new OA \Response (
2568
+ response: 200 ,
2569
+ description: "Execute a command on the application's current container. " ,
2570
+ content: [
2571
+ new OA \MediaType (
2572
+ mediaType: 'application/json ' ,
2573
+ schema: new OA \Schema (
2574
+ type: 'object ' ,
2575
+ properties: [
2576
+ 'message ' => ['type ' => 'string ' , 'example ' => 'Command executed. ' ],
2577
+ 'response ' => ['type ' => 'string ' ],
2578
+ ]
2579
+ )
2580
+ ),
2581
+ ]
2582
+ ),
2583
+ new OA \Response (
2584
+ response: 401 ,
2585
+ ref: '#/components/responses/401 ' ,
2586
+ ),
2587
+ new OA \Response (
2588
+ response: 400 ,
2589
+ ref: '#/components/responses/400 ' ,
2590
+ ),
2591
+ new OA \Response (
2592
+ response: 404 ,
2593
+ ref: '#/components/responses/404 ' ,
2594
+ ),
2595
+ ]
2596
+ )]
2597
+ public function execute_command_by_uuid (Request $ request )
2598
+ {
2599
+ $ data = $ request ->validate ([
2600
+ 'command ' => 'required|string|max:255 ' ,
2601
+ ]);
2602
+ $ teamId = getTeamIdFromToken ();
2603
+ if (is_null ($ teamId )) {
2604
+ return invalidTokenResponse ();
2605
+ }
2606
+ $ uuid = $ request ->route ('uuid ' );
2607
+ if (!$ uuid ) {
2608
+ return response ()->json (['message ' => 'UUID is required. ' ], 400 );
2609
+ }
2610
+ $ application = Application::ownedByCurrentTeamAPI ($ teamId )->where ('uuid ' , $ request ->uuid )->first ();
2611
+ if (!$ application ) {
2612
+ return response ()->json (['message ' => 'Application not found. ' ], 404 );
2613
+ }
2614
+
2615
+ $ container = getCurrentApplicationContainerStatus ($ application ->destination ->server , $ application ->id )->firstOrFail ();
2616
+ $ status = getContainerStatus ($ application ->destination ->server , $ container ['Names ' ]);
2617
+
2618
+ if ('running ' !== $ status ) {
2619
+ return ;
2620
+ }
2621
+
2622
+ $ commands = collect ([
2623
+ executeInDocker ($ container ['Names ' ], $ data ['command ' ]),
2624
+ ]);
2625
+
2626
+ $ res = instant_remote_process ($ commands , $ application ->destination ->server );
2627
+
2628
+ return response ()->json ([
2629
+ 'message ' => 'Command executed. ' ,
2630
+ 'response ' => $ res ,
2631
+ ]);
2632
+ }
2633
+
2532
2634
private function validateDataApplications (Request $ request , Server $ server )
2533
2635
{
2534
2636
$ teamId = getTeamIdFromToken ();
0 commit comments