[MODIFY] 외부 Edge 패키지 등록 API 수정, EdgeSWVO 필드 추가 및 개선, Bearer 인증 설정 수정, application.properties의 외부 인증 URL 변경

main
bjkim 8 months ago
parent ab0281eae8
commit d4f3620933

@ -94,7 +94,6 @@ public class ExternalAuthController {
return ResponseEntity.ok(ApiResponse.failure(e.getMessage())); return ResponseEntity.ok(ApiResponse.failure(e.getMessage()));
} }
} }
@Operation( @Operation(
summary = "S3 업로드 + 외부 DB 등록", summary = "S3 업로드 + 외부 DB 등록",
description = "파일을 S3에 업로드하고 외부 DB에 등록합니다.", description = "파일을 S3에 업로드하고 외부 DB에 등록합니다.",
@ -126,20 +125,20 @@ public class ExternalAuthController {
} }
} }
// @Operation(summary = "외부 DB 등록", description = "S3 업로드된 파일 정보를 외부 DB에 등록합니다.", @Operation(summary = "외부 DB 등록", description = "S3 업로드된 파일 정보를 외부 DB에 등록합니다.",
// security = @SecurityRequirement(name = "bearerAuth")) security = @SecurityRequirement(name = "bearerAuth"))
// @PostMapping("/register") @PostMapping("/register")
// public ResponseEntity<String> registerMetadata( public ResponseEntity<String> registerMetadata(
// @RequestBody EdgeSWVO edgeSWVO @RequestBody EdgeSWVO edgeSWVO
// ) { ) {
// try { try {
// String result = edgeSWUploadService.registerMetadata(edgeSWVO); String result = edgeSWUploadService.registerMetadata(edgeSWVO);
// return ResponseEntity.ok(result); return ResponseEntity.ok(result);
// } catch (Exception e) { } catch (Exception e) {
// log.error("DB 등록 실패", e); log.error("DB 등록 실패", e);
// return ResponseEntity.internalServerError().body("DB 등록 실패: " + e.getMessage()); return ResponseEntity.internalServerError().body("DB 등록 실패: " + e.getMessage());
// } }
// } }
// DTO: 요청 // DTO: 요청
public static record SigninRequest(String id, String password) { } public static record SigninRequest(String id, String password) { }

@ -1,72 +1,67 @@
package kr.re.etri.autoflow.payload.request; 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.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Getter @Getter
@Setter @Setter
@Schema(description = "Edge SW 등록용 데이터")
public class EdgeSWVO implements Serializable { public class EdgeSWVO implements Serializable {
private int sw_serial = -1; @Schema(description = "생성 일시 (ISO-8601 형식, UTC)", example = "2025-10-20T11:46:49.848Z", required = true)
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;
private String creation_datetime; 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<MultipartFile> 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; @Schema(description = "SW ID", example = "SW001", required = true)
private String sw_serial_list; private String sw_id;
private int archive_type = -1;
private boolean hmac = false; @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 user_id;
private String window_root_location;
private String window_exe_name; @Schema(description = "인증 토큰", example = "eyJhbGciOiJIUzI1NiJ9...", required = true)
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;
private String auth_id; 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 String secret_at;
private boolean admin_at;
@Schema(description = "파일 위치", example = "/opt/edge/files/edge-manager.jar")
private String user_input_install_location; private String file_location;
// 파일 리스트 getter/setter (복사본 반환) @Schema(description = "파일 이름", example = "edge-manager.jar")
public List<MultipartFile> getFiles() { private String file_name;
if (this.files != null) {
return new ArrayList<>(this.files); @Schema(description = "파일 종류", example = "jar")
} private String file_type;
return null;
} @Schema(description = "파일 크기 (byte 단위)", example = "123456")
private long file_size;
public void setFiles(List<MultipartFile> files) {
if (files != null) { @Schema(description = "파일 업로드용 리스트 (JSON 전송 시 무시)", hidden = true)
this.files = new ArrayList<>(files); @JsonIgnore
} else { private List<?> files;
this.files = null;
}
}
} }

@ -34,81 +34,89 @@ public class EdgeSWUploadService {
this.restTemplate = restTemplate; this.restTemplate = restTemplate;
} }
public String uploadAndSend(EdgeSWVO edgeSWVO) throws IOException { // public String uploadAndSend(EdgeSWVO edgeSWVO) throws IOException {
// 1⃣ S3 업로드 // // 1⃣ S3 업로드
for (MultipartFile file : edgeSWVO.getFiles()) { // for (MultipartFile file : edgeSWVO.getFiles()) {
File tempFile = convertMultiPartToFile(file); // File tempFile = convertMultiPartToFile(file);
String key = file.getOriginalFilename(); // String key = file.getOriginalFilename();
s3Client.putObject( // s3Client.putObject(
PutObjectRequest.builder() // PutObjectRequest.builder()
.bucket(s3Bucket) // .bucket(s3Bucket)
.key(key) // .key(key)
.build(), // .build(),
RequestBody.fromFile(tempFile) // RequestBody.fromFile(tempFile)
); // );
edgeSWVO.setFile_name(file.getOriginalFilename()); // edgeSWVO.setFile_name(file.getOriginalFilename());
edgeSWVO.setFile_size(file.getSize()); // edgeSWVO.setFile_size(file.getSize());
edgeSWVO.setFile_location(key); // edgeSWVO.setFile_location(key);
tempFile.delete(); // tempFile.delete();
} // }
//
// // 2⃣ 외부 API 전송
// MultiValueMap<String, Object> 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<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
//
// ResponseEntity<String> response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class);
//
// return response.getBody();
// }
// 2⃣ 외부 API 전송 public String registerMetadata(EdgeSWVO edgeSWVO) {
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); // JSON Body 구성
for (MultipartFile file : edgeSWVO.getFiles()) { Map<String, Object> jsonBody = new HashMap<>();
File tempFile = convertMultiPartToFile(file); jsonBody.put("creation_datetime", edgeSWVO.getCreation_datetime());
body.add("files", new FileSystemResource(tempFile)); 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(); 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()) { if (edgeSWVO.getAuth_id() != null && !edgeSWVO.getAuth_id().isEmpty()) {
headers.setBearerAuth(edgeSWVO.getAuth_id()); headers.setBearerAuth(edgeSWVO.getAuth_id());
} }
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(jsonBody, headers);
ResponseEntity<String> response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class); ResponseEntity<String> response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class);
return response.getBody(); return response.getBody();
} }
// public String registerMetadata(EdgeSWVO edgeSWVO) {
// // 외부 API로 전송할 JSON Body 구성
// Map<String, Object> 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<Map<String, Object>> requestEntity = new HttpEntity<>(jsonBody, headers);
//
// ResponseEntity<String> response = restTemplate.postForEntity(externalApiUrl, requestEntity, String.class);
//
// return response.getBody();
// }
private File convertMultiPartToFile(MultipartFile file) throws IOException { private File convertMultiPartToFile(MultipartFile file) throws IOException {
File convFile = File.createTempFile("upload-", file.getOriginalFilename()); File convFile = File.createTempFile("upload-", file.getOriginalFilename());
try (FileOutputStream fos = new FileOutputStream(convFile)) { try (FileOutputStream fos = new FileOutputStream(convFile)) {

@ -52,11 +52,12 @@ public class OpenAPIConfig {
.type(SecurityScheme.Type.APIKEY) .type(SecurityScheme.Type.APIKEY)
.in(SecurityScheme.In.HEADER) .in(SecurityScheme.In.HEADER)
) )
.addSecuritySchemes(SECURITY_SCHEME_BEARER, .addSecuritySchemes("bearerAuth",
new SecurityScheme() new SecurityScheme()
.type(SecurityScheme.Type.HTTP) .type(SecurityScheme.Type.HTTP)
.scheme("bearer") .scheme("bearer")
.bearerFormat("JWT") .bearerFormat("JWT")
.name("Authorization")
); );
} }

@ -72,7 +72,7 @@ server.servlet.encoding.force=true
spring.servlet.multipart.enabled=true spring.servlet.multipart.enabled=true
#OTA?? #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 external.auth.edge-search-url=https://cuuva.com:24443/api/datamanager/edge-pkg/search
cloud.aws.region.static=ap-northeast-2 cloud.aws.region.static=ap-northeast-2

Loading…
Cancel
Save