bitbucket - 配置 bitbucket 插件以避免对安全变量进行硬编码
问题描述
我开发了一个 Atlasian Bitbucket 插件,它可以全局监听推送/PR,并使用 REST API 将存储库详细信息发送到数据库。
我需要进行配置REST API URL
,credential
以便我的插件可以进行 API 调用。目前我有hardcoded
REST API URL
并且credential
在我的插件属性文件中。我不喜欢,因为每次如果我需要创建一个包来针对我的测试环境或生产环境,我都必须进行更改。另外,我不喜欢在源代码中保留凭据。
在 bitbucket 插件中添加配置屏幕的最佳方法是什么?我想要 URL、用户名和密码的表单(一旦我安装了插件)并且只更新一次 Bitbucket 中的存储。如果我需要重新启动我的 bitbucket,我不想丢失保存的数据。
我试图搜索如何配置 bitbucket 插件,但是找不到简单的方法。我确实看到了多种方法,例如添加“配置”按钮,该按钮将打开一个 serverlet 以获取用户输入。对我来说似乎很神秘。另外,我看到很多关于模板的建议,例如速度、大豆等,这让我很困惑。
由于我是插件开发的新手,因此无法探索。寻求帮助。
解决方案
简单配置文件的一种可能性是从 Bitbucket 主目录读取 somefile.properties,这样配置文件将在应用程序更新后继续存在。
- 创建
somefile.properties
于BITBUCKET_HOME
server.username=YOUR_USERNAME
server.password=YOUR_PASSWORD
- 像这样读取插件类中的属性
// imports
import com.atlassian.bitbucket.server.StorageService;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
private final StorageService storageService;
// StorageService injected via constructor injection
public SomePlugin(@ComponentImport final StorageService storageService) {
this.storageService = storageService;
}
Properties p = new Properties();
File file = new File(storageService.getHomeDir().toString(), "somefile.properties");
FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(file);
p.load(fileInputStream);
String username = p.getProperty("server.username");
String password = p.getProperty("server.password");
} catch (IOException e) {
//handle exception
}
推荐阅读
- mysql - 为 1 列获取 1 个值
- angular5 - 在 Angular 5 中自定义 routerLink
- wpf - WPF列表框排序不起作用
- android - 在 google play store 上更新应用程序时,我的共享首选项正在删除
- git - 如何使用 rebase 正确反映从分支到另一个分支的更改
- java - 如何在java中的txt文件中写入特定数量的字符
- java - 使用 java priorityQueue 删除方法
- android - Android AWS sdk 无法上传
- python - 导入时模拟模块全局变量
- crystal-reports - 在水晶报表中的行中复制时如何抑制字段值或将字段值设置为空