Parcourir la source

添加 DockerAuth 配置页面和接口

reghao il y a 1 an
Parent
commit
97f067e3b9

+ 16 - 0
common/src/main/java/cn/reghao/bnt/common/docker/po/DockerRegistry.java

@@ -0,0 +1,16 @@
+package cn.reghao.bnt.common.docker.po;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author reghao
+ * @date 2024-07-26 17:29:56
+ */
+@AllArgsConstructor
+@Getter
+public class DockerRegistry {
+    private String registryUrl;
+    private String username;
+    private String password;
+}

+ 83 - 0
web/src/main/java/cn/reghao/bnt/web/devops/app/controller/page/DockerAuthPageController.java

@@ -0,0 +1,83 @@
+package cn.reghao.bnt.web.devops.app.controller.page;
+
+import cn.reghao.bnt.web.devops.app.db.repository.DockerAuthRepository;
+import cn.reghao.bnt.web.devops.app.model.po.DockerAuth;
+import cn.reghao.bnt.web.devops.app.model.vo.KeyValue;
+import cn.reghao.bnt.web.devops.build.model.constant.RepoAuthType;
+import cn.reghao.bnt.web.devops.build.model.constant.RepoType;
+import cn.reghao.bnt.web.util.db.PageSort;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2024-07-26 17:36:37
+ */
+@Api(tags = "Docker 认证配置页面")
+@Controller
+@RequestMapping("/app/config/docker")
+public class DockerAuthPageController {
+    private final DockerAuthRepository dockerAuthRepository;
+
+    public DockerAuthPageController(DockerAuthRepository dockerAuthRepository) {
+        this.dockerAuthRepository = dockerAuthRepository;
+    }
+
+    @ApiOperation(value = "仓库认证列表页面")
+    @GetMapping("/auth")
+    public String repoAuthPage(Model model) {
+        PageRequest pageRequest = PageSort.pageRequest();
+        Page<DockerAuth> page = dockerAuthRepository.findAll(pageRequest);
+
+        model.addAttribute("page", page);
+        model.addAttribute("list", page.getContent());
+        return "/devops/app/config/docker/index";
+    }
+
+    @ApiOperation(value = "仓库认证添加页面")
+    @GetMapping("/auth/add")
+    public String addRepoAuthPage(Model model) {
+        setRepoAuthModel(model);
+        return "/devops/app/config/docker/add";
+    }
+
+    @ApiOperation(value = "仓库认证编辑页面")
+    @GetMapping("/auth/edit/{id}")
+    public String editRepoAuthPage(@PathVariable("id") DockerAuth repoAuth, Model model) {
+        repoAuth.setNull();
+        model.addAttribute("repoAuth", repoAuth);
+        return "/devops/app/config/docker/edit";
+    }
+
+    private void setRepoAuthModel(Model model) {
+        List<KeyValue> repos = new ArrayList<>();
+        for (RepoType repoType : RepoType.values()) {
+            repos.add(new KeyValue(repoType.name(), repoType.name()));
+        }
+
+        List<KeyValue> auths = new ArrayList<>();
+        for (RepoAuthType authType : RepoAuthType.values()) {
+            auths.add(new KeyValue(authType.name(), authType.name()));
+        }
+
+        model.addAttribute("repos", repos);
+        model.addAttribute("auths", auths);
+    }
+
+    @GetMapping("/auth/detail/{id}")
+    public String repoAuthDetailPage(@PathVariable("id") DockerAuth repoAuth, Model model) {
+        repoAuth.setPassword("******");
+        model.addAttribute("repoAuth", repoAuth);
+        return "/devops/app/config/docker/detail";
+    }
+}

+ 12 - 0
web/src/main/java/cn/reghao/bnt/web/devops/app/db/repository/DockerAuthRepository.java

@@ -0,0 +1,12 @@
+package cn.reghao.bnt.web.devops.app.db.repository;
+
+import cn.reghao.bnt.web.devops.app.model.po.DockerAuth;
+import org.springframework.data.jpa.repository.JpaRepository;
+
+/**
+ * @author reghao
+ * @date 2024-07-26 17:26:16
+ */
+public interface DockerAuthRepository extends JpaRepository<DockerAuth, Integer> {
+    DockerAuth findByRegistryUrl(String registryUrl);
+}

+ 28 - 0
web/src/main/java/cn/reghao/bnt/web/devops/app/model/po/DockerAuth.java

@@ -0,0 +1,28 @@
+package cn.reghao.bnt.web.devops.app.model.po;
+
+import cn.reghao.bnt.web.util.db.BaseEntity;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author reghao
+ * @date 2024-07-26 17:24:57
+ */
+@NoArgsConstructor
+@Getter
+@Setter
+@Entity
+@Table(name = "devops_docker_auth")
+public class DockerAuth extends BaseEntity {
+    @Column(nullable = false, unique = true)
+    @NotBlank(message = "docker registry 不能为空字符串")
+    private String registryUrl;
+    private String username;
+    private String password;
+}

+ 82 - 0
web/src/main/resources/templates/devops/app/config/docker/add.html

@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+
+<body>
+<div class="layui-form timo-compile">
+    <form th:action="@{/api/app/config/build/repoauth}">
+        <div class="layui-form-item">
+            <label class="layui-form-label required">仓库类型<i id="repo_type_tips" class="fa fa-question-circle"></i></label>
+            <div class="layui-input-inline">
+                <select name="type">
+                    <option th:each="item : ${repos}" th:value="${item.key}">[[${item.value}]]</option>
+                </select>
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label required">认证名字</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="name" placeholder="请输入认证名字" required>
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label required">认证类型<i id="repo_auth_type_tips" class="fa fa-question-circle"></i></label>
+            <div class="layui-input-inline">
+                <select name="authType">
+                    <option th:each="item : ${auths}" th:value="${item.key}">[[${item.value}]]</option>
+                </select>
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label">用户名</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="username" placeholder="请输入用户名">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label">密码</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="password" placeholder="请输入密码">
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label">RSA 私钥</label>
+            <div class="layui-input-inline">
+                <textarea class="layui-textarea" name="rsaPrikey" placeholder="请输入 RSA 私钥"></textarea>
+            </div>
+        </div>
+        <div class="layui-form-item timo-finally">
+            <button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 保存</button>
+            <button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
+        </div>
+    </form>
+</div>
+
+<script th:replace="/common/template :: script"></script>
+<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
+<script type="text/javascript" th:inline="javascript">
+    $(function () {
+        $("#repo_type_tips").hover(function () {
+            var tips = layer.tips('目前仅支持 git 仓库<br />', '#repo_type_tips',{
+                tips: [1, '#555555']
+            });
+            sleep(1000);
+            layer.close(tips);
+        })
+
+        $("#repo_auth_type_tips").hover(function () {
+            var tips = layer.tips(
+                '仓库不需要认证则选择 none 类型<br/>' +
+                'http 认证类型必须填写用户名和密码<br/>' +
+                'ssh 认证必须填写 RSA 私钥<br/>',
+                '#repo_auth_type_tips',{
+                tips: [1, '#555555']
+            });
+            sleep(1000);
+            layer.close(tips);
+        })
+    })
+</script>
+</body>
+</html>

+ 35 - 0
web/src/main/resources/templates/devops/app/config/docker/detail.html

@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+<body>
+    <div class="timo-detail-page">
+        <table class="layui-table timo-detail-table">
+            <tbody>
+            <tr>
+                <th>仓库类型</th>
+                <td th:text="${repoAuth.type}"></td>
+                <th>认证名字</th>
+                <td th:text="${repoAuth.name}"></td>
+            </tr>
+            <tr>
+                <th>认证方式</th>
+                <td th:text="${repoAuth.authType}"></td>
+                <span th:if="${repoAuth.authType} == 'ssh'">
+                    <th>RSA 私钥</th>
+                    <td>
+                        <textarea class="layui-textarea" readonly="readonly" th:text="${repoAuth.rsaPrikey}"></textarea>
+                    </td>
+                </span>
+                <span th:if="${repoAuth.authType} == 'http'">
+                    <th>用户名</th>
+                    <td th:text="${repoAuth.username}"></td>
+                    <th>密码</th>
+                    <td th:text="${repoAuth.password}"></td>
+                </span>
+            </tr>
+            </tbody>
+        </table>
+    </div>
+<script th:replace="/common/template :: script"></script>
+</body>
+</html>

+ 57 - 0
web/src/main/resources/templates/devops/app/config/docker/edit.html

@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+
+<body>
+<div class="layui-form timo-compile">
+    <form th:action="@{/api/app/config/build/repoauth}">
+        <div class="layui-form-item">
+            <label class="layui-form-label required">仓库类型</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="type" th:value="${repoAuth.type}" readonly>
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label required">认证名字</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="name" th:value="${repoAuth.name}" readonly>
+            </div>
+        </div>
+        <div class="layui-form-item">
+            <label class="layui-form-label required">认证类型</label>
+            <div class="layui-input-inline">
+                <input class="layui-input" type="text" name="authType" th:value="${repoAuth.authType}" readonly>
+            </div>
+        </div>
+        <div th:if="${repoAuth.getAuthType()} == 'http'">
+            <div class="layui-form-item">
+                <label class="layui-form-label required">用户名</label>
+                <div class="layui-input-inline">
+                    <input class="layui-input" type="text" name="username" placeholder="请输入用户名" required>
+                </div>
+            </div>
+            <div class="layui-form-item">
+                <label class="layui-form-label required">密码</label>
+                <div class="layui-input-inline">
+                    <input class="layui-input" type="text" name="password" placeholder="请输入密码" required>
+                </div>
+            </div>
+        </div>
+        <div class="layui-form-item" th:if="${repoAuth.getAuthType()} == 'ssh'">
+            <label class="layui-form-label required">RSA 私钥</label>
+            <div class="layui-input-inline">
+                <textarea class="layui-textarea" name="rsaPrikey" placeholder="请输入 RSA 私钥"></textarea>
+            </div>
+        </div>
+        <div class="layui-form-item timo-finally">
+            <button class="layui-btn ajax-submit"><i class="fa fa-check-circle"></i> 更新</button>
+            <button class="layui-btn btn-secondary close-popup"><i class="fa fa-times-circle"></i> 关闭</button>
+        </div>
+    </form>
+</div>
+
+<script th:replace="/common/template :: script"></script>
+<script type="text/javascript" th:src="@{/js/plugins/jquery-2.2.4.min.js}"></script>
+</body>
+</html>

+ 57 - 0
web/src/main/resources/templates/devops/app/config/docker/index.html

@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html xmlns:th="http://www.thymeleaf.org">
+<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
+
+<body class="timo-layout-page">
+<div class="layui-card">
+    <div class="layui-card-header timo-card-header">
+        <span><i class="fa fa-bars"></i> 仓库认证</span>
+        <i class="layui-icon layui-icon-refresh refresh-btn"></i>
+    </div>
+    <div class="layui-card-body">
+        <div class="layui-row timo-card-screen put-row">
+            <div class="pull-right screen-btn-group">
+                <div class="btn-group-right">
+                    <button class="layui-btn open-popup" data-title="添加仓库认证" th:attr="data-url=@{/app/config/build/repoauth/add}"
+                            data-size="640,480">
+                        <i class="fa fa-plus"></i> 添加
+                    </button>
+                </div>
+            </div>
+        </div>
+        <div class="timo-table-wrap">
+            <table class="layui-table timo-table">
+                <thead>
+                <tr>
+                    <th class="sortable" data-field="type">仓库类型</th>
+                    <th class="sortable" data-field="name">认证名字</th>
+                    <th class="sortable" data-field="authType">认证类型</th>
+                    <th>操作</th>
+                </tr>
+                </thead>
+                <tbody>
+                <tr th:each="item:${list}">
+                    <td th:text="${item.type}">仓库类型</td>
+                    <td th:text="${item.name}">认证名字</td>
+                    <td th:text="${item.authType}">认证类型</td>
+                    <td>
+                        <a class="open-popup" data-title="详细" th:attr="data-url=@{'/app/config/build/repoauth/detail/'+${item.id}}"
+                           data-size="640,480" href="#">详细</a>
+                        <a class="open-popup" data-title="编辑" th:attr="data-url=@{'/app/config/build/repoauth/edit/'+${item.id}}"
+                           data-size="640,480" href="#">编辑</a>
+                        <a class="ajax-delete" th:attr="data-msg='确定要删除 '+ ${item.name} + '?'"
+                           th:href="@{'/api/app/config/build/repoauth/' + ${item.id}}">删除</a>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </div>
+        <div th:replace="/common/fragment :: page"></div>
+    </div>
+</div>
+
+<script th:replace="/common/template :: script"></script>
+<script type="text/javascript">
+</script>
+</body>
+</html>