Skip to content

Commit

Permalink
#16 Fix: 두 Provider 키 동시 등록 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gytjd committed Nov 13, 2024
1 parent 4a0801c commit 83fdf8f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ public ListResult<MemberResponseDto> getAllMembers() {
}


// 특정 회원 조회 (이메일로)
@GetMapping("/email/{email}")
public SingleResult<MemberResponseDto> getMemberByEmail(@PathVariable String email) {
@GetMapping("/email")
public SingleResult<MemberResponseDto> getMemberByEmail(@RequestParam String email) {
// 특정 회원 조회
Member member = memberService.getMemberByEmail(email);
if (member == null) {
Expand All @@ -64,27 +63,17 @@ public SingleResult<MemberResponseDto> getMemberByEmail(@PathVariable String ema



// AWS 키 추가/업데이트
@PostMapping("/add-aws-key")
public SingleResult<String> 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<String> addGcpKey(@RequestBody AddGcpKeyRequestDto addGcpKeyRequestDto) {
// GCP 키 추가 및 S3 URL 반환
String gcpKeyUrl = memberService.addOrUpdateGcpKey(
addGcpKeyRequestDto.getEmail(),
addGcpKeyRequestDto.getGcpKeyContent()
// AWS 키 추가/업데이트
@PostMapping("/add-aws-gcp-key")
public SingleResult<String> 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 키 삭제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

@Getter
@Setter
public class AddAwsKeyRequestDto {
public class AddAwsAndGcpKeyRequestDto {
private String email;
private String accessKey;
private String secretKey;
private String companyName;
}
private String gcpKeyContent;
}
12 changes: 0 additions & 12 deletions src/main/java/AIWA/MCPBackend_Member/Dto/AddGcpKeyRequestDto.java

This file was deleted.

18 changes: 7 additions & 11 deletions src/main/java/AIWA/MCPBackend_Member/Entity/AiwaKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -38,4 +34,4 @@ public AiwaKey(String companyName, String accessKey, String secretKey, String gc
this.gcpKeyPath = gcpKeyPath;
this.member = member;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,60 +56,28 @@ public List<Member> 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<AiwaKey> 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<AiwaKey> 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.";
}


Expand Down

0 comments on commit 83fdf8f

Please sign in to comment.