Skip to content

Commit

Permalink
Merge pull request #101 from AWS-Cloud-School-6/100-fix-gcp-json-키파일-…
Browse files Browse the repository at this point in the history
…등록-에러-해결

#100 [Fix]: GCP json 키파일 등록 문제 해결
  • Loading branch information
integer-bin authored Nov 26, 2024
2 parents 5611b09 + 4dc6246 commit 66bfeb3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 18 additions & 4 deletions aiwa-mcp-frontend/src/Console/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function MyPage({ provider }) {
}, []);

const handleSubmit = async () => {
let response = null;
try {
// 기존 회사 정보 확인
let existingKeys = null;
Expand All @@ -106,18 +107,31 @@ function MyPage({ provider }) {
finalGcpKeyFile = existingKeys.gcpKeyFile || null;
}

const url = `${MEMBER_API_URL}/members/add-aws-gcp-key?email=${encodeURIComponent(currentUser?.id)}&companyName=${encodeURIComponent(companyName)}&accessKey=${encodeURIComponent(finalAccessKey)}&secretKey=${encodeURIComponent(finalSecretKey)}&projectId=${encodeURIComponent(finalProjectId)}`;

// 새로운 키 정보로 업데이트
if (provider === 'AWS') {
finalAccessKey = accessKey;
finalSecretKey = secretKey;
response = await axios.post(url);
} else if (provider === 'GCP') {
finalProjectId = projectId;
finalGcpKeyFile = gcpKeyFile;
}

// FormData 객체 생성
const formData = new FormData();

// JSON 문자열을 Blob으로 변환하여 파일로 추가
const jsonBlob = new Blob([gcpKeyFile], { type: 'application/json' });
formData.append('gcpKeyFile', jsonBlob, 'gcpKey.json');

const url = `${MEMBER_API_URL}/members/add-aws-gcp-key?email=${encodeURIComponent(currentUser?.id)}&companyName=${encodeURIComponent(companyName)}&accessKey=${encodeURIComponent(finalAccessKey)}&secretKey=${encodeURIComponent(finalSecretKey)}&projectId=${encodeURIComponent(finalProjectId)}&gcpKeyFile=${encodeURIComponent(finalGcpKeyFile)}`;
// FormData와 함께 POST 요청 전송
response = await axios.post(url, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
}

const response = await axios.post(url);
console.log('API 응답:', response.data.msg);
alert('키 성공적으로 제출');
window.location.href = '/console'; // Redirect to console page first
Expand Down
8 changes: 7 additions & 1 deletion aiwa-mcp-frontend/src/Console/SideBar/SidebarConsole.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ function SidebarConsole({ onSelectProvider }) {
<p>Access Key: {maskAccessKey(key.accessKey)}</p>
<p>Secret Key: {maskAccessKey(key.secretKey)}</p>
<p>Project ID: {key.projectId}</p>
{key.gcpKeyPath && <p>GCP Key Path: {key.gcpKeyPath}</p>}
{key.gcpKeyPath && (
<p style={{
wordBreak: 'break-all'
}}>
GCP Key Path: {key.gcpKeyPath}
</p>
)}
</div>
))}
</div>
Expand Down

0 comments on commit 66bfeb3

Please sign in to comment.