我需要使用我的 Java 代码获取存储在 aws 参数存储中的 api 令牌。我需要 api 令牌来验证 JiraClient。但我不确定检索价值的正确方法。这是我尝试过的。
import com.atlassian.jira.rest.client.api.IssueRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.domain.input.IssueInput;
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import software.amazon.awscdk.services.ssm.StringParameter;
import java.net.URI;
public class JiraClient {
private final String email;
private final String apiToken;
private final String jiraUrl;
private final JiraRestClient restClient;
public JiraClient(String email, String jiraUrl) {
this.email = email;
this.jiraUrl = jiraUrl;
this.apiToken = StringParameter.valueForSecureStringParameter(this, "/JIRA/Token", 1);
this.restClient = getJiraRestClient();
}
private JiraRestClient getJiraRestClient() {
return new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(getJiraUri(), this.email, this.apiToken);
}
public String createIssue(String projectKey, Long issueTypeId, String issueSummary) {
IssueRestClient issueClient = restClient.getIssueClient();
IssueInput newIssue = new IssueInputBuilder(projectKey, issueTypeId, issueSummary).build();
return issueClient.createIssue(newIssue).claim().getKey();
}
private URI getJiraUri() {
return URI.create(this.jiraUrl);
}
}
在该行this.apiToken = StringParameter.valueForSecureStringParameter(this, "/JIRA/Token", 1);
中,第一个参数应该是一个构造对象。