Search in sources :

Example 16 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class NodeProjectInfoController method clearAll.

/**
 * 删除节点缓存的所有项目
 *
 * @return json
 */
@GetMapping(value = "clear_all_project", produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission(superUser = true)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String clearAll() {
    Entity where = Entity.create();
    where.set("id", " <> id");
    int del = projectInfoCacheService.del(where);
    return JsonMessage.getString(200, "成功删除" + del + "条项目缓存");
}
Also used : Entity(cn.hutool.db.Entity) SystemPermission(io.jpom.permission.SystemPermission) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 17 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class NodeProjectInfoController method syncProject.

/**
 * 同步节点项目
 *
 * @return json
 */
@GetMapping(value = "sync_project", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String syncProject(String nodeId) {
    NodeModel nodeModel = nodeService.getByKey(nodeId);
    Assert.notNull(nodeModel, "对应的节点不存在");
    int count = projectInfoCacheService.delCache(nodeId, getRequest());
    String msg = projectInfoCacheService.syncExecuteNode(nodeModel);
    return JsonMessage.getString(200, "主动清除:" + count + StrUtil.SPACE + msg);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) GetMapping(org.springframework.web.bind.annotation.GetMapping) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature)

Example 18 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class EditProjectController method saveProject.

/**
 * 保存项目
 *
 * @param id id
 * @return json
 */
@RequestMapping(value = "saveProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String saveProject(String id) {
    // 防止和Jpom冲突
    if (StrUtil.isNotEmpty(ConfigBean.getInstance().applicationTag) && ConfigBean.getInstance().applicationTag.equalsIgnoreCase(id)) {
        return JsonMessage.getString(401, "当前项目id已经被Jpom占用");
    }
    NodeModel node = getNode();
    JsonMessage<Object> request = NodeForward.request(node, getRequest(), NodeUrl.Manage_SaveProject);
    if (request.getCode() == HttpStatus.OK.value()) {
        projectInfoCacheService.syncNode(node, id);
    }
    return request.toString();
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class ProjectManageControl method deleteProject.

/**
 * 删除项目
 *
 * @param id id
 * @return json
 */
@PostMapping(value = "deleteProject", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteProject(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, String copyId) {
    NodeModel nodeModel = getNode();
    HttpServletRequest servletRequest = getRequest();
    if (StrUtil.isEmpty(copyId)) {
        // 检查节点分发
        List<OutGivingModel> outGivingModels = outGivingServer.listByWorkspace(servletRequest);
        if (outGivingModels != null) {
            boolean match = outGivingModels.stream().anyMatch(outGivingModel -> outGivingModel.checkContains(nodeModel.getId(), id));
            Assert.state(!match, "当前项目存在节点分发,不能直接删除");
        // for (OutGivingModel outGivingModel : outGivingModels) {
        // if (outGivingModel.checkContains(nodeModel.getId(), id)) {
        // return JsonMessage.getString(405, "当前项目存在节点分发,不能直接删除");
        // }
        // }
        }
        // 
        List<MonitorModel> monitorModels = monitorService.listByWorkspace(servletRequest);
        if (monitorModels != null) {
            boolean match = monitorModels.stream().anyMatch(monitorModel -> monitorModel.checkNodeProject(nodeModel.getId(), id));
            // if (monitorService.checkProject(nodeModel.getId(), id)) {
            // return JsonMessage.getString(405, );
            // }
            Assert.state(!match, "当前项目存在监控项,不能直接删除");
        }
        boolean releaseMethod = buildService.checkReleaseMethod(nodeModel.getId() + StrUtil.COLON + id, servletRequest, BuildReleaseMethod.Project);
        Assert.state(!releaseMethod, "当前项目存在构建项,不能直接删除");
    }
    JsonMessage<Object> request = NodeForward.request(nodeModel, servletRequest, NodeUrl.Manage_DeleteProject);
    if (request.getCode() == HttpStatus.OK.value()) {
        // 
        projectInfoCacheService.syncNode(nodeModel);
    }
    return request.toString();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeModel(io.jpom.model.data.NodeModel) MonitorModel(io.jpom.model.data.MonitorModel) OutGivingModel(io.jpom.model.data.OutGivingModel) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 20 with Feature

use of io.jpom.permission.Feature in project Jpom by dromara.

the class DockerSwarmServiceController method pullImage.

/**
 * @return json
 */
@GetMapping(value = "start-log", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String pullImage(@ValidatorItem String id, @ValidatorItem String type, @ValidatorItem String dataId) throws Exception {
    IPlugin plugin = PluginFactory.getPlugin(DockerSwarmInfoService.DOCKER_PLUGIN_NAME);
    Map<String, Object> parameter = dockerInfoService.getBySwarmPluginMap(id, getRequest());
    parameter.put(StrUtil.equalsIgnoreCase(type, "service") ? "serviceId" : "taskId", dataId);
    // 
    String uuid = IdUtil.fastSimpleUUID();
    File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), "docker-swarm-log", uuid + ".log");
    LogRecorder logRecorder = LogRecorder.builder().file(file).build();
    logRecorder.info("start pull {}", dataId);
    Consumer<String> logConsumer = logRecorder::append;
    parameter.put("charset", CharsetUtil.CHARSET_UTF_8);
    parameter.put("consumer", logConsumer);
    parameter.put("tail", 50);
    ThreadUtil.execute(() -> {
        try {
            plugin.execute(StrUtil.equalsIgnoreCase(type, "service") ? "logService" : "logTask", parameter);
        } catch (Exception e) {
            logRecorder.error("拉取异常", e);
        }
        logRecorder.info("pull end");
    });
    return JsonMessage.getString(200, "开始拉取", uuid);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) LogRecorder(io.jpom.util.LogRecorder) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

Feature (io.jpom.permission.Feature)129 MethodFeature (io.jpom.permission.MethodFeature)129 ClassFeature (io.jpom.permission.ClassFeature)128 JSONObject (com.alibaba.fastjson.JSONObject)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 File (java.io.File)36 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 DockerInfoModel (io.jpom.model.docker.DockerInfoModel)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)22 NodeModel (io.jpom.model.data.NodeModel)21 GetMapping (org.springframework.web.bind.annotation.GetMapping)21 UserModel (io.jpom.model.data.UserModel)14 SystemPermission (io.jpom.permission.SystemPermission)14 BuildInfoModel (io.jpom.model.data.BuildInfoModel)12 SshModel (io.jpom.model.data.SshModel)10 Entity (cn.hutool.db.Entity)8 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)8 JSONArray (com.alibaba.fastjson.JSONArray)8 JsonMessage (cn.jiangzeyin.common.JsonMessage)7 List (java.util.List)7