Rundeck Java通知插件STORAGE_PATH_AUTOMATIC_READ功能失效求助
解决Rundeck Java通知插件STORAGE_PATH_AUTOMATIC_READ不生效问题
问题原因
Rundeck的STORAGE_PATH_AUTOMATIC_READ渲染选项在Notification插件中不会自动触发值转换,该逻辑仅默认适配Workflow步骤类插件,需要手动实现属性解析逻辑来读取密钥存储内容。
解决方案
实现PluginPropertyResolver接口,通过Rundeck的StorageService手动读取密钥存储中的实际值,替换属性中的路径字符串。
修改后的代码示例
import org.rundeck.storage.api.StorageService; import org.rundeck.core.plugins.Plugin; import org.rundeck.core.plugins.PluginProperty; import org.rundeck.core.plugins.configuration.RenderingOption; import org.rundeck.core.plugins.configuration.StringRenderingConstants; import org.rundeck.plugins.notification.NotificationPlugin; import org.rundeck.core.plugins.configuration.DynamicProperties; import org.rundeck.core.plugins.configuration.PluginPropertyResolver; import org.rundeck.app.spi.Services; import org.rundeck.core.execution.ExecutionContext; import javax.inject.Inject; import java.util.Map; import java.util.Properties; @Plugin(service = "Notification", name = "smSlackNotificationPlugin") @PluginDescription(title = "SM Slack Notification", description = "SM custom Slack Notification Plugin") public class SMSlackNotificationPlugin implements NotificationPlugin, DynamicProperties, PluginPropertyResolver { private final StorageService storageService; @Inject public SMSlackNotificationPlugin(Services services) { this.storageService = services.getStorageService(); } @PluginProperty(name = "example", title = "Example String", description = "Example description") private String example; @PluginProperty(name = "botkey", title = "Bot Key", description = "Bot key test", required = true) @RenderingOptions({ @RenderingOption( key = StringRenderingConstants.SELECTION_ACCESSOR_KEY, value = "STORAGE_PATH" ), @RenderingOption( key = StringRenderingConstants.STORAGE_PATH_ROOT_KEY, value = "keys/AWS" ), @RenderingOption( key = StringRenderingConstants.VALUE_CONVERSION_KEY, value = "STORAGE_PATH_AUTOMATIC_READ" ) }) private String botkey; @Override public void resolveProperties(ExecutionContext context, Properties properties) { String botKeyPath = properties.getProperty("botkey"); // 验证路径格式,确保是密钥存储路径 if (botKeyPath != null && botKeyPath.startsWith("keys/")) { try { // 读取密钥存储中的实际内容 String actualBotKey = storageService.getResourceAsString(botKeyPath); // 更新属性值和类成员变量 properties.setProperty("botkey", actualBotKey); this.botkey = actualBotKey; } catch (Exception e) { throw new RuntimeException("读取Bot密钥失败: " + e.getMessage(), e); } } } @Override public boolean notify(String trigger, ExecutionContext context, Map<String, Object> executionData) { // 此处botkey已替换为实际密钥内容 System.out.println("Bot Key: " + botkey); // 编写你的Slack通知逻辑 return true; } }
额外检查点
- 确认密钥存储路径
keys/AWS存在且有对应密钥数据。 - 检查Rundeck ACL策略,确保运行插件的账号拥有该存储路径的读取权限。
- 核对Rundeck版本,确保
StorageService和PluginPropertyResolver接口可用(建议使用3.0+版本)。
内容的提问来源于stack exchange,提问作者Russell917
相关产品推荐
相关产品推荐

