readLocalPluginSource reads the source code of a built-in plugin
(pluginName string)
| 2196 | }) |
| 2197 | } |
| 2198 | |
| 2199 | // Check if plugin exists in memory |
| 2200 | if p, exists := plugin.GetPlugin(id); exists { |
| 2201 | return c.JSON(http.StatusOK, map[string]interface{}{ |
| 2202 | "success": true, |
| 2203 | "plugin": id, |
| 2204 | "parameters": p.Parameters, |
| 2205 | "returnType": p.ReturnType, |
| 2206 | }) |
| 2207 | } |
| 2208 | |
| 2209 | // Check if plugin exists in temporary files |
| 2210 | if tempContent, exists := plugin.GetPluginNew(id); exists { |
| 2211 | parameters, returnType, err := plugin.Inspect("", tempContent, id) |
| 2212 | if err != nil { |
| 2213 | return c.JSON(http.StatusOK, map[string]interface{}{ |
| 2214 | "success": false, |
| 2215 | "error": fmt.Sprintf("Failed to parse temporary plugin: %v", err), |
| 2216 | }) |
| 2217 | } |
| 2218 | |
| 2219 | return c.JSON(http.StatusOK, map[string]interface{}{ |
| 2220 | "success": true, |
| 2221 | "plugin": id, |
| 2222 | "parameters": parameters, |
| 2223 | "returnType": returnType, |
| 2224 | }) |
| 2225 | } |
| 2226 | |
| 2227 | return c.JSON(http.StatusNotFound, map[string]interface{}{ |
| 2228 | "success": false, |
| 2229 | "error": "Plugin not found: " + id, |
| 2230 | }) |
| 2231 | } |
| 2232 | |
| 2233 | // readLocalPluginSource reads the source code of a built-in plugin |
| 2234 | func readLocalPluginSource(pluginName string) (string, error) { |
| 2235 | // Get current working directory |
| 2236 | wd, err := os.Getwd() |
| 2237 | if err != nil { |
| 2238 | logger.Error("Failed to get working directory", "error", err) |
| 2239 | wd = "." |
| 2240 | } |
| 2241 | |
| 2242 | // Map plugin names to their source file paths |
| 2243 | var sourcePath string |
| 2244 | switch pluginName { |
| 2245 | case "isLocalIP": |
| 2246 | // Try multiple possible paths |
| 2247 | possiblePaths := []string{ |
| 2248 | filepath.Join(wd, "local_plugin", "is_local_ip", "is_local_ip.go"), |
| 2249 | filepath.Join(wd, "src", "local_plugin", "is_local_ip", "is_local_ip.go"), |
| 2250 | "local_plugin/is_local_ip/is_local_ip.go", |
| 2251 | "src/local_plugin/is_local_ip/is_local_ip.go", |
| 2252 | } |
| 2253 | |
| 2254 | for _, path := range possiblePaths { |
| 2255 | if _, err := os.Stat(path); err == nil { |
no test coverage detected