|
22 | 22 | import com.alibaba.nacos.api.model.v2.Result; |
23 | 23 | import com.alibaba.nacos.api.plugin.PluginType; |
24 | 24 | import com.alibaba.nacos.auth.annotation.Secured; |
| 25 | +import com.alibaba.nacos.common.utils.JacksonUtils; |
25 | 26 | import com.alibaba.nacos.common.utils.StringUtils; |
26 | 27 | import com.alibaba.nacos.core.plugin.PluginManager; |
27 | 28 | import com.alibaba.nacos.core.plugin.model.PluginInfo; |
28 | 29 | import com.alibaba.nacos.core.plugin.model.vo.PluginDetailVO; |
29 | 30 | import com.alibaba.nacos.core.plugin.model.vo.PluginInfoVO; |
30 | | -import com.alibaba.nacos.core.plugin.model.form.PluginStatusForm; |
31 | | -import com.alibaba.nacos.core.plugin.model.form.PluginConfigForm; |
32 | 31 | import com.alibaba.nacos.core.utils.Commons; |
33 | 32 | import com.alibaba.nacos.plugin.auth.constant.ActionTypes; |
34 | 33 | import com.alibaba.nacos.plugin.auth.constant.ApiType; |
35 | 34 | import com.alibaba.nacos.plugin.auth.constant.SignType; |
| 35 | +import com.fasterxml.jackson.core.type.TypeReference; |
36 | 36 | import org.springframework.http.HttpStatus; |
37 | 37 | import org.springframework.web.bind.annotation.GetMapping; |
38 | 38 | import org.springframework.web.bind.annotation.PutMapping; |
39 | | -import org.springframework.web.bind.annotation.RequestBody; |
40 | 39 | import org.springframework.web.bind.annotation.RequestMapping; |
41 | 40 | import org.springframework.web.bind.annotation.RequestParam; |
42 | 41 | import org.springframework.web.bind.annotation.RestController; |
43 | 42 |
|
44 | 43 | import java.util.List; |
| 44 | +import java.util.Map; |
45 | 45 |
|
46 | 46 | import static com.alibaba.nacos.core.utils.Commons.NACOS_ADMIN_CORE_CONTEXT_V3; |
47 | 47 |
|
@@ -112,36 +112,51 @@ public Result<PluginDetailVO> getPluginDetail( |
112 | 112 | /** |
113 | 113 | * Enable or disable plugin. |
114 | 114 | * |
115 | | - * @param form plugin status form |
| 115 | + * @param pluginType plugin type |
| 116 | + * @param pluginName plugin name |
| 117 | + * @param enabled enable or disable |
| 118 | + * @param localOnly whether only apply to local node |
116 | 119 | * @return success result |
117 | 120 | */ |
118 | 121 | @PutMapping("/status") |
119 | 122 | @Secured(resource = Commons.NACOS_ADMIN_CORE_CONTEXT_V3 |
120 | 123 | + "/plugin", action = ActionTypes.WRITE, signType = SignType.CONSOLE, apiType = ApiType.ADMIN_API) |
121 | | - public Result<String> updatePluginStatus(@RequestBody PluginStatusForm form) throws NacosApiException { |
122 | | - validatePluginIdentifier(form.getPluginType(), form.getPluginName()); |
123 | | - String pluginId = form.getPluginType() + ":" + form.getPluginName(); |
124 | | - unifiedPluginManager.setPluginEnabled(pluginId, form.isEnabled(), form.isLocalOnly()); |
| 124 | + public Result<String> updatePluginStatus( |
| 125 | + @RequestParam("pluginType") String pluginType, |
| 126 | + @RequestParam("pluginName") String pluginName, |
| 127 | + @RequestParam("enabled") boolean enabled, |
| 128 | + @RequestParam(value = "localOnly", defaultValue = "false") boolean localOnly) throws NacosApiException { |
| 129 | + validatePluginIdentifier(pluginType, pluginName); |
| 130 | + String pluginId = pluginType + ":" + pluginName; |
| 131 | + unifiedPluginManager.setPluginEnabled(pluginId, enabled, localOnly); |
125 | 132 | return Result.success("Plugin status updated successfully"); |
126 | 133 | } |
127 | 134 |
|
128 | 135 | /** |
129 | 136 | * Update plugin configuration. |
130 | 137 | * |
131 | | - * @param form plugin config form |
| 138 | + * @param pluginType plugin type |
| 139 | + * @param pluginName plugin name |
| 140 | + * @param configJson plugin configuration as JSON string |
| 141 | + * @param localOnly whether only apply to local node |
132 | 142 | * @return success result |
133 | 143 | */ |
134 | 144 | @PutMapping("/config") |
135 | 145 | @Secured(resource = Commons.NACOS_ADMIN_CORE_CONTEXT_V3 |
136 | 146 | + "/plugin", action = ActionTypes.WRITE, signType = SignType.CONSOLE, apiType = ApiType.ADMIN_API) |
137 | | - public Result<String> updatePluginConfig(@RequestBody PluginConfigForm form) throws NacosApiException { |
138 | | - validatePluginIdentifier(form.getPluginType(), form.getPluginName()); |
139 | | - if (form.getConfig() == null) { |
| 147 | + public Result<String> updatePluginConfig( |
| 148 | + @RequestParam("pluginType") String pluginType, |
| 149 | + @RequestParam("pluginName") String pluginName, |
| 150 | + @RequestParam("config") String configJson, |
| 151 | + @RequestParam(value = "localOnly", defaultValue = "false") boolean localOnly) throws NacosApiException { |
| 152 | + validatePluginIdentifier(pluginType, pluginName); |
| 153 | + Map<String, String> config = JacksonUtils.toObj(configJson, new TypeReference<Map<String, String>>() { }); |
| 154 | + if (config == null) { |
140 | 155 | throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.PARAMETER_VALIDATE_ERROR, |
141 | 156 | "Plugin configuration is required"); |
142 | 157 | } |
143 | | - String pluginId = form.getPluginType() + ":" + form.getPluginName(); |
144 | | - unifiedPluginManager.updatePluginConfig(pluginId, form.getConfig(), form.isLocalOnly()); |
| 158 | + String pluginId = pluginType + ":" + pluginName; |
| 159 | + unifiedPluginManager.updatePluginConfig(pluginId, config, localOnly); |
145 | 160 | return Result.success("Plugin configuration updated successfully"); |
146 | 161 | } |
147 | 162 |
|
|
0 commit comments