英文:
Get value from AWS Parameter store in Java
问题
以下是已翻译的内容:
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);
这一行中,第一个参数应为 Construct 对象。
英文:
I need to fetch an api token which is stored in the aws parameter store using my Java code. I need the api token to authenticate a JiraClient. But I am not sure of the correct way of retrieving the value. Here is what I have tried.
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);
}
}
In the line this.apiToken = StringParameter.valueForSecureStringParameter(this, "/JIRA/Token", 1);
the first parameter should be a Construct Object.
答案1
得分: 1
你正在使用来自aws-cdk的StringParameter.valueForSecureStringParameter方法,它是AWS的“基础设施即代码”服务。
你应该使用AWS Java SDK中AWSSimpleSystemsManagement接口中定义的getParameter()方法。
英文:
You are using the StringParameter.valueForSecureStringParameter method from aws-cdk which is an "Infrastructure as Code" service from AWS.
You should be using the getParameter() method defined in the AWSSimpleSystemsManagement interface in the AWS Java SDK.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论