forked from Hithomelabs/CFTunnels
feat(portainer-automation): add deploy controller with X-API-Key auth
This commit is contained in:
parent
1a6da256d2
commit
d7cee78c22
@ -0,0 +1,43 @@
|
|||||||
|
package com.hithomelabs.portainer.controller;
|
||||||
|
|
||||||
|
import com.hithomelabs.portainer.config.PortainerAutomationProperties;
|
||||||
|
import com.hithomelabs.portainer.service.DeployService;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/deploy")
|
||||||
|
public class DeployController {
|
||||||
|
|
||||||
|
private final DeployService deployService;
|
||||||
|
private final String serviceApiKey;
|
||||||
|
|
||||||
|
public DeployController(DeployService deployService,
|
||||||
|
PortainerAutomationProperties properties) {
|
||||||
|
this.deployService = deployService;
|
||||||
|
this.serviceApiKey = properties.getService().getApiKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{stackId}")
|
||||||
|
public ResponseEntity<String> deploy(@PathVariable Long stackId,
|
||||||
|
@RequestHeader("X-API-Key") String apiKey) {
|
||||||
|
if (serviceApiKey == null || !serviceApiKey.equals(apiKey)) {
|
||||||
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
|
||||||
|
.body("Invalid or missing X-API-Key");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
deployService.deploy(stackId);
|
||||||
|
return ResponseEntity.ok("Stack " + stackId + " redeploy triggered");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Redeploy failed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user