diff --git a/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java b/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java index 2e9c00a..7b5a817 100644 --- a/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java +++ b/src/main/java/kr/re/etri/autoflow/controllers/ExternalAuthController.java @@ -94,7 +94,6 @@ public class ExternalAuthController { return ResponseEntity.ok(ApiResponse.failure(e.getMessage())); } } - @Operation( summary = "S3 업로드 + 외부 DB 등록", description = "파일을 S3에 업로드하고 외부 DB에 등록합니다.", @@ -126,20 +125,20 @@ public class ExternalAuthController { } } -// @Operation(summary = "외부 DB 등록", description = "S3 업로드된 파일 정보를 외부 DB에 등록합니다.", -// security = @SecurityRequirement(name = "bearerAuth")) -// @PostMapping("/register") -// public ResponseEntity registerMetadata( -// @RequestBody EdgeSWVO edgeSWVO -// ) { -// try { -// String result = edgeSWUploadService.registerMetadata(edgeSWVO); -// return ResponseEntity.ok(result); -// } catch (Exception e) { -// log.error("DB 등록 실패", e); -// return ResponseEntity.internalServerError().body("DB 등록 실패: " + e.getMessage()); -// } -// } + @Operation(summary = "외부 DB 등록", description = "S3 업로드된 파일 정보를 외부 DB에 등록합니다.", + security = @SecurityRequirement(name = "bearerAuth")) + @PostMapping("/register") + public ResponseEntity registerMetadata( + @RequestBody EdgeSWVO edgeSWVO + ) { + try { + String result = edgeSWUploadService.registerMetadata(edgeSWVO); + return ResponseEntity.ok(result); + } catch (Exception e) { + log.error("DB 등록 실패", e); + return ResponseEntity.internalServerError().body("DB 등록 실패: " + e.getMessage()); + } + } // DTO: 요청 public static record SigninRequest(String id, String password) { } diff --git a/src/main/java/kr/re/etri/autoflow/payload/request/EdgeSWVO.java b/src/main/java/kr/re/etri/autoflow/payload/request/EdgeSWVO.java index 7f30860..b79c3a6 100644 --- a/src/main/java/kr/re/etri/autoflow/payload/request/EdgeSWVO.java +++ b/src/main/java/kr/re/etri/autoflow/payload/request/EdgeSWVO.java @@ -1,72 +1,67 @@ package kr.re.etri.autoflow.payload.request; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; -import org.springframework.web.multipart.MultipartFile; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; @Getter @Setter +@Schema(description = "Edge SW 등록용 데이터") public class EdgeSWVO implements Serializable { - private int sw_serial = -1; - private int ed_pkg_serial = -1; - private int sw_group = -1; - private String sw_group_name; - private int sw_type = -1; - private String sw_type_name; - private String sw_manufacturer; - private String package_id; - private String sw_id; - private String sw_version; - private String sw_name; - private String file_type; - private String file_name; + @Schema(description = "생성 일시 (ISO-8601 형식, UTC)", example = "2025-10-20T11:46:49.848Z", required = true) private String creation_datetime; - private long file_size = -1; - private String file_location; - private int install_os = -1; - private String install_os_name; - private List files = new ArrayList<>(); + @Schema(description = "다운로드 위치", example = "/opt/edge/download") + private String download_location; + + @Schema(description = "Edge 패키지 일련번호", nullable = true, example = "null") + private Integer ed_pkg_serial = null; - private boolean newest_version = false; - private String sw_serial_list; - private int archive_type = -1; - private boolean hmac = false; + @Schema(description = "SW ID", example = "SW001", required = true) + private String sw_id; + + @Schema(description = "SW 버전 (정수형)", example = "1", required = true) + private int sw_version; + + @Schema(description = "SW 이름", example = "Edge Manager", required = true) + private String sw_name; + + @Schema(description = "사용자 ID", example = "admin", required = true) private String user_id; - private String window_root_location; - private String window_exe_name; - private String linux_root_location; - private String linux_exe_name; - private String edge_id; - private String location_number; - - private String exec_yn; - private String download_location; + + @Schema(description = "인증 토큰", example = "eyJhbGciOiJIUzI1NiJ9...", required = true) private String auth_id; + @Schema(description = "설치 OS (1=Windows, 2=Linux 등)", example = "1", defaultValue = "1") + private int install_os = 1; + + @Schema(description = "아카이브 여부", example = "0", defaultValue = "0") + private int archive_type = 0; + + @Schema(description = "실행 여부", example = "0", defaultValue = "0") + private String exec_yn = "0"; + + @Schema(description = "비밀글 여부", example = "false") private String secret_at; - private boolean admin_at; - - private String user_input_install_location; - - // 파일 리스트 getter/setter (복사본 반환) - public List getFiles() { - if (this.files != null) { - return new ArrayList<>(this.files); - } - return null; - } - - public void setFiles(List files) { - if (files != null) { - this.files = new ArrayList<>(files); - } else { - this.files = null; - } - } + + @Schema(description = "파일 위치", example = "/opt/edge/files/edge-manager.jar") + private String file_location; + + @Schema(description = "파일 이름", example = "edge-manager.jar") + private String file_name; + + @Schema(description = "파일 종류", example = "jar") + private String file_type; + + @Schema(description = "파일 크기 (byte 단위)", example = "123456") + private long file_size; + + @Schema(description = "파일 업로드용 리스트 (JSON 전송 시 무시)", hidden = true) + @JsonIgnore + private List files; } diff --git a/src/main/java/kr/re/etri/autoflow/service/EdgeSWUploadService.java b/src/main/java/kr/re/etri/autoflow/service/EdgeSWUploadService.java index 167ac28..129fff3 100644 --- a/src/main/java/kr/re/etri/autoflow/service/EdgeSWUploadService.java +++ b/src/main/java/kr/re/etri/autoflow/service/EdgeSWUploadService.java @@ -34,81 +34,89 @@ public class EdgeSWUploadService { this.restTemplate = restTemplate; } - public String uploadAndSend(EdgeSWVO edgeSWVO) throws IOException { - // 1️⃣ S3 업로드 - for (MultipartFile file : edgeSWVO.getFiles()) { - File tempFile = convertMultiPartToFile(file); - String key = file.getOriginalFilename(); - s3Client.putObject( - PutObjectRequest.builder() - .bucket(s3Bucket) - .key(key) - .build(), - RequestBody.fromFile(tempFile) - ); - edgeSWVO.setFile_name(file.getOriginalFilename()); - edgeSWVO.setFile_size(file.getSize()); - edgeSWVO.setFile_location(key); - tempFile.delete(); - } +// public String uploadAndSend(EdgeSWVO edgeSWVO) throws IOException { +// // 1️⃣ S3 업로드 +// for (MultipartFile file : edgeSWVO.getFiles()) { +// File tempFile = convertMultiPartToFile(file); +// String key = file.getOriginalFilename(); +// s3Client.putObject( +// PutObjectRequest.builder() +// .bucket(s3Bucket) +// .key(key) +// .build(), +// RequestBody.fromFile(tempFile) +// ); +// edgeSWVO.setFile_name(file.getOriginalFilename()); +// edgeSWVO.setFile_size(file.getSize()); +// edgeSWVO.setFile_location(key); +// tempFile.delete(); +// } +// +// // 2️⃣ 외부 API 전송 +// MultiValueMap body = new LinkedMultiValueMap<>(); +// for (MultipartFile file : edgeSWVO.getFiles()) { +// File tempFile = convertMultiPartToFile(file); +// body.add("files", new FileSystemResource(tempFile)); +// } +// +// // EdgeSWVO의 다른 필드들을 body에 추가 +// body.add("sw_id", edgeSWVO.getSw_id()); +// body.add("sw_version", edgeSWVO.getSw_version()); +// body.add("sw_name", edgeSWVO.getSw_name()); +// body.add("creation_datetime", edgeSWVO.getCreation_datetime()); +// body.add("file_location", edgeSWVO.getFile_location()); +// body.add("auth_id", edgeSWVO.getAuth_id()); +// +// HttpHeaders headers = new HttpHeaders(); +// headers.setContentType(MediaType.MULTIPART_FORM_DATA); +// +// if (edgeSWVO.getAuth_id() != null && !edgeSWVO.getAuth_id().isEmpty()) { +// headers.setBearerAuth(edgeSWVO.getAuth_id()); +// } +// +// HttpEntity> requestEntity = new HttpEntity<>(body, headers); +// +// ResponseEntity response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class); +// +// return response.getBody(); +// } - // 2️⃣ 외부 API 전송 - MultiValueMap body = new LinkedMultiValueMap<>(); - for (MultipartFile file : edgeSWVO.getFiles()) { - File tempFile = convertMultiPartToFile(file); - body.add("files", new FileSystemResource(tempFile)); - } + public String registerMetadata(EdgeSWVO edgeSWVO) { + // JSON Body 구성 + Map jsonBody = new HashMap<>(); + jsonBody.put("creation_datetime", edgeSWVO.getCreation_datetime()); + jsonBody.put("download_location", edgeSWVO.getDownload_location()); + jsonBody.put("ed_pkg_serial", edgeSWVO.getEd_pkg_serial()); + jsonBody.put("sw_id", edgeSWVO.getSw_id()); + jsonBody.put("sw_version", edgeSWVO.getSw_version()); + jsonBody.put("sw_name", edgeSWVO.getSw_name()); + jsonBody.put("user_id", edgeSWVO.getUser_id()); + jsonBody.put("auth_id", edgeSWVO.getAuth_id()); + jsonBody.put("install_os", edgeSWVO.getInstall_os()); + jsonBody.put("archive_type", edgeSWVO.getArchive_type()); + jsonBody.put("exec_yn", edgeSWVO.getExec_yn()); + jsonBody.put("secret_at", edgeSWVO.getSecret_at()); + + jsonBody.put("file_location", edgeSWVO.getFile_location()); + jsonBody.put("file_name", edgeSWVO.getFile_name()); + jsonBody.put("file_type", edgeSWVO.getFile_type()); + jsonBody.put("file_size", edgeSWVO.getFile_size()); - // EdgeSWVO의 다른 필드들을 body에 추가 - body.add("sw_id", edgeSWVO.getSw_id()); - body.add("sw_version", edgeSWVO.getSw_version()); - body.add("sw_name", edgeSWVO.getSw_name()); - body.add("creation_datetime", edgeSWVO.getCreation_datetime()); - body.add("file_location", edgeSWVO.getFile_location()); - body.add("auth_id", edgeSWVO.getAuth_id()); HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.MULTIPART_FORM_DATA); + headers.setContentType(MediaType.APPLICATION_JSON); + // JWT 인증 헤더 추가 if (edgeSWVO.getAuth_id() != null && !edgeSWVO.getAuth_id().isEmpty()) { headers.setBearerAuth(edgeSWVO.getAuth_id()); } - HttpEntity> requestEntity = new HttpEntity<>(body, headers); + HttpEntity> requestEntity = new HttpEntity<>(jsonBody, headers); ResponseEntity response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class); - return response.getBody(); } -// public String registerMetadata(EdgeSWVO edgeSWVO) { -// // 외부 API로 전송할 JSON Body 구성 -// Map jsonBody = new HashMap<>(); -// jsonBody.put("sw_id", edgeSWVO.getSw_id()); -// jsonBody.put("sw_version", edgeSWVO.getSw_version()); -// jsonBody.put("sw_name", edgeSWVO.getSw_name()); -// jsonBody.put("creation_datetime", edgeSWVO.getCreation_datetime()); -// jsonBody.put("file_name", edgeSWVO.getFile_name()); -// jsonBody.put("file_size", edgeSWVO.getFile_size()); -// jsonBody.put("file_location", edgeSWVO.getFile_location()); -// jsonBody.put("auth_id", edgeSWVO.getAuth_id()); -// // 필요에 따라 추가 필드도 넣기 -// -// HttpHeaders headers = new HttpHeaders(); -// headers.setContentType(MediaType.APPLICATION_JSON); -// -// // JWT 인증 헤더 추가 -// if (edgeSWVO.getAuth_id() != null && !edgeSWVO.getAuth_id().isEmpty()) { -// headers.setBearerAuth(edgeSWVO.getAuth_id()); -// } -// -// HttpEntity> requestEntity = new HttpEntity<>(jsonBody, headers); -// -// ResponseEntity response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class); -// -// return response.getBody(); -// } - private File convertMultiPartToFile(MultipartFile file) throws IOException { File convFile = File.createTempFile("upload-", file.getOriginalFilename()); try (FileOutputStream fos = new FileOutputStream(convFile)) { diff --git a/src/main/java/kr/re/etri/autoflow/swagger/OpenAPIConfig.java b/src/main/java/kr/re/etri/autoflow/swagger/OpenAPIConfig.java index a76204a..35b6f28 100644 --- a/src/main/java/kr/re/etri/autoflow/swagger/OpenAPIConfig.java +++ b/src/main/java/kr/re/etri/autoflow/swagger/OpenAPIConfig.java @@ -52,11 +52,12 @@ public class OpenAPIConfig { .type(SecurityScheme.Type.APIKEY) .in(SecurityScheme.In.HEADER) ) - .addSecuritySchemes(SECURITY_SCHEME_BEARER, + .addSecuritySchemes("bearerAuth", new SecurityScheme() .type(SecurityScheme.Type.HTTP) .scheme("bearer") .bearerFormat("JWT") + .name("Authorization") ); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 78f19e7..c44c9ce 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -72,7 +72,7 @@ server.servlet.encoding.force=true spring.servlet.multipart.enabled=true #OTA?? -external.auth.signin-url=https://cuuva.com:24443/api/datamanager/user/signin +external.auth.signin-url=https://a659120d3e2ff43ff94087b29396fd96-1057696791.ap-northeast-2.elb.amazonaws.com/api/datamanager/user/signin external.auth.edge-search-url=https://cuuva.com:24443/api/datamanager/edge-pkg/search cloud.aws.region.static=ap-northeast-2