From fad478f2eaca9f310d90e7b9c4582fbf1885775a Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:16:57 +0900 Subject: [PATCH 1/7] =?UTF-8?q?Feat:=20AiwaKey=20Class=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MemberController.java | 5 +-- .../MCPBackend_Member/Entity/AiwaKey.java | 35 +++++++++++++++++++ .../AIWA/MCPBackend_Member/Entity/Member.java | 12 +++---- 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java diff --git a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java index 59a02f7..7a31577 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java +++ b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java @@ -43,10 +43,7 @@ public CommonResult deleteMember(@RequestBody MemberDeleteRequestDto deleteMembe // 특정 회원 조회 @GetMapping("/email") // PathVariable로 이메일을 전달 public SingleResult getMember(@RequestParam String email) { - Member findMember = memberService.getMemberByEmail(email); // Optional을 반환하지 않는다고 가정 -// System.out.println(email); -// System.out.println(findMember.getAccess_key()); -// System.out.println(findMember.getSecret_key()); + Member findMember = memberService.getMemberByEmail(email); if (findMember != null) { // Member 정보를 MemberCredentialDTO로 변환 diff --git a/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java new file mode 100644 index 0000000..ebd66ea --- /dev/null +++ b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java @@ -0,0 +1,35 @@ +package AIWA.MCPBackend_Member.Entity; + + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + + +@Entity +@Getter +@Setter +@NoArgsConstructor +public class AiwaKey { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String companyName; + + @Column(length = 1000) + private String accessKey; // AWS access key + + @Column(length = 1000) + private String secretKey; // AWS secret key + + @Column(length = 2048) // S3 경로를 저장 + private String gcpKeyPath; + + @ManyToOne + @JoinColumn(name = "member_id", nullable = false) + private Member member; +} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Entity/Member.java b/src/main/java/AIWA/MCPBackend_Member/Entity/Member.java index d9335f9..efe7deb 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Entity/Member.java +++ b/src/main/java/AIWA/MCPBackend_Member/Entity/Member.java @@ -6,6 +6,9 @@ import lombok.NoArgsConstructor; import lombok.Setter; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @@ -27,15 +30,12 @@ public class Member { @Column(unique = true, nullable = false) private String email; - @Column(length = 1000) - private String access_key; - @Column(length = 1000) - private String secret_key; + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true) + private List aiwaKeys = new ArrayList<>(); public Member(String name, String password, String email) { this.name = name; this.password = password; this.email = email; } - -} +} \ No newline at end of file From e7f493a34c90e108b3852b2bf02d770d3db6fdf7 Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:24:09 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#16=20S3Service=20=EC=97=90=20Gcp=20Credent?= =?UTF-8?q?ial=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/s3/S3Service.java | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java b/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java index 893a29c..1688ce5 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java @@ -1,11 +1,13 @@ package AIWA.MCPBackend_Member.Service.s3; - import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.*; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; + @Service @RequiredArgsConstructor public class S3Service { @@ -13,14 +15,13 @@ public class S3Service { private final AmazonS3 s3Client; private final String bucketName = "aiwa-terraform"; + // 사용자 디렉토리 생성 public void createUserDirectory(String userId) { String userPrefix = "users/" + userId + "/"; - // 초기 main.tf 및 terraform.tfstate 파일을 업로드합니다 uploadInitialFiles(userPrefix); } private void uploadInitialFiles(String userPrefix) { - // 초기 main.tf 파일 String mainTfContent = """ variable "aws_access_key" { description = "AWS Access Key" @@ -34,44 +35,68 @@ private void uploadInitialFiles(String userPrefix) { provider "aws" { region = "ap-northeast-2" - access_key = var.aws_access_key // 변수로 AWS Access Key 제공 - secret_key = var.aws_secret_key // 변수로 AWS Secret Key 제공 + access_key = var.aws_access_key + secret_key = var.aws_secret_key } """; s3Client.putObject(bucketName, userPrefix + "main.tf", mainTfContent); + } + + // AWS tfvars 파일 생성 + public String createAwsTfvarsFile(String userId, String accessKey, String secretKey) { + String userPrefix = "users/" + userId + "/"; + String tfvarsContent = String.format(""" + aws_access_key = "%s" + aws_secret_key = "%s" + """, accessKey, secretKey); -// // 빈 상태 파일 -// String emptyState = "{}"; -// s3Client.putObject(bucketName, userPrefix + "terraform.tfstate", emptyState); + String tfvarsKey = userPrefix + "aws_terraform.tfvars"; + s3Client.putObject(bucketName, tfvarsKey, tfvarsContent); + return s3Client.getUrl(bucketName, tfvarsKey).toString(); // S3 URL 반환 } - public void deleteUserDirectory(String userId) { + // GCP 자격 증명 파일 업로드 + public String uploadGcpKeyFile(String userId, String gcpKeyContent) { String userPrefix = "users/" + userId + "/"; + String gcpKeyFileKey = userPrefix + "gcp_credentials.json"; + byte[] gcpKeyBytes = gcpKeyContent.getBytes(StandardCharsets.UTF_8); + + ObjectMetadata metadata = new ObjectMetadata(); + metadata.setContentLength(gcpKeyBytes.length); + s3Client.putObject(bucketName, gcpKeyFileKey, new ByteArrayInputStream(gcpKeyBytes), metadata); - // S3에서 해당 디렉터리(prefix)를 기준으로 모든 파일 목록을 가져옴 + return s3Client.getUrl(bucketName, gcpKeyFileKey).toString(); // S3 URL 반환 + } + + // 사용자 디렉토리 삭제 + public void deleteUserDirectory(String userId) { + String userPrefix = "users/" + userId + "/"; ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(bucketName).withPrefix(userPrefix); ListObjectsV2Result result; - // 모든 객체를 반복적으로 가져와 삭제 do { result = s3Client.listObjectsV2(request); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { s3Client.deleteObject(bucketName, objectSummary.getKey()); } request.setContinuationToken(result.getNextContinuationToken()); - } while (result.isTruncated()); // 계속해서 모든 객체를 삭제할 때까지 반복 + } while (result.isTruncated()); } - - public void createTfvarsFile(String userId, String accessKey, String secretKey) { - String userPrefix = "users/" + userId + "/"; - String tfvarsContent = String.format(""" - aws_access_key = "%s" - aws_secret_key = "%s" - """, accessKey, secretKey); - - s3Client.putObject(bucketName, userPrefix + "terraform.tfvars", tfvarsContent); + // GCP 키 파일 삭제 + public void deleteGcpKeyFile(String userId) { + String gcpKeyFileKey = "users/" + userId + "/gcp_credentials.json"; + if (s3Client.doesObjectExist(bucketName, gcpKeyFileKey)) { + s3Client.deleteObject(bucketName, gcpKeyFileKey); + } } + // AWS tfvars 파일 삭제 + public void deleteAwsTfvarsFile(String userId) { + String awsTfvarsKey = "users/" + userId + "/aws_terraform.tfvars"; + if (s3Client.doesObjectExist(bucketName, awsTfvarsKey)) { + s3Client.deleteObject(bucketName, awsTfvarsKey); + } + } } \ No newline at end of file From b7a8c2a51dd4301e37d9f352bf676cc945604ce8 Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:25:35 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#16=20Fix:=20MemberService=20=EC=97=90=20GC?= =?UTF-8?q?P=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MCPBackend_Member/Entity/AiwaKey.java | 22 ++++++---- .../Service/member/MemberService.java | 42 ++++++++++++++----- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java index ebd66ea..b7960bc 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java +++ b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java @@ -1,13 +1,10 @@ package AIWA.MCPBackend_Member.Entity; - import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; import lombok.Setter; - @Entity @Getter @Setter @@ -18,18 +15,27 @@ public class AiwaKey { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private String companyName; + @Column(nullable = false) + private String companyName; // 고객 회사 이름 @Column(length = 1000) - private String accessKey; // AWS access key + private String accessKey; // AWS Access Key @Column(length = 1000) - private String secretKey; // AWS secret key + private String secretKey; // AWS Secret Key - @Column(length = 2048) // S3 경로를 저장 - private String gcpKeyPath; + @Column(length = 2048) + private String gcpKeyPath; // GCP 키 파일 S3 경로 @ManyToOne @JoinColumn(name = "member_id", nullable = false) private Member member; + + public AiwaKey(String companyName, String accessKey, String secretKey, String gcpKeyPath, Member member) { + this.companyName = companyName; + this.accessKey = accessKey; + this.secretKey = secretKey; + this.gcpKeyPath = gcpKeyPath; + this.member = member; + } } \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java index 3b7da9e..e67320f 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java @@ -3,6 +3,7 @@ import AIWA.MCPBackend_Member.Dto.MemberDeleteRequestDto; import AIWA.MCPBackend_Member.Dto.MemberRequestDto; +import AIWA.MCPBackend_Member.Entity.AiwaKey; import AIWA.MCPBackend_Member.Entity.Member; import AIWA.MCPBackend_Member.Repository.MemberRepository; import AIWA.MCPBackend_Member.Service.s3.S3Service; @@ -59,22 +60,41 @@ public List getAllMembers() { } - public Member addOrUpdateKeys(String email,String access_key,String secret_key) { - + public Member addOrUpdateAwsKey(String email, String accessKey, String secretKey) { Member member = getMemberByEmail(email); - member.setAccess_key(access_key); - member.setSecret_key(secret_key); - s3Service.createTfvarsFile(email,access_key,secret_key); + + // AWS 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 + Optional existingAwsKey = member.getAiwaKeys().stream() + .filter(key -> "AWS".equalsIgnoreCase(key.getCompanyName())) + .findFirst(); + + if (existingAwsKey.isPresent()) { + existingAwsKey.get().setAccessKey(accessKey); + existingAwsKey.get().setSecretKey(secretKey); + } else { + AiwaKey awsKey = new AiwaKey("AWS", accessKey, secretKey, null, member); + member.getAiwaKeys().add(awsKey); + } + return memberRepository.save(member); } - // Access Key와 Secret Key 삭제 - public Member removeKeys(Long id) { - Member member = memberRepository.findById(id) - .orElseThrow(() -> new RuntimeException("Member not found")); + public Member addOrUpdateGcpKey(String email, String gcpKeyContent) { + Member member = getMemberByEmail(email); - member.setAccess_key(null); - member.setSecret_key(null); + // GCP 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 + Optional existingGcpKey = member.getAiwaKeys().stream() + .filter(key -> "GCP".equalsIgnoreCase(key.getCompanyName())) + .findFirst(); + + if (existingGcpKey.isPresent()) { + String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); + existingGcpKey.get().setGcpKeyPath(gcpKeyPath); + } else { + String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); + AiwaKey gcpKey = new AiwaKey("GCP", null, null, gcpKeyPath, member); + member.getAiwaKeys().add(gcpKey); + } return memberRepository.save(member); } From 0e5013ff33a020980b48ee1037d35a96679019c2 Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:29:19 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#16=20Feat:=20MemberService=20=EC=97=90=20K?= =?UTF-8?q?ey=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/member/MemberService.java | 23 ++++++++++++++ .../Service/s3/S3Service.java | 31 ++++++++++--------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java index e67320f..2c5efa1 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java @@ -98,4 +98,27 @@ public Member addOrUpdateGcpKey(String email, String gcpKeyContent) { return memberRepository.save(member); } + + public Member removeAwsKey(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new RuntimeException("Member not found")); + + member.getAiwaKeys().removeIf(key -> "AWS".equalsIgnoreCase(key.getCompanyName())); + + return memberRepository.save(member); + } + + + public Member removeGcpKey(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new RuntimeException("Member not found")); + + // GCP 키를 삭제하고 S3에서 GCP 키 파일도 삭제 + member.getAiwaKeys().removeIf(key -> "GCP".equalsIgnoreCase(key.getCompanyName())); + s3Service.deleteGcpKeyFile(member.getEmail()); + + return memberRepository.save(member); + } + + } \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java b/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java index 1688ce5..36d9996 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/s3/S3Service.java @@ -68,6 +68,22 @@ public String uploadGcpKeyFile(String userId, String gcpKeyContent) { return s3Client.getUrl(bucketName, gcpKeyFileKey).toString(); // S3 URL 반환 } + // GCP 키 파일 삭제 + public void deleteGcpKeyFile(String userId) { + String gcpKeyFileKey = "users/" + userId + "/gcp_credentials.json"; + if (s3Client.doesObjectExist(bucketName, gcpKeyFileKey)) { + s3Client.deleteObject(bucketName, gcpKeyFileKey); + } + } + + // AWS tfvars 파일 삭제 + public void deleteAwsTfvarsFile(String userId) { + String awsTfvarsKey = "users/" + userId + "/aws_terraform.tfvars"; + if (s3Client.doesObjectExist(bucketName, awsTfvarsKey)) { + s3Client.deleteObject(bucketName, awsTfvarsKey); + } + } + // 사용자 디렉토리 삭제 public void deleteUserDirectory(String userId) { @@ -84,19 +100,4 @@ public void deleteUserDirectory(String userId) { } while (result.isTruncated()); } - // GCP 키 파일 삭제 - public void deleteGcpKeyFile(String userId) { - String gcpKeyFileKey = "users/" + userId + "/gcp_credentials.json"; - if (s3Client.doesObjectExist(bucketName, gcpKeyFileKey)) { - s3Client.deleteObject(bucketName, gcpKeyFileKey); - } - } - - // AWS tfvars 파일 삭제 - public void deleteAwsTfvarsFile(String userId) { - String awsTfvarsKey = "users/" + userId + "/aws_terraform.tfvars"; - if (s3Client.doesObjectExist(bucketName, awsTfvarsKey)) { - s3Client.deleteObject(bucketName, awsTfvarsKey); - } - } } \ No newline at end of file From 94e16eda524540f13b4c4cc14b30cba0f861041f Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:37:23 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#16=20Feat:=20MemberController=20=EB=82=B4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20AWS,GCP=20=EA=B0=81=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MemberController.java | 75 +++++++++++-------- .../Dto/AddAwsKeyRequestDto.java | 13 ++++ .../Dto/AddGcpKeyRequestDto.java | 12 +++ .../MCPBackend_Member/Dto/CompanyDto.java | 18 ----- .../Dto/DeleteKeyRequestDto.java | 11 +++ .../Dto/MemberCredentialDTO.java | 19 ----- .../Dto/MemberDeleteRequestDto.java | 12 +-- .../Dto/MemberRequestDto.java | 14 ++-- .../Dto/MemberResponseDto.java | 21 +++--- .../Service/member/MemberService.java | 25 ++++++- 10 files changed, 119 insertions(+), 101 deletions(-) create mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java create mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java delete mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java create mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/DeleteKeyRequestDto.java delete mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/MemberCredentialDTO.java diff --git a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java index 7a31577..c6fcb5c 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java +++ b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java @@ -1,6 +1,5 @@ package AIWA.MCPBackend_Member.Controller; - import AIWA.MCPBackend_Member.Dto.*; import AIWA.MCPBackend_Member.Entity.Member; import AIWA.MCPBackend_Member.Service.member.MemberService; @@ -18,12 +17,14 @@ @RequiredArgsConstructor @RequestMapping("/member/api/members") public class MemberController { + private final MemberService memberService; private final ResponseService responseService; // 회원 등록 @PostMapping("/register") public SingleResult registerMember(@RequestBody MemberRequestDto memberRequestDto) { + // 회원 등록 Member savedMember = memberService.registerMember(memberRequestDto); MemberResponseDto memberResponseDto = MemberResponseDto.toDto(savedMember); return responseService.getSingleResult(memberResponseDto); @@ -32,46 +33,58 @@ public SingleResult registerMember(@RequestBody MemberRequest // 회원 삭제 @DeleteMapping("/delete") public CommonResult deleteMember(@RequestBody MemberDeleteRequestDto deleteMemberRequestDto) { - // 회원 삭제 서비스 호출 + // 회원 삭제 memberService.deleteMember(deleteMemberRequestDto); - - // 성공 응답 반환 (ResponseService를 통해) return responseService.getSuccessResult(); } - - - // 특정 회원 조회 - @GetMapping("/email") // PathVariable로 이메일을 전달 - public SingleResult getMember(@RequestParam String email) { - Member findMember = memberService.getMemberByEmail(email); - - if (findMember != null) { - // Member 정보를 MemberCredentialDTO로 변환 - MemberCredentialDTO memberCredentialDTO = new MemberCredentialDTO( - findMember.getEmail(), - findMember.getAccess_key(), - findMember.getSecret_key() - ); - System.out.println(memberCredentialDTO); - return responseService.getSingleResult(memberCredentialDTO); - } else { - return (SingleResult) responseService.getFailResult(); - } - } - + + // 모든 회원 조회 @GetMapping("/all") public ListResult getAllMembers() { + // 모든 회원 조회 List members = memberService.getAllMembers(); - List memberResponseDtoList = members.stream().map(MemberResponseDto::toDto).collect(Collectors.toList()); + List memberResponseDtoList = members.stream() + .map(MemberResponseDto::toDto) + .collect(Collectors.toList()); return responseService.getListResult(memberResponseDtoList); } - @PostMapping("/update-credentials") - public CommonResult updateCredentials(@RequestBody MemberCredentialDTO memberCredentialDTO) { - System.out.println(memberCredentialDTO.getAccessKey()); - System.out.println(memberCredentialDTO.getSecretKey()); - memberService.addOrUpdateKeys(memberCredentialDTO.getEmail(),memberCredentialDTO.getAccessKey(), memberCredentialDTO.getSecretKey()); + // AWS 키 추가/업데이트 + @PostMapping("/add-aws-key") + public SingleResult addAwsKey(@RequestBody AddAwsKeyRequestDto addAwsKeyRequestDto) { + // AWS 키 추가 및 S3 URL 반환 + String tfvarsUrl = memberService.addOrUpdateAwsKey( + addAwsKeyRequestDto.getEmail(), + addAwsKeyRequestDto.getAccessKey(), + addAwsKeyRequestDto.getSecretKey() + ); + return responseService.getSingleResult(tfvarsUrl); + } + + // GCP 키 추가/업데이트 + @PostMapping("/add-gcp-key") + public SingleResult addGcpKey(@RequestBody AddGcpKeyRequestDto addGcpKeyRequestDto) { + // GCP 키 추가 및 S3 URL 반환 + String gcpKeyUrl = memberService.addOrUpdateGcpKey( + addGcpKeyRequestDto.getEmail(), + addGcpKeyRequestDto.getGcpKeyContent() + ); + return responseService.getSingleResult(gcpKeyUrl); + } + + // AWS 키 삭제 + @DeleteMapping("/delete-aws-key") + public CommonResult deleteAwsKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) { + // AWS 키 삭제 + memberService.removeAwsKey(deleteKeyRequestDto.getMemberId()); return responseService.getSuccessResult(); } + // GCP 키 삭제 + @DeleteMapping("/delete-gcp-key") + public CommonResult deleteGcpKey(@RequestBody DeleteKeyRequestDto deleteKeyRequestDto) { + // GCP 키 삭제 + memberService.removeGcpKey(deleteKeyRequestDto.getMemberId()); + return responseService.getSuccessResult(); + } } \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java new file mode 100644 index 0000000..8a40580 --- /dev/null +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java @@ -0,0 +1,13 @@ +package AIWA.MCPBackend_Member.Dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AddAwsKeyRequestDto { + private String email; + private String accessKey; + private String secretKey; + private String companyName; +} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java new file mode 100644 index 0000000..a0a7659 --- /dev/null +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java @@ -0,0 +1,12 @@ +package AIWA.MCPBackend_Member.Dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AddGcpKeyRequestDto { + private String email; + private String gcpKeyContent; + private String companyName; +} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java deleted file mode 100644 index 1f81381..0000000 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package AIWA.MCPBackend_Member.Dto; - -import lombok.Getter; - -@Getter -public class CompanyDto { - private String userId; - private String company; - private String accessKey; - private String secretKey; - - public CompanyDto(String userId, String company, String accessKey, String secretKey) { - this.userId = userId; - this.company = company; - this.accessKey = accessKey; - this.secretKey = secretKey; - } -} diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/DeleteKeyRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/DeleteKeyRequestDto.java new file mode 100644 index 0000000..92ce125 --- /dev/null +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/DeleteKeyRequestDto.java @@ -0,0 +1,11 @@ +package AIWA.MCPBackend_Member.Dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class DeleteKeyRequestDto { + private Long memberId; + private String companyName; // AWS 또는 GCP +} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberCredentialDTO.java b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberCredentialDTO.java deleted file mode 100644 index 4d930cb..0000000 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberCredentialDTO.java +++ /dev/null @@ -1,19 +0,0 @@ -package AIWA.MCPBackend_Member.Dto; - -import lombok.Data; -import lombok.Getter; - - -@Data -@Getter -public class MemberCredentialDTO { - private String email; - private String accessKey; - private String secretKey; - - public MemberCredentialDTO(String email, String accessKey, String secretKey) { - this.email = email; - this.accessKey = accessKey; - this.secretKey = secretKey; - } -} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberDeleteRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberDeleteRequestDto.java index 387351b..dd9f310 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberDeleteRequestDto.java +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberDeleteRequestDto.java @@ -1,14 +1,10 @@ package AIWA.MCPBackend_Member.Dto; import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.Setter; @Getter -@NoArgsConstructor // 기본 생성자 추가 +@Setter public class MemberDeleteRequestDto { - private String email; // final 제거 - - public MemberDeleteRequestDto(String email) { - this.email = email; - } -} + private String email; +} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberRequestDto.java index e61ea7b..1db34d2 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberRequestDto.java +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberRequestDto.java @@ -1,16 +1,12 @@ package AIWA.MCPBackend_Member.Dto; import lombok.Getter; +import lombok.Setter; @Getter +@Setter public class MemberRequestDto { - private final String name; - private final String password; - private final String email; - - public MemberRequestDto(String name, String password, String email) { - this.name = name; - this.password = password; - this.email = email; - } + private String name; + private String email; + private String password; } \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java index 8218b2a..39fbf0b 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java @@ -1,22 +1,19 @@ package AIWA.MCPBackend_Member.Dto; - import AIWA.MCPBackend_Member.Entity.Member; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; -@Data +@Getter +@Setter public class MemberResponseDto { - private String userName; + private String name; private String email; - private String accessKey; - - public MemberResponseDto(String userName, String email, String accessKey) { - this.userName = userName; - this.email = email; - this.accessKey = accessKey; - } public static MemberResponseDto toDto(Member member) { - return new MemberResponseDto(member.getName(), member.getEmail(), member.getAccess_key()); + MemberResponseDto dto = new MemberResponseDto(); + dto.setName(member.getName()); + dto.setEmail(member.getEmail()); + return dto; } } \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java index 2c5efa1..a24940c 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java @@ -60,7 +60,7 @@ public List getAllMembers() { } - public Member addOrUpdateAwsKey(String email, String accessKey, String secretKey) { + public String addOrUpdateAwsKey(String email, String accessKey, String secretKey) { Member member = getMemberByEmail(email); // AWS 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 @@ -68,6 +68,8 @@ public Member addOrUpdateAwsKey(String email, String accessKey, String secretKey .filter(key -> "AWS".equalsIgnoreCase(key.getCompanyName())) .findFirst(); + String tfvarsUrl = ""; // URL을 반환할 변수 + if (existingAwsKey.isPresent()) { existingAwsKey.get().setAccessKey(accessKey); existingAwsKey.get().setSecretKey(secretKey); @@ -76,10 +78,15 @@ public Member addOrUpdateAwsKey(String email, String accessKey, String secretKey member.getAiwaKeys().add(awsKey); } - return memberRepository.save(member); + member = memberRepository.save(member); + + // S3에 AWS tfvars 파일 업로드 후 URL 반환 + tfvarsUrl = s3Service.createAwsTfvarsFile(email, accessKey, secretKey); + + return tfvarsUrl; // tfvars URL 반환 } - public Member addOrUpdateGcpKey(String email, String gcpKeyContent) { + public String addOrUpdateGcpKey(String email, String gcpKeyContent) { Member member = getMemberByEmail(email); // GCP 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 @@ -87,16 +94,26 @@ public Member addOrUpdateGcpKey(String email, String gcpKeyContent) { .filter(key -> "GCP".equalsIgnoreCase(key.getCompanyName())) .findFirst(); + String gcpKeyUrl = ""; // GCP 키 파일 URL을 저장할 변수 + if (existingGcpKey.isPresent()) { + // 기존 GCP 키를 업데이트 String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); existingGcpKey.get().setGcpKeyPath(gcpKeyPath); } else { + // 새 GCP 키를 추가 String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); AiwaKey gcpKey = new AiwaKey("GCP", null, null, gcpKeyPath, member); member.getAiwaKeys().add(gcpKey); } - return memberRepository.save(member); + // 회원을 저장 + member = memberRepository.save(member); + + // GCP 키의 S3 URL 반환 + gcpKeyUrl = s3Service.uploadGcpKeyFile(email, gcpKeyContent); + + return gcpKeyUrl; // GCP 키 파일 URL 반환 } public Member removeAwsKey(Long memberId) { From 4a0801cfe5cceb9da76d1172c26fd4e6d89281b5 Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 14:46:43 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#16=20Fix=20MemberResponseDto=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=B0=8F=20AIwaKeyResponseDto=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MemberController.java | 17 ++++++++- .../Dto/AiwaKeyResponseDto.java | 25 +++++++++++++ .../Dto/MemberResponseDto.java | 35 +++++++++++++++---- .../Service/member/MemberService.java | 6 ++-- 4 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/AiwaKeyResponseDto.java diff --git a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java index c6fcb5c..fd47e3b 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java +++ b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java @@ -37,7 +37,7 @@ public CommonResult deleteMember(@RequestBody MemberDeleteRequestDto deleteMembe memberService.deleteMember(deleteMemberRequestDto); return responseService.getSuccessResult(); } - + // 모든 회원 조회 @GetMapping("/all") public ListResult getAllMembers() { @@ -49,6 +49,21 @@ public ListResult getAllMembers() { return responseService.getListResult(memberResponseDtoList); } + + // 특정 회원 조회 (이메일로) + @GetMapping("/email/{email}") + public SingleResult getMemberByEmail(@PathVariable String email) { + // 특정 회원 조회 + Member member = memberService.getMemberByEmail(email); + if (member == null) { + throw new RuntimeException("Member not found with Email: " + email); // 예외 처리 + } + MemberResponseDto memberResponseDto = MemberResponseDto.toDto(member); + return responseService.getSingleResult(memberResponseDto); + } + + + // AWS 키 추가/업데이트 @PostMapping("/add-aws-key") public SingleResult addAwsKey(@RequestBody AddAwsKeyRequestDto addAwsKeyRequestDto) { diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/AiwaKeyResponseDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/AiwaKeyResponseDto.java new file mode 100644 index 0000000..cd7867b --- /dev/null +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/AiwaKeyResponseDto.java @@ -0,0 +1,25 @@ +package AIWA.MCPBackend_Member.Dto; + +import AIWA.MCPBackend_Member.Entity.AiwaKey; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AiwaKeyResponseDto { + + private String companyName; // 회사 이름 (AWS, GCP 등) + private String accessKey; // Access Key (AWS의 경우만 있을 수 있음) + private String secretKey; // Secret Key (AWS의 경우만 있을 수 있음) + private String gcpKeyPath; // GCP Key Path (GCP의 경우만 있을 수 있음) + + // Entity -> DTO 변환 메서드 + public static AiwaKeyResponseDto toDto(AiwaKey aiwaKey) { + AiwaKeyResponseDto dto = new AiwaKeyResponseDto(); + dto.setCompanyName(aiwaKey.getCompanyName()); + dto.setAccessKey(aiwaKey.getAccessKey()); + dto.setSecretKey(aiwaKey.getSecretKey()); + dto.setGcpKeyPath(aiwaKey.getGcpKeyPath()); + return dto; + } +} diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java index 39fbf0b..a4dcc25 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/MemberResponseDto.java @@ -1,19 +1,40 @@ package AIWA.MCPBackend_Member.Dto; import AIWA.MCPBackend_Member.Entity.Member; +import AIWA.MCPBackend_Member.Entity.AiwaKey; import lombok.Getter; import lombok.Setter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import java.util.stream.Collectors; @Getter @Setter public class MemberResponseDto { - private String name; - private String email; + private Long id; // 회원 ID + private String name; // 회원 이름 + private String email; // 회원 이메일 + + @JsonIgnore // 비밀번호는 반환하지 않음 + private String password; // 회원 비밀번호 + + private List aiwaKeys; // 회원이 관리하는 회사들의 키 정보 리스트 + + // Entity -> DTO 변환 메서드 public static MemberResponseDto toDto(Member member) { - MemberResponseDto dto = new MemberResponseDto(); - dto.setName(member.getName()); - dto.setEmail(member.getEmail()); - return dto; + MemberResponseDto memberResponseDto = new MemberResponseDto(); + memberResponseDto.setId(member.getId()); + memberResponseDto.setName(member.getName()); + memberResponseDto.setEmail(member.getEmail()); + memberResponseDto.setPassword(member.getPassword()); // 비밀번호는 필요 없다면 제외 가능 + + // AiwaKey 리스트를 AiwaKeyResponseDto 리스트로 변환 + List aiwaKeyResponseDtoList = member.getAiwaKeys().stream() + .map(AiwaKeyResponseDto::toDto) + .collect(Collectors.toList()); + memberResponseDto.setAiwaKeys(aiwaKeyResponseDtoList); + + return memberResponseDto; } -} \ No newline at end of file +} diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java index a24940c..17be379 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java @@ -47,10 +47,6 @@ public void deleteMember(MemberDeleteRequestDto deleteMemberRequestDto) { // 특정 회원 조회 - public Optional getMemberById(Long id) { - return memberRepository.findById(id); - } - public Member getMemberByEmail(String email) { return memberRepository.findByEmail(email); } @@ -116,6 +112,8 @@ public String addOrUpdateGcpKey(String email, String gcpKeyContent) { return gcpKeyUrl; // GCP 키 파일 URL 반환 } + + public Member removeAwsKey(Long memberId) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new RuntimeException("Member not found")); From 83fdf8fe1d10e69c33a14e354a67af221e36c0f6 Mon Sep 17 00:00:00 2001 From: gytjd Date: Wed, 13 Nov 2024 15:20:45 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#16=20Fix:=20=EB=91=90=20Provider=20?= =?UTF-8?q?=ED=82=A4=20=EB=8F=99=EC=8B=9C=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/MemberController.java | 33 ++++-------- ...to.java => AddAwsAndGcpKeyRequestDto.java} | 6 +-- .../Dto/AddGcpKeyRequestDto.java | 12 ----- .../MCPBackend_Member/Entity/AiwaKey.java | 18 +++---- .../Service/member/MemberService.java | 52 ++++--------------- 5 files changed, 31 insertions(+), 90 deletions(-) rename src/main/java/AIWA/MCPBackend_Member/Dto/{AddAwsKeyRequestDto.java => AddAwsAndGcpKeyRequestDto.java} (70%) delete mode 100644 src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java diff --git a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java index fd47e3b..0f84a88 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java +++ b/src/main/java/AIWA/MCPBackend_Member/Controller/MemberController.java @@ -50,9 +50,8 @@ public ListResult getAllMembers() { } - // 특정 회원 조회 (이메일로) - @GetMapping("/email/{email}") - public SingleResult getMemberByEmail(@PathVariable String email) { + @GetMapping("/email") + public SingleResult getMemberByEmail(@RequestParam String email) { // 특정 회원 조회 Member member = memberService.getMemberByEmail(email); if (member == null) { @@ -64,27 +63,17 @@ public SingleResult getMemberByEmail(@PathVariable String ema - // AWS 키 추가/업데이트 - @PostMapping("/add-aws-key") - public SingleResult addAwsKey(@RequestBody AddAwsKeyRequestDto addAwsKeyRequestDto) { - // AWS 키 추가 및 S3 URL 반환 - String tfvarsUrl = memberService.addOrUpdateAwsKey( - addAwsKeyRequestDto.getEmail(), - addAwsKeyRequestDto.getAccessKey(), - addAwsKeyRequestDto.getSecretKey() - ); - return responseService.getSingleResult(tfvarsUrl); - } - // GCP 키 추가/업데이트 - @PostMapping("/add-gcp-key") - public SingleResult addGcpKey(@RequestBody AddGcpKeyRequestDto addGcpKeyRequestDto) { - // GCP 키 추가 및 S3 URL 반환 - String gcpKeyUrl = memberService.addOrUpdateGcpKey( - addGcpKeyRequestDto.getEmail(), - addGcpKeyRequestDto.getGcpKeyContent() + // AWS 키 추가/업데이트 + @PostMapping("/add-aws-gcp-key") + public SingleResult addAwsAndGcpKey(@RequestBody AddAwsAndGcpKeyRequestDto requestDto) { + String result = memberService.addOrUpdateAwsAndGcpKey( + requestDto.getEmail(), + requestDto.getAccessKey(), + requestDto.getSecretKey(), + requestDto.getGcpKeyContent() ); - return responseService.getSingleResult(gcpKeyUrl); + return responseService.getSingleResult(result); } // AWS 키 삭제 diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsAndGcpKeyRequestDto.java similarity index 70% rename from src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java rename to src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsAndGcpKeyRequestDto.java index 8a40580..a4263d9 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsKeyRequestDto.java +++ b/src/main/java/AIWA/MCPBackend_Member/Dto/AddAwsAndGcpKeyRequestDto.java @@ -5,9 +5,9 @@ @Getter @Setter -public class AddAwsKeyRequestDto { +public class AddAwsAndGcpKeyRequestDto { private String email; private String accessKey; private String secretKey; - private String companyName; -} \ No newline at end of file + private String gcpKeyContent; +} diff --git a/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java b/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java deleted file mode 100644 index a0a7659..0000000 --- a/src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java +++ /dev/null @@ -1,12 +0,0 @@ -package AIWA.MCPBackend_Member.Dto; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class AddGcpKeyRequestDto { - private String email; - private String gcpKeyContent; - private String companyName; -} \ No newline at end of file diff --git a/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java index b7960bc..65f6823 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java +++ b/src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java @@ -13,22 +13,18 @@ public class AiwaKey { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "aiwa_key_id") private Long id; @Column(nullable = false) - private String companyName; // 고객 회사 이름 + private String companyName; - @Column(length = 1000) - private String accessKey; // AWS Access Key - - @Column(length = 1000) - private String secretKey; // AWS Secret Key - - @Column(length = 2048) - private String gcpKeyPath; // GCP 키 파일 S3 경로 + private String accessKey; + private String secretKey; + private String gcpKeyPath; @ManyToOne - @JoinColumn(name = "member_id", nullable = false) + @JoinColumn(name = "member_id") private Member member; public AiwaKey(String companyName, String accessKey, String secretKey, String gcpKeyPath, Member member) { @@ -38,4 +34,4 @@ public AiwaKey(String companyName, String accessKey, String secretKey, String gc this.gcpKeyPath = gcpKeyPath; this.member = member; } -} \ No newline at end of file +} diff --git a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java index 17be379..0b88b9c 100644 --- a/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java +++ b/src/main/java/AIWA/MCPBackend_Member/Service/member/MemberService.java @@ -56,60 +56,28 @@ public List getAllMembers() { } - public String addOrUpdateAwsKey(String email, String accessKey, String secretKey) { + public String addOrUpdateAwsAndGcpKey(String email, String accessKey, String secretKey, String gcpKeyContent) { Member member = getMemberByEmail(email); - // AWS 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 + // 키가 하나의 회사에 대해 AWS와 GCP를 모두 처리할 수 있도록 합니다. Optional existingAwsKey = member.getAiwaKeys().stream() .filter(key -> "AWS".equalsIgnoreCase(key.getCompanyName())) .findFirst(); - String tfvarsUrl = ""; // URL을 반환할 변수 - if (existingAwsKey.isPresent()) { - existingAwsKey.get().setAccessKey(accessKey); - existingAwsKey.get().setSecretKey(secretKey); + AiwaKey awsKey = existingAwsKey.get(); + awsKey.setAccessKey(accessKey); + awsKey.setSecretKey(secretKey); + // GCP 키를 추가할 경우 GCP Key Path를 업데이트 + awsKey.setGcpKeyPath(s3Service.uploadGcpKeyFile(email, gcpKeyContent)); } else { - AiwaKey awsKey = new AiwaKey("AWS", accessKey, secretKey, null, member); - member.getAiwaKeys().add(awsKey); + AiwaKey newKey = new AiwaKey("AWS", accessKey, secretKey, s3Service.uploadGcpKeyFile(email, gcpKeyContent), member); + member.getAiwaKeys().add(newKey); } member = memberRepository.save(member); - // S3에 AWS tfvars 파일 업로드 후 URL 반환 - tfvarsUrl = s3Service.createAwsTfvarsFile(email, accessKey, secretKey); - - return tfvarsUrl; // tfvars URL 반환 - } - - public String addOrUpdateGcpKey(String email, String gcpKeyContent) { - Member member = getMemberByEmail(email); - - // GCP 키가 있는지 확인하고, 있으면 업데이트, 없으면 추가 - Optional existingGcpKey = member.getAiwaKeys().stream() - .filter(key -> "GCP".equalsIgnoreCase(key.getCompanyName())) - .findFirst(); - - String gcpKeyUrl = ""; // GCP 키 파일 URL을 저장할 변수 - - if (existingGcpKey.isPresent()) { - // 기존 GCP 키를 업데이트 - String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); - existingGcpKey.get().setGcpKeyPath(gcpKeyPath); - } else { - // 새 GCP 키를 추가 - String gcpKeyPath = s3Service.uploadGcpKeyFile(email, gcpKeyContent); - AiwaKey gcpKey = new AiwaKey("GCP", null, null, gcpKeyPath, member); - member.getAiwaKeys().add(gcpKey); - } - - // 회원을 저장 - member = memberRepository.save(member); - - // GCP 키의 S3 URL 반환 - gcpKeyUrl = s3Service.uploadGcpKeyFile(email, gcpKeyContent); - - return gcpKeyUrl; // GCP 키 파일 URL 반환 + return "AWS and GCP keys have been successfully added or updated."; }