Skip to content

Commit

Permalink
Merge pull request #18 from Strato-YangSungHun/main
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Strato-YangSungHun authored Sep 25, 2024
2 parents bbe28f8 + 6ffd49b commit c0b0713
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion WIKI.md

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions src/main/java/kr/co/mcmp/oss/service/OssServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public List<OssDto> getOssList(String ossTypeName) {
.collect(Collectors.toList());

// ossTypeList에서 ossTypeIdx 목록을 추출
List<Long> ossTypeIdxList = ossTypeList.stream()
List<Long> ossTypeIdxList = ossTypeList
.stream()
.map(OssTypeDto::getOssTypeIdx)
.collect(Collectors.toList());

Expand All @@ -98,7 +99,7 @@ public List<OssDto> getOssList(String ossTypeName) {
if ( !CollectionUtils.isEmpty(ossList) ) {
ossList = ossList
.stream()
.map(ossDto -> OssDto.setEncryptPassword(ossDto, decryptAesString(ossDto.getOssPassword())))
.map(ossDto -> OssDto.setDecryptPassword(ossDto, decryptAesString(ossDto.getOssPassword())))
.collect(Collectors.toList());
}

Expand All @@ -119,17 +120,15 @@ public List<OssDto> getOssList(String ossTypeName) {
@Transactional
public Long registOss(OssDto ossDto) {
try {
OssType ossTypeEntity = ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx());
OssTypeDto ossTypeDto = OssTypeDto.from(ossTypeEntity);

OssDto encriptOssDto = ossDto.setEncryptPassword(ossDto, encryptAesString(ossDto.getOssPassword()));
OssTypeDto ossTypeDto = OssTypeDto.from(ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx()));

Oss ossEntity = OssDto.toEntity(encriptOssDto, ossTypeDto);
ossEntity = ossRepository.save(ossEntity);
ossDto = ossDto.setEncryptPassword(ossDto, encryptAesString(ossDto.getOssPassword()));
ossDto = OssDto.from(ossRepository.save(OssDto.toEntity(ossDto, ossTypeDto)));

workflowServiceImpl.createJenkinsJob(ossTypeDto, ossDto);
if("JENKINS".equals(ossTypeDto.getOssTypeName().toUpperCase()))
workflowServiceImpl.createJenkinsJob(ossTypeDto, ossDto);

return ossEntity.getOssIdx();
return ossDto.getOssIdx();
} catch (Exception e) {
log.error(e.getMessage());
return null;
Expand All @@ -145,16 +144,15 @@ public Long registOss(OssDto ossDto) {
public Boolean updateOss(OssDto ossDto) {
Boolean result = false;
try {
OssType ossTypeEntity = ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx());
OssTypeDto ossTypeDto = OssTypeDto.from(ossTypeEntity);

OssDto encriptOssDto = ossDto.setEncryptPassword(ossDto, encryptAesString(ossDto.getOssPassword()));

managedJenkinsCredential(encriptOssDto, "update");
OssTypeDto ossTypeDto = OssTypeDto.from(ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx()));
ossDto = ossDto.setEncryptPassword(ossDto, encryptAesString(ossDto.getOssPassword()));

ossRepository.save(OssDto.toEntity(encriptOssDto, ossTypeDto));
ossRepository.save(OssDto.toEntity(ossDto, ossTypeDto));

workflowServiceImpl.createJenkinsJob(ossTypeDto, encriptOssDto);
if("JENKINS".equals(ossTypeDto.getOssTypeName().toUpperCase())) {
managedJenkinsCredential(ossDto, "update");
workflowServiceImpl.createJenkinsJob(ossTypeDto, ossDto);
}

result = true;
} catch (Exception e) {
Expand All @@ -179,13 +177,17 @@ public Boolean deleteOss(Long ossIdx) {
Oss ossEntity = ossRepository.findByOssIdx(ossIdx);
OssDto ossDto = OssDto.from(ossEntity);

if(ossDto.getOssPassword() != null)
managedJenkinsCredential(ossDto, "delete");

if(!workflowRepository.existsByOss_OssIdx(ossIdx)) {
ossRepository.deleteByOssIdx(ossIdx);
result = true;
}

OssTypeDto ossTypeDto = OssTypeDto.from(ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx()));
if("JENKINS".equals(ossTypeDto.getOssTypeName().toUpperCase())) {
if(ossDto.getOssPassword() != null)
managedJenkinsCredential(ossDto, "delete");
}

} catch (Exception e) {
log.error(e.getMessage());
}
Expand All @@ -203,7 +205,7 @@ public Boolean checkConnection(OssDto ossDto) {
OssTypeDto osstypeDto = OssTypeDto.from(ossTypeRepository.findByOssTypeIdx(ossDto.getOssTypeIdx()));

if(!osstypeDto.getOssTypeName().isEmpty()) {
switch(osstypeDto.getOssTypeName()) {
switch(osstypeDto.getOssTypeName().toUpperCase()) {
case "JENKINS" :
if (StringUtils.isBlank(ossDto.getOssUrl()) ||
StringUtils.isBlank(ossDto.getOssUsername()) ||
Expand Down Expand Up @@ -278,7 +280,7 @@ public OssDto detailOss(Long ossIdx) {
try {
Oss ossEntity = ossRepository.findByOssIdx(ossIdx);
OssDto ossDto = OssDto.from(ossEntity);
return OssDto.setDecryptPassword(ossDto, encodingBase64String(decryptAesString(ossEntity.getOssPassword())));
return OssDto.setDecryptPassword(ossDto, decryptAesString(ossEntity.getOssPassword()));
} catch (Exception e) {
log.error(e.getMessage());
return null;
Expand Down Expand Up @@ -350,7 +352,7 @@ public String encryptBase64String(String str) {
*/
public String encryptAesString(String str) {
if ( StringUtils.isNotBlank(str) ) {
return AES256Util.encrypt(Base64Util.base64Decoding(str));
return AES256Util.encrypt(str);
}
else {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ public void createJenkinsJob(OssTypeDto ossTypeDto, OssDto ossDto) {
workflowResDto.getWorkflowInfo().getScript(),
workflowResDto.getWorkflowParams());
}
log.info("Jenkins Job 생성 완료 : {}", isExistJob);
}
}
} catch (IOException ioe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;

import kr.co.mcmp.util.Base64Util;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class JenkinsRestApi {
* JenkinsClient Object 획득
*/
private JenkinsClient getJenkinsClient(String url, String id, String password) {
String plainTextPassword = AES256Util.decrypt(password);
String plainTextPassword = Base64Util.base64Decoding(AES256Util.decrypt(password));

return JenkinsClient.builder().endPoint(url)
.credentials(id + ":" + plainTextPassword)
Expand All @@ -57,7 +58,7 @@ private JenkinsClient getJenkinsClient(String url, String id, String password) {
public boolean isConnect(String url, String id, String password) {
boolean isRunning = false;
try {
String plainTextPassword = AES256Util.decrypt(password);
String plainTextPassword = Base64Util.base64Decoding(AES256Util.decrypt(password));

JenkinsClient jenkinsClient = JenkinsClient.builder().endPoint(url)
.credentials(id + ":" + plainTextPassword).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javax.xml.xpath.XPathExpressionException;

import com.cdancy.jenkins.rest.domain.job.BuildInfo;
import kr.co.mcmp.util.AES256Util;
import kr.co.mcmp.util.Base64Util;
import kr.co.mcmp.workflow.service.jenkins.api.JenkinsRestApi;
import kr.co.mcmp.oss.dto.OssDto;
import kr.co.mcmp.workflow.dto.entityMappingDto.WorkflowParamDto;
Expand Down Expand Up @@ -55,6 +57,7 @@ public boolean isJenkinsConnect(OssDto jenkins) {
public boolean isExistJobName(OssDto jenkins, String jobName) {
return Optional.ofNullable(api.getJenkinsJob(jenkins.getOssUrl(), jenkins.getOssUsername(), jenkins.getOssPassword(), jobName)).isPresent();
}

/*****
* jenkins job 생성
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0b0713

Please sign in to comment.