Skip to content

Commit

Permalink
Merge pull request #13 from AWS-Cloud-School-6/12-feat-s3-company-spe…
Browse files Browse the repository at this point in the history
…cific-directing

#12 Feat: S3 Company-Specific Directing
  • Loading branch information
nareunhang authored Nov 13, 2024
2 parents 44ec6d8 + e8ffa04 commit d17d158
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package AIWA.MCPBackend_Member.Controller;


import AIWA.MCPBackend_Member.Dto.MemberCredentialDTO;
import AIWA.MCPBackend_Member.Dto.MemberDeleteRequestDto;
import AIWA.MCPBackend_Member.Dto.MemberRequestDto;
import AIWA.MCPBackend_Member.Dto.MemberResponseDto;
import AIWA.MCPBackend_Member.Dto.*;
import AIWA.MCPBackend_Member.Entity.Member;
import AIWA.MCPBackend_Member.Service.member.MemberService;
import AIWA.MCPBackend_Member.Service.response.ResponseService;
Expand Down Expand Up @@ -73,10 +70,10 @@ public ListResult<MemberResponseDto> getAllMembers() {
}

@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());
public CommonResult updateCredentials(@RequestBody CompanyDto companyDto) {
System.out.println(companyDto.getAccessKey());
System.out.println(companyDto.getSecretKey());
memberService.addOrUpdateKeys(companyDto.getUserId(),companyDto.getCompany(),companyDto.getAccessKey(), companyDto.getSecretKey());
return responseService.getSuccessResult();
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/AIWA/MCPBackend_Member/Dto/CompanyDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public Member registerMember(MemberRequestDto memberRequestDto) {
if (memberRepository.findByEmail(memberRequestDto.getEmail()) != null) {
throw new RuntimeException("Email already exists");
}
s3Service.createUserDirectory(memberRequestDto.getEmail());
Member regiMember=new Member(memberRequestDto.getName(), memberRequestDto.getPassword(), memberRequestDto.getEmail());
return memberRepository.save(regiMember);
}
Expand Down Expand Up @@ -58,12 +57,13 @@ public List<Member> getAllMembers() {
}


public Member addOrUpdateKeys(String email,String access_key,String secret_key) {
public Member addOrUpdateKeys(String email, String company,String access_key,String secret_key) {

Member member = getMemberByEmail(email);
member.setAccess_key(access_key);
member.setSecret_key(secret_key);
s3Service.createTfvarsFile(email,access_key,secret_key);
s3Service.createUserDirectory(company);
s3Service.createTfvarsFile(company,access_key,secret_key);
return memberRepository.save(member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class S3Service {
private final AmazonS3 s3Client;
private final String bucketName = "aiwa-terraform";

public void createUserDirectory(String userId) {
String userPrefix = "users/" + userId + "/";
public void createUserDirectory(String company) {
String userPrefix = "users/" + company + "/";
// 초기 main.tf 및 terraform.tfstate 파일을 업로드합니다
uploadInitialFiles(userPrefix);
}
Expand Down Expand Up @@ -64,8 +64,8 @@ public void deleteUserDirectory(String userId) {
}


public void createTfvarsFile(String userId, String accessKey, String secretKey) {
String userPrefix = "users/" + userId + "/";
public void createTfvarsFile(String company, String accessKey, String secretKey) {
String userPrefix = "users/" + company + "/";
String tfvarsContent = String.format("""
aws_access_key = "%s"
aws_secret_key = "%s"
Expand Down

0 comments on commit d17d158

Please sign in to comment.