|
|
@@ -3,6 +3,7 @@ package cn.reghao.devops.mgr.ops.build.service;
|
|
|
import cn.reghao.devops.common.docker.DockerImpl;
|
|
|
import cn.reghao.devops.common.docker.model.DockerAuth;
|
|
|
import cn.reghao.devops.mgr.ops.build.db.repository.RepoAuthConfigRepository;
|
|
|
+import cn.reghao.devops.mgr.ops.build.model.constant.RepoAuthType;
|
|
|
import cn.reghao.devops.mgr.ops.build.model.dto.DockerRegistryDto;
|
|
|
import cn.reghao.devops.mgr.ops.build.model.po.RepoAuthConfig;
|
|
|
import cn.reghao.devops.mgr.ops.docker.db.repository.DockerRegistryRepository;
|
|
|
@@ -33,22 +34,25 @@ public class DockerRegistryService {
|
|
|
return Result.fail(String.format("RepoAuthName %s not exists", repoAuthName));
|
|
|
}
|
|
|
|
|
|
- DockerAuth dockerAuth = new DockerAuth();
|
|
|
- dockerAuth.setRegistryUrl(dockerRegistryDto.getRegistryUrl());
|
|
|
- dockerAuth.setUsername(repoAuthConfig.getUsername());
|
|
|
- dockerAuth.setPassword(repoAuthConfig.getPassword());
|
|
|
- DockerImpl docker = new DockerImpl();
|
|
|
- docker.auth(dockerAuth);
|
|
|
+ if (repoAuthConfig.getAuthType().equals(RepoAuthType.http.name())) {
|
|
|
+ DockerAuth dockerAuth = new DockerAuth();
|
|
|
+ dockerAuth.setRegistryUrl(dockerRegistryDto.getRegistryUrl());
|
|
|
+ dockerAuth.setUsername(repoAuthConfig.getUsername());
|
|
|
+ dockerAuth.setPassword(repoAuthConfig.getPassword());
|
|
|
+ DockerImpl docker = new DockerImpl();
|
|
|
+ docker.auth(dockerAuth);
|
|
|
+ }
|
|
|
|
|
|
- String registryUrl = dockerAuth.getRegistryUrl();
|
|
|
- DockerRegistry dockerRegistry = dockerAuthRepository.findByRegistryUrl(registryUrl);
|
|
|
+ String registryUrl = dockerRegistryDto.getRegistryUrl();
|
|
|
+ String registryNamespace = dockerRegistryDto.getRegistryNamespace();
|
|
|
+ DockerRegistry dockerRegistry = dockerAuthRepository.findByRegistryUrlAndRegistryNamespace(registryUrl, registryNamespace);
|
|
|
if (dockerRegistry == null) {
|
|
|
dockerRegistry = new DockerRegistry(dockerRegistryDto, repoAuthConfig);
|
|
|
dockerAuthRepository.save(dockerRegistry);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- return Result.fail(String.format("%s already exists", dockerRegistry.getRegistryUrl()));
|
|
|
+ return Result.fail(String.format("%s/%s already exists", registryUrl, registryNamespace));
|
|
|
}
|
|
|
|
|
|
public Result delete(int id) {
|