Search in sources :

Example 1 with NodeAgentWhitelist

use of io.jpom.model.node.NodeAgentWhitelist in project Jpom by dromara.

the class SystemConfigController method getWhitelist.

/**
 * 加载白名单配置
 *
 * @return json
 */
@RequestMapping(value = "get_whitelist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_NODE_WHITELIST, method = MethodFeature.LIST)
public String getWhitelist() {
    String workspaceId = nodeService.getCheckUserWorkspace(getRequest());
    NodeAgentWhitelist config = systemParametersServer.getConfigDefNewInstance(StrUtil.format("node_whitelist_{}", workspaceId), NodeAgentWhitelist.class);
    return JsonMessage.getString(200, "加载成功", config);
}
Also used : NodeAgentWhitelist(io.jpom.model.node.NodeAgentWhitelist) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with NodeAgentWhitelist

use of io.jpom.model.node.NodeAgentWhitelist in project Jpom by dromara.

the class SystemConfigController method saveWhitelist.

/**
 * 保存白名单配置
 *
 * @return json
 */
@RequestMapping(value = "save_whitelist", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.SYSTEM_NODE_WHITELIST, method = MethodFeature.EDIT)
public String saveWhitelist(@ValidatorItem(msg = "请选择分发的节点") String nodeIds, String project, String certificate, String nginx, String allowEditSuffix, String allowRemoteDownloadHost) {
    HttpServletRequest httpServletRequest = getRequest();
    String workspaceId = nodeService.getCheckUserWorkspace(httpServletRequest);
    NodeAgentWhitelist agentWhitelist = new NodeAgentWhitelist();
    agentWhitelist.setNodeIds(nodeIds);
    agentWhitelist.setProject(project);
    agentWhitelist.setCertificate(certificate);
    agentWhitelist.setNginx(nginx);
    agentWhitelist.setAllowEditSuffix(allowEditSuffix);
    agentWhitelist.setAllowRemoteDownloadHost(allowRemoteDownloadHost);
    String format = StrUtil.format("node_whitelist_{}", workspaceId);
    systemParametersServer.upsert(format, agentWhitelist, format);
    // 
    List<String> nodeIdsStr = StrUtil.splitTrim(nodeIds, StrUtil.LF);
    UserModel user = getUser();
    for (String s : nodeIdsStr) {
        NodeModel byKey = nodeService.getByKey(s, httpServletRequest);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(agentWhitelist);
        JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.WhitelistDirectory_Submit, user, jsonObject);
        Assert.state(request.getCode() == 200, "分发 " + byKey.getName() + " 节点配置失败" + request.getMsg());
    }
    return JsonMessage.getString(200, "保存成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) NodeAgentWhitelist(io.jpom.model.node.NodeAgentWhitelist) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NodeAgentWhitelist (io.jpom.model.node.NodeAgentWhitelist)2 ClassFeature (io.jpom.permission.ClassFeature)2 Feature (io.jpom.permission.Feature)2 MethodFeature (io.jpom.permission.MethodFeature)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JSONObject (com.alibaba.fastjson.JSONObject)1 NodeModel (io.jpom.model.data.NodeModel)1 UserModel (io.jpom.model.data.UserModel)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1