From bad172c3f10b277ea888e8dc910f8baf961baf8b Mon Sep 17 00:00:00 2001 From: Maxwell Brown <55033421+Galactus22625@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:38:23 -0800 Subject: [PATCH] Jira Source Configuration and Filter Changes and add license headers (#5306) * jira yaml changes and tests, authentication and hosts Signed-off-by: Maxwell Brown * filter config file changes Signed-off-by: Maxwell Brown * jira filter config changes and implementation Signed-off-by: Maxwell Brown * filter change test corrections Signed-off-by: Maxwell Brown * project name -> key for now Signed-off-by: Maxwell Brown * removed unfishished function Signed-off-by: Maxwell Brown * address pr comments Signed-off-by: Maxwell Brown * Add license headers to all jira source files Signed-off-by: Maxwell Brown --------- Signed-off-by: Maxwell Brown --- .../plugins/source/jira/JiraClient.java | 10 ++ .../plugins/source/jira/JiraItemInfo.java | 10 ++ .../plugins/source/jira/JiraIterator.java | 10 ++ .../plugins/source/jira/JiraService.java | 68 +++++++++-- .../plugins/source/jira/JiraSource.java | 10 ++ .../plugins/source/jira/JiraSourceConfig.java | 101 ++++------------ .../configuration/AuthenticationConfig.java | 45 +++++++ .../jira/configuration/BasicConfig.java | 29 +++++ .../jira/configuration/FilterConfig.java | 26 ++++ .../jira/configuration/IssueTypeConfig.java | 29 +++++ .../source/jira/configuration/NameConfig.java | 30 +++++ .../jira/configuration/Oauth2Config.java | 35 ++++++ .../jira/configuration/ProjectConfig.java | 20 +++ .../jira/configuration/StatusConfig.java | 29 +++++ .../jira/exception/BadRequestException.java | 10 ++ .../jira/exception/UnAuthorizedException.java | 10 ++ .../plugins/source/jira/models/IssueBean.java | 10 ++ .../source/jira/models/SearchResults.java | 11 ++ .../jira/rest/BasicAuthInterceptor.java | 14 ++- .../jira/rest/CustomRestTemplateConfig.java | 10 ++ .../source/jira/rest/JiraRestClient.java | 15 +++ .../jira/rest/OAuth2RequestInterceptor.java | 10 ++ .../source/jira/rest/auth/JiraAuthConfig.java | 10 ++ .../jira/rest/auth/JiraAuthFactory.java | 10 ++ .../jira/rest/auth/JiraBasicAuthConfig.java | 10 ++ .../jira/rest/auth/JiraOauthConfig.java | 18 ++- .../source/jira/utils/AddressValidation.java | 10 ++ .../plugins/source/jira/utils/Constants.java | 10 ++ .../source/jira/utils/JiraConfigHelper.java | 66 ++++++++-- .../source/jira/utils/JiraContentType.java | 10 ++ .../source/jira/utils/JqlConstants.java | 13 ++ .../plugins/source/jira/JiraClientTest.java | 10 ++ .../source/jira/JiraConfigHelperTest.java | 104 +++++++++++++--- .../plugins/source/jira/JiraItemInfoTest.java | 10 ++ .../plugins/source/jira/JiraIteratorTest.java | 10 ++ .../plugins/source/jira/JiraServiceTest.java | 54 +++++++-- .../source/jira/JiraSourceConfigTest.java | 114 ++++++++++-------- .../plugins/source/jira/JiraSourceTest.java | 31 ++++- .../exception/BadRequestExceptionTest.java | 10 ++ .../exception/UnAuthorizedExceptionTest.java | 10 ++ .../source/jira/models/IssueBeanTest.java | 10 ++ .../source/jira/models/SearchResultsTest.java | 10 ++ .../jira/rest/BasicAuthInterceptorTest.java | 24 +++- .../rest/CustomRestTemplateConfigTest.java | 33 +++++ .../source/jira/rest/JiraRestClientTest.java | 10 ++ .../rest/OAuth2RequestInterceptorTest.java | 10 ++ .../jira/rest/auth/JiraAuthFactoryTest.java | 20 +++ .../rest/auth/JiraBasicAuthConfigTest.java | 10 ++ .../jira/rest/auth/JiraOauthConfigTest.java | 19 ++- .../jira/utils/AddressValidationTest.java | 10 ++ .../jira/utils/JiraContentTypeTest.java | 10 ++ .../resources/basic-auth-jira-pipeline.yaml | 10 +- .../resources/oauth2-auth-jira-pipeline.yaml | 15 ++- 53 files changed, 1042 insertions(+), 201 deletions(-) create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/AuthenticationConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/BasicConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/FilterConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/IssueTypeConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/NameConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/Oauth2Config.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/ProjectConfig.java create mode 100644 data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/StatusConfig.java diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraClient.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraClient.java index 7e463f4534..3c809fa798 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraClient.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraClient.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfo.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfo.java index 0952f20a2a..349ab7bccb 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfo.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfo.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import lombok.Getter; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraIterator.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraIterator.java index 3027b9ec99..5ae040cc7f 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraIterator.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraIterator.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraService.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraService.java index 38eb9eed40..4600d1bdeb 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraService.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraService.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import io.micrometer.core.instrument.Counter; @@ -14,8 +24,10 @@ import javax.inject.Named; import java.time.Instant; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Queue; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -25,9 +37,12 @@ import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.DELIMITER; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.GREATER_THAN_EQUALS; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.ISSUE_TYPE_IN; +import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.ISSUE_TYPE_NOT_IN; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.PREFIX; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.PROJECT_IN; +import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.PROJECT_NOT_IN; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.STATUS_IN; +import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.STATUS_NOT_IN; import static org.opensearch.dataprepper.plugins.source.jira.utils.JqlConstants.SUFFIX; @@ -117,26 +132,41 @@ private void addItemsToQueue(List issueList, Queue itemInfo private StringBuilder createIssueFilterCriteria(JiraSourceConfig configuration, Instant ts) { log.info("Creating issue filter criteria"); - if (!CollectionUtils.isEmpty(JiraConfigHelper.getProjectKeyFilter(configuration))) { + if (!CollectionUtils.isEmpty(JiraConfigHelper.getProjectNameIncludeFilter(configuration)) || !CollectionUtils.isEmpty(JiraConfigHelper.getProjectNameExcludeFilter(configuration)) ) { validateProjectFilters(configuration); } StringBuilder jiraQl = new StringBuilder(UPDATED + GREATER_THAN_EQUALS + ts.toEpochMilli()); - if (!CollectionUtils.isEmpty(JiraConfigHelper.getProjectKeyFilter(configuration))) { - jiraQl.append(PROJECT_IN).append(JiraConfigHelper.getProjectKeyFilter(configuration).stream() + if (!CollectionUtils.isEmpty(JiraConfigHelper.getProjectNameIncludeFilter(configuration))) { + jiraQl.append(PROJECT_IN).append(JiraConfigHelper.getProjectNameIncludeFilter(configuration).stream() + .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) + .append(CLOSING_ROUND_BRACKET); + } + if (!CollectionUtils.isEmpty(JiraConfigHelper.getProjectNameExcludeFilter(configuration))) { + jiraQl.append(PROJECT_NOT_IN).append(JiraConfigHelper.getProjectNameExcludeFilter(configuration).stream() + .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) + .append(CLOSING_ROUND_BRACKET); + } + if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueTypeIncludeFilter(configuration))) { + jiraQl.append(ISSUE_TYPE_IN).append(JiraConfigHelper.getIssueTypeIncludeFilter(configuration).stream() + .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) + .append(CLOSING_ROUND_BRACKET); + } + if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueTypeExcludeFilter(configuration))) { + jiraQl.append(ISSUE_TYPE_NOT_IN).append(JiraConfigHelper.getIssueTypeExcludeFilter(configuration).stream() .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) .append(CLOSING_ROUND_BRACKET); } - if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueTypeFilter(configuration))) { - jiraQl.append(ISSUE_TYPE_IN).append(JiraConfigHelper.getIssueTypeFilter(configuration).stream() + if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueStatusIncludeFilter(configuration))) { + jiraQl.append(STATUS_IN).append(JiraConfigHelper.getIssueStatusIncludeFilter(configuration).stream() .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) .append(CLOSING_ROUND_BRACKET); } - if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueStatusFilter(configuration))) { - jiraQl.append(STATUS_IN).append(JiraConfigHelper.getIssueStatusFilter(configuration).stream() + if (!CollectionUtils.isEmpty(JiraConfigHelper.getIssueStatusExcludeFilter(configuration))) { + jiraQl.append(STATUS_NOT_IN).append(JiraConfigHelper.getIssueStatusExcludeFilter(configuration).stream() .collect(Collectors.joining(DELIMITER, PREFIX, SUFFIX))) .append(CLOSING_ROUND_BRACKET); } - log.trace("Created issue filter criteria JiraQl query: {}", jiraQl); + log.error("Created issue filter criteria JiraQl query: {}", jiraQl); return jiraQl; } @@ -148,9 +178,21 @@ private StringBuilder createIssueFilterCriteria(JiraSourceConfig configuration, private void validateProjectFilters(JiraSourceConfig configuration) { log.trace("Validating project filters"); List badFilters = new ArrayList<>(); + Set includedProjects = new HashSet<>(); + List includedAndExcludedProjects = new ArrayList<>(); Pattern regex = Pattern.compile("[^A-Z0-9]"); - JiraConfigHelper.getProjectKeyFilter(configuration).forEach(projectFilter -> { + JiraConfigHelper.getProjectNameIncludeFilter(configuration).forEach(projectFilter -> { Matcher matcher = regex.matcher(projectFilter); + includedProjects.add(projectFilter); + if (matcher.find() || projectFilter.length() <= 1 || projectFilter.length() > 10) { + badFilters.add(projectFilter); + } + }); + JiraConfigHelper.getProjectNameExcludeFilter(configuration).forEach(projectFilter -> { + Matcher matcher = regex.matcher(projectFilter); + if (includedProjects.contains(projectFilter)) { + includedAndExcludedProjects.add(projectFilter); + } if (matcher.find() || projectFilter.length() <= 1 || projectFilter.length() > 10) { badFilters.add(projectFilter); } @@ -162,6 +204,14 @@ private void validateProjectFilters(JiraSourceConfig configuration) { "Invalid project key found in filter configuration for " + filters); } + if (!includedAndExcludedProjects.isEmpty()) { + String filters = String.join("\"" + includedAndExcludedProjects + "\"", ", "); + log.error("One or more project keys found in both include and exclude: {}", includedAndExcludedProjects); + throw new BadRequestException("Bad request exception occurred " + + "Project filters is invalid because the following projects are listed in both include and exclude" + + filters); + } + } } \ No newline at end of file diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSource.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSource.java index 2641ab60ad..2ffc7b3b53 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSource.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSource.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfig.java index f37434cf9d..df5cd70f0b 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfig.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfig.java @@ -1,16 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import com.fasterxml.jackson.annotation.JsonProperty; -import jakarta.validation.constraints.Size; +import jakarta.validation.Valid; import lombok.Getter; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.FilterConfig; import org.opensearch.dataprepper.plugins.source.source_crawler.base.CrawlerSourceConfig; import java.time.Duration; -import java.util.ArrayList; import java.util.List; -import java.util.Map; - -import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.OAUTH2; @Getter public class JiraSourceConfig implements CrawlerSourceConfig { @@ -20,50 +28,23 @@ public class JiraSourceConfig implements CrawlerSourceConfig { /** * Jira account url */ - @JsonProperty("account_url") - private String accountUrl; + @JsonProperty("hosts") + private List hosts; /** - * A map of connector credentials specific to this source + * Authentication Config to Access Jira */ - @JsonProperty("connector_credentials") - private Map connectorCredentials; + @JsonProperty("authentication") + @Valid + private AuthenticationConfig authenticationConfig; - /** - * List of projects to ingest - */ - @JsonProperty("projects") - @Size(max = 1000, message = "Project type filter should not be more than 1000") - private List project = new ArrayList<>(); /** - * List of specific issue types to ingest. - * Ex: Story, Epic, Task etc + * Filter Config to filter what tickets get ingested */ - @JsonProperty("issue_types") - @Size(max = 1000, message = "Issue type filter should be less than 1000") - private List issueType = new ArrayList<>(); + @JsonProperty("filter") + private FilterConfig filterConfig; - /** - * Optional Inclusion patterns for filtering some tickets - */ - @JsonProperty("inclusion_patterns") - @Size(max = 100, message = "inclusion pattern filters should not be more than 1000") - private List inclusionPatterns; - - /** - * Optional Exclusion patterns for excluding some tickets - */ - @JsonProperty("exclusion_patterns") - @Size(max = 1000, message = "exclusion pattern filter should be less than 1000") - private List exclusionPatterns; - - /** - * Optional Status filter to ingest the tickets - */ - @JsonProperty("statuses") - @Size(max = 1000, message = "Status filter should be less than 1000") - private List status = new ArrayList<>(); /** * Number of worker threads to spawn to parallel source fetching @@ -78,43 +59,11 @@ public class JiraSourceConfig implements CrawlerSourceConfig { @JsonProperty("backoff_time") private Duration backOff = DEFAULT_BACKOFF_MILLIS; - public String getJiraId() { - return this.getConnectorCredentials().get("jira_id"); - } - - public String getJiraCredential() { - return this.getConnectorCredentials().get("jira_credential"); + public String getAccountUrl() { + return this.getHosts().get(0); } public String getAuthType() { - return this.getConnectorCredentials().get("auth_type"); - } - - public String getAccessToken() { - return fetchGivenOAuthAttribute("access_token"); - } - - public String getRefreshToken() { - return fetchGivenOAuthAttribute("refresh_token"); - } - - public String getClientId() { - return fetchGivenOAuthAttribute("client_id"); - } - - public String getClientSecret() { - return fetchGivenOAuthAttribute("client_secret"); + return this.getAuthenticationConfig().getAuthType(); } - - private String fetchGivenOAuthAttribute(String givenAttribute) { - if (!OAUTH2.equals(getAuthType())) { - throw new RuntimeException("Authentication Type is not OAuth2."); - } - String attributeValue = this.getConnectorCredentials().get(givenAttribute); - if (attributeValue == null || attributeValue.isEmpty()) { - throw new RuntimeException(String.format("%s is required for OAuth2 AuthType", givenAttribute)); - } - return attributeValue; - } - } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/AuthenticationConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/AuthenticationConfig.java new file mode 100644 index 0000000000..25cfd4185a --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/AuthenticationConfig.java @@ -0,0 +1,45 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.Valid; +import jakarta.validation.constraints.AssertTrue; +import lombok.Getter; + +import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.BASIC; +import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.OAUTH2; + +@Getter +public class AuthenticationConfig { + @JsonProperty("basic") + @Valid + private BasicConfig basicConfig; + + @JsonProperty("oauth2") + @Valid + private Oauth2Config oauth2Config; + + @AssertTrue(message = "Authentication config should have either basic or oauth2") + private boolean isValidAuthenticationConfig() { + boolean hasBasic = basicConfig != null; + boolean hasOauth = oauth2Config != null; + return hasBasic ^ hasOauth; + } + + public String getAuthType() { + if (basicConfig != null) { + return BASIC; + } else { + return OAUTH2; + } + } +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/BasicConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/BasicConfig.java new file mode 100644 index 0000000000..b3a261f13a --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/BasicConfig.java @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.AssertTrue; +import lombok.Getter; + +@Getter +public class BasicConfig { + @JsonProperty("username") + private String username; + + @JsonProperty("password") + private String password; + + @AssertTrue(message = "Username and Password are both required for Basic Auth") + private boolean isBasicConfigValid() { + return username != null && password != null; + } +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/FilterConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/FilterConfig.java new file mode 100644 index 0000000000..987fa545e7 --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/FilterConfig.java @@ -0,0 +1,26 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +@Getter +public class FilterConfig { + @JsonProperty("project") + private ProjectConfig projectConfig; + + @JsonProperty("status") + private StatusConfig statusConfig; + + @JsonProperty("issue_type") + private IssueTypeConfig issueTypeConfig; +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/IssueTypeConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/IssueTypeConfig.java new file mode 100644 index 0000000000..977d9a3a9e --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/IssueTypeConfig.java @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Size; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class IssueTypeConfig { + @JsonProperty("include") + @Size(max = 1000, message = "Issue type filter should not be more than 1000") + private List include = new ArrayList<>(); + + @JsonProperty("exclude") + @Size(max = 1000, message = "Issue type filter should not be more than 1000") + private List exclude = new ArrayList<>(); +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/NameConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/NameConfig.java new file mode 100644 index 0000000000..3df833d072 --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/NameConfig.java @@ -0,0 +1,30 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Size; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class NameConfig { + @JsonProperty("include") + @Size(max = 1000, message = "Project name type filter should not be more than 1000") + private List include = new ArrayList<>(); + + @JsonProperty("exclude") + @Size(max = 1000, message = "Project name type filter should not be more than 1000") + private List exclude = new ArrayList<>(); +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/Oauth2Config.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/Oauth2Config.java new file mode 100644 index 0000000000..3282e7b38f --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/Oauth2Config.java @@ -0,0 +1,35 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.AssertTrue; +import lombok.Getter; + +@Getter +public class Oauth2Config { + @JsonProperty("client_id") + private String clientId; + + @JsonProperty("client_secret") + private String clientSecret; + + @JsonProperty("access_token") + private String accessToken; + + @JsonProperty("refresh_token") + private String refreshToken; + + @AssertTrue(message = "Client ID, Client Secret, Access Token, and Refresh Token are both required for Oauth2") + private boolean isOauth2ConfigValid() { + return clientId != null && clientSecret != null && accessToken != null && refreshToken != null; + } +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/ProjectConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/ProjectConfig.java new file mode 100644 index 0000000000..19bec8ad05 --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/ProjectConfig.java @@ -0,0 +1,20 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +@Getter +public class ProjectConfig { + @JsonProperty("key") + private NameConfig nameConfig; +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/StatusConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/StatusConfig.java new file mode 100644 index 0000000000..288d138f31 --- /dev/null +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/configuration/StatusConfig.java @@ -0,0 +1,29 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +package org.opensearch.dataprepper.plugins.source.jira.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import jakarta.validation.constraints.Size; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public class StatusConfig { + @JsonProperty("include") + @Size(max = 1000, message = "status type filter should not be more than 1000") + private List include = new ArrayList<>(); + + @JsonProperty("exclude") + @Size(max = 1000, message = "status type filter should not be more than 1000") + private List exclude = new ArrayList<>(); +} diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestException.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestException.java index 589e8626ab..69c0cca638 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestException.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestException.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.exception; /** diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedException.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedException.java index 1efa30e032..441f966bd8 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedException.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedException.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.exception; /** diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBean.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBean.java index ec437ac25d..5f2769883f 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBean.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBean.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.models; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResults.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResults.java index 96bc445cdb..677967a340 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResults.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResults.java @@ -1,3 +1,14 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + + package org.opensearch.dataprepper.plugins.source.jira.models; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptor.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptor.java index 57dbb65f94..e3a1b992f0 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptor.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptor.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; @@ -17,8 +27,8 @@ public class BasicAuthInterceptor implements ClientHttpRequestInterceptor { private final String password; public BasicAuthInterceptor(JiraSourceConfig config) { - this.username = config.getJiraId(); - this.password = config.getJiraCredential(); + this.username = config.getAuthenticationConfig().getBasicConfig().getUsername(); + this.password = config.getAuthenticationConfig().getBasicConfig().getPassword();; } @Override diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfig.java index 231351bcee..70cd189267 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfig.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfig.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClient.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClient.java index 6b71a032b8..caf5d84ee7 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClient.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClient.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import com.google.common.annotations.VisibleForTesting; @@ -34,17 +44,20 @@ public class JiraRestClient { public static final String REST_API_SEARCH = "rest/api/3/search"; public static final String REST_API_FETCH_ISSUE = "rest/api/3/issue"; + public static final String REST_API_PROJECTS = "/rest/api/3/project/search"; public static final String FIFTY = "50"; public static final String START_AT = "startAt"; public static final String MAX_RESULT = "maxResults"; public static final List RETRY_ATTEMPT_SLEEP_TIME = List.of(1, 2, 5, 10, 20, 40); private static final String TICKET_FETCH_LATENCY_TIMER = "ticketFetchLatency"; private static final String SEARCH_CALL_LATENCY_TIMER = "searchCallLatency"; + private static final String PROJECTS_FETCH_LATENCY_TIMER = "projectFetchLatency"; private static final String ISSUES_REQUESTED = "issuesRequested"; private final RestTemplate restTemplate; private final JiraAuthConfig authConfig; private final Timer ticketFetchLatencyTimer; private final Timer searchCallLatencyTimer; + private final Timer projectFetchLatencyTimer; private final Counter issuesRequestedCounter; private final PluginMetrics jiraPluginMetrics = PluginMetrics.fromNames("jiraRestClient", "aws"); private int sleepTimeMultiplier = 1000; @@ -55,6 +68,8 @@ public JiraRestClient(RestTemplate restTemplate, JiraAuthConfig authConfig) { ticketFetchLatencyTimer = jiraPluginMetrics.timer(TICKET_FETCH_LATENCY_TIMER); searchCallLatencyTimer = jiraPluginMetrics.timer(SEARCH_CALL_LATENCY_TIMER); + projectFetchLatencyTimer = jiraPluginMetrics.timer(PROJECTS_FETCH_LATENCY_TIMER); + issuesRequestedCounter = jiraPluginMetrics.counter(ISSUES_REQUESTED); } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptor.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptor.java index bf748ceb26..be71df7ac7 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptor.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptor.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import org.opensearch.dataprepper.plugins.source.jira.rest.auth.JiraAuthConfig; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthConfig.java index 274ce8b5d7..cae78da954 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthConfig.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthConfig.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; /** diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactory.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactory.java index 1ba1d9717f..f178d56812 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactory.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactory.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfig.java index 233cbf9f49..32509a2229 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfig.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfig.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfig.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfig.java index f7f4e8493f..791c9e6ff4 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfig.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfig.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; import lombok.Getter; @@ -55,10 +65,10 @@ public class JiraOauthConfig implements JiraAuthConfig { public JiraOauthConfig(JiraSourceConfig jiraSourceConfig) { this.jiraSourceConfig = jiraSourceConfig; - this.accessToken = jiraSourceConfig.getAccessToken(); - this.refreshToken = jiraSourceConfig.getRefreshToken(); - this.clientId = jiraSourceConfig.getClientId(); - this.clientSecret = jiraSourceConfig.getClientSecret(); + this.accessToken = jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getAccessToken(); + this.refreshToken = jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getRefreshToken(); + this.clientId = jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getClientId(); + this.clientSecret = jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getClientSecret(); } public String getJiraAccountCloudId() { diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidation.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidation.java index 0fc1c379f5..d6cc166226 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidation.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidation.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; import lombok.NonNull; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/Constants.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/Constants.java index ff6a780bfd..067380def6 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/Constants.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/Constants.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; /** diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraConfigHelper.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraConfigHelper.java index 07b1e1a213..dd815bd607 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraConfigHelper.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraConfigHelper.java @@ -1,9 +1,20 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; import lombok.extern.slf4j.Slf4j; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; +import java.util.ArrayList; import java.util.List; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.BASIC; @@ -14,18 +25,23 @@ */ @Slf4j public class JiraConfigHelper { - - public static final String ISSUE_STATUS_FILTER = "status"; - public static final String ISSUE_TYPE_FILTER = "issuetype"; - - /** * Get Issue Status Filter from repository configuration. * * @return List Issue Status Filter. */ - public static List getIssueStatusFilter(JiraSourceConfig repositoryConfiguration) { - return repositoryConfiguration.getStatus(); + public static List getIssueStatusIncludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || repositoryConfiguration.getFilterConfig().getStatusConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getStatusConfig().getInclude(); + } + + public static List getIssueStatusExcludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || repositoryConfiguration.getFilterConfig().getStatusConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getStatusConfig().getExclude(); } /** @@ -33,8 +49,18 @@ public static List getIssueStatusFilter(JiraSourceConfig repositoryConfi * * @return List Issue Type Filter. */ - public static List getIssueTypeFilter(JiraSourceConfig repositoryConfiguration) { - return repositoryConfiguration.getIssueType(); + public static List getIssueTypeIncludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || repositoryConfiguration.getFilterConfig().getIssueTypeConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getIssueTypeConfig().getInclude(); + } + + public static List getIssueTypeExcludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || repositoryConfiguration.getFilterConfig().getIssueTypeConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getIssueTypeConfig().getExclude(); } /** @@ -43,8 +69,22 @@ public static List getIssueTypeFilter(JiraSourceConfig repositoryConfigu * * @return List Project Filter. */ - public static List getProjectKeyFilter(JiraSourceConfig repositoryConfiguration) { - return repositoryConfiguration.getProject(); + public static List getProjectNameIncludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || + repositoryConfiguration.getFilterConfig().getProjectConfig() == null || + repositoryConfiguration.getFilterConfig().getProjectConfig().getNameConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getProjectConfig().getNameConfig().getInclude(); + } + + public static List getProjectNameExcludeFilter(JiraSourceConfig repositoryConfiguration) { + if (repositoryConfiguration.getFilterConfig() == null || + repositoryConfiguration.getFilterConfig().getProjectConfig() == null || + repositoryConfiguration.getFilterConfig().getProjectConfig().getNameConfig() == null) { + return new ArrayList<>(); + } + return repositoryConfiguration.getFilterConfig().getProjectConfig().getNameConfig().getExclude(); } @@ -62,13 +102,13 @@ public static boolean validateConfig(JiraSourceConfig config) { } if (BASIC.equals(authType)) { - if (config.getJiraId() == null || config.getJiraCredential() == null) { + if (config.getAuthenticationConfig().getBasicConfig().getUsername() == null || config.getAuthenticationConfig().getBasicConfig().getPassword() == null) { throw new RuntimeException("Jira ID or Credential are required for Basic AuthType"); } } if (OAUTH2.equals(authType)) { - if (config.getAccessToken() == null || config.getRefreshToken() == null) { + if (config.getAuthenticationConfig().getOauth2Config().getAccessToken() == null || config.getAuthenticationConfig().getOauth2Config().getRefreshToken() == null) { throw new RuntimeException("Access Token or Refresh Token are required for OAuth2 AuthType"); } } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentType.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentType.java index 9d37a6e8ca..3f43c0e01e 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentType.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentType.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; import lombok.AllArgsConstructor; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JqlConstants.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JqlConstants.java index 5b88208f74..99474024e1 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JqlConstants.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/main/java/org/opensearch/dataprepper/plugins/source/jira/utils/JqlConstants.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; public class JqlConstants { @@ -7,10 +17,13 @@ public class JqlConstants { public static final String SLASH = "/"; public static final String PROJECT_IN = " AND project in ("; public static final String STATUS_IN = " AND status in ("; + public static final String PROJECT_NOT_IN = " AND project not in ("; + public static final String STATUS_NOT_IN = " AND status not in ("; public static final String DELIMITER = "\",\""; public static final String PREFIX = "\""; public static final String SUFFIX = "\""; public static final String ISSUE_TYPE_IN = " AND issueType in ("; + public static final String ISSUE_TYPE_NOT_IN = " AND issueType not in ("; public static final String JQL_FIELD = "jql"; public static final String EXPAND_FIELD = "expand"; public static final String EXPAND_VALUE = "all"; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraClientTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraClientTest.java index 4720ffc89b..78531afd61 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraClientTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraClientTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraConfigHelperTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraConfigHelperTest.java index ac26864a25..eeb9c03941 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraConfigHelperTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraConfigHelperTest.java @@ -1,9 +1,27 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.BasicConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.FilterConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.IssueTypeConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.NameConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.Oauth2Config; +import org.opensearch.dataprepper.plugins.source.jira.configuration.ProjectConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.StatusConfig; import org.opensearch.dataprepper.plugins.source.jira.utils.JiraConfigHelper; import java.util.List; @@ -23,6 +41,30 @@ public class JiraConfigHelperTest { @Mock JiraSourceConfig jiraSourceConfig; + @Mock + FilterConfig filterConfig; + + @Mock + StatusConfig statusConfig; + + @Mock + IssueTypeConfig issueTypeConfig; + + @Mock + ProjectConfig projectConfig; + + @Mock + NameConfig nameConfig; + + @Mock + AuthenticationConfig authenticationConfig; + + @Mock + BasicConfig basicConfig; + + @Mock + Oauth2Config oauth2Config; + @Test void testInitialization() { JiraConfigHelper jiraConfigHelper = new JiraConfigHelper(); @@ -31,28 +73,48 @@ void testInitialization() { @Test void testGetIssueStatusFilter() { - assertTrue(JiraConfigHelper.getIssueStatusFilter(jiraSourceConfig).isEmpty()); + when(jiraSourceConfig.getFilterConfig()).thenReturn(filterConfig); + when(filterConfig.getStatusConfig()).thenReturn(statusConfig); + assertTrue(JiraConfigHelper.getIssueStatusIncludeFilter(jiraSourceConfig).isEmpty()); + assertTrue(JiraConfigHelper.getIssueStatusExcludeFilter(jiraSourceConfig).isEmpty()); List issueStatusFilter = List.of("Done", "In Progress"); - when(jiraSourceConfig.getProject()).thenReturn(issueStatusFilter); - assertEquals(issueStatusFilter, JiraConfigHelper.getProjectKeyFilter(jiraSourceConfig)); + List issueStatusExcludeFilter = List.of("Done2", "In Progress2"); + when(statusConfig.getInclude()).thenReturn(issueStatusFilter); + when(statusConfig.getExclude()).thenReturn(issueStatusExcludeFilter); + assertEquals(issueStatusFilter, JiraConfigHelper.getIssueStatusIncludeFilter(jiraSourceConfig)); + assertEquals(issueStatusExcludeFilter, JiraConfigHelper.getIssueStatusExcludeFilter(jiraSourceConfig)); } @Test void testGetIssueTypeFilter() { - assertTrue(JiraConfigHelper.getProjectKeyFilter(jiraSourceConfig).isEmpty()); + when(jiraSourceConfig.getFilterConfig()).thenReturn(filterConfig); + when(filterConfig.getIssueTypeConfig()).thenReturn(issueTypeConfig); + assertTrue(JiraConfigHelper.getIssueTypeIncludeFilter(jiraSourceConfig).isEmpty()); + assertTrue(JiraConfigHelper.getIssueTypeExcludeFilter(jiraSourceConfig).isEmpty()); List issueTypeFilter = List.of("Bug", "Story"); - when(jiraSourceConfig.getProject()).thenReturn(issueTypeFilter); - assertEquals(issueTypeFilter, JiraConfigHelper.getProjectKeyFilter(jiraSourceConfig)); + List issueTypeExcludeFilter = List.of("Bug2", "Story2"); + when(issueTypeConfig.getInclude()).thenReturn(issueTypeFilter); + when(issueTypeConfig.getExclude()).thenReturn(issueTypeExcludeFilter); + assertEquals(issueTypeFilter, JiraConfigHelper.getIssueTypeIncludeFilter(jiraSourceConfig)); + assertEquals(issueTypeExcludeFilter, JiraConfigHelper.getIssueTypeExcludeFilter(jiraSourceConfig)); } @Test - void testGetProjectKeyFilter() { - assertTrue(JiraConfigHelper.getProjectKeyFilter(jiraSourceConfig).isEmpty()); - List projectKeyFilter = List.of("TEST", "TEST2"); - when(jiraSourceConfig.getProject()).thenReturn(projectKeyFilter); - assertEquals(projectKeyFilter, JiraConfigHelper.getProjectKeyFilter(jiraSourceConfig)); + void testGetProjectNameFilter() { + when(jiraSourceConfig.getFilterConfig()).thenReturn(filterConfig); + when(filterConfig.getProjectConfig()).thenReturn(projectConfig); + when(projectConfig.getNameConfig()).thenReturn(nameConfig); + assertTrue(JiraConfigHelper.getProjectNameIncludeFilter(jiraSourceConfig).isEmpty()); + assertTrue(JiraConfigHelper.getProjectNameExcludeFilter(jiraSourceConfig).isEmpty()); + List projectNameFilter = List.of("TEST", "TEST2"); + List projectNameExcludeFilter = List.of("TEST3", "TEST4"); + when(nameConfig.getInclude()).thenReturn(projectNameFilter); + when(nameConfig.getExclude()).thenReturn(projectNameExcludeFilter); + assertEquals(projectNameFilter, JiraConfigHelper.getProjectNameIncludeFilter(jiraSourceConfig)); + assertEquals(projectNameExcludeFilter, JiraConfigHelper.getProjectNameExcludeFilter(jiraSourceConfig)); } + @Test void testValidateConfig() { assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); @@ -68,16 +130,18 @@ void testValidateConfig() { void testValidateConfigBasic() { when(jiraSourceConfig.getAccountUrl()).thenReturn("https://test.com"); when(jiraSourceConfig.getAuthType()).thenReturn(BASIC); + when(jiraSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getBasicConfig()).thenReturn(basicConfig); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getJiraId()).thenReturn("id"); + when(basicConfig.getUsername()).thenReturn("id"); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getJiraCredential()).thenReturn("credential"); - when(jiraSourceConfig.getJiraId()).thenReturn(null); + when(basicConfig.getPassword()).thenReturn("credential"); + when(basicConfig.getUsername()).thenReturn(null); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getJiraId()).thenReturn("id"); + when(basicConfig.getUsername()).thenReturn("id"); assertDoesNotThrow(() -> JiraConfigHelper.validateConfig(jiraSourceConfig)); } @@ -85,16 +149,18 @@ void testValidateConfigBasic() { void testValidateConfigOauth2() { when(jiraSourceConfig.getAccountUrl()).thenReturn("https://test.com"); when(jiraSourceConfig.getAuthType()).thenReturn(OAUTH2); + when(jiraSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getOauth2Config()).thenReturn(oauth2Config); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getAccessToken()).thenReturn("id"); + when(oauth2Config.getAccessToken()).thenReturn("id"); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getRefreshToken()).thenReturn("credential"); - when(jiraSourceConfig.getAccessToken()).thenReturn(null); + when(oauth2Config.getRefreshToken()).thenReturn("credential"); + when(oauth2Config.getAccessToken()).thenReturn(null); assertThrows(RuntimeException.class, () -> JiraConfigHelper.validateConfig(jiraSourceConfig)); - when(jiraSourceConfig.getAccessToken()).thenReturn("id"); + when(oauth2Config.getAccessToken()).thenReturn("id"); assertDoesNotThrow(() -> JiraConfigHelper.validateConfig(jiraSourceConfig)); } } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfoTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfoTest.java index 49dc6873bd..f5e6b0906b 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfoTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraItemInfoTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraIteratorTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraIteratorTest.java index 8d9dc85869..73e184330a 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraIteratorTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraIteratorTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java index af07ab6f0d..0de0ea47dc 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import com.fasterxml.jackson.core.JsonProcessingException; @@ -45,6 +55,7 @@ import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.CREATED; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.KEY; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.NAME; +import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.OAUTH2; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.PROJECT; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.UPDATED; @@ -85,16 +96,45 @@ public static JiraSourceConfig createJiraConfiguration(String auth_type, List issueStatus, List projectKey) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); - Map connectorCredentialsMap = new HashMap<>(); - connectorCredentialsMap.put("auth_type", auth_type); + Map authenticationMap = new HashMap<>(); + Map basicMap = new HashMap<>(); + Map oauth2Map = new HashMap<>(); + if (auth_type.equals(BASIC)) { + basicMap.put("username", "test_username"); + basicMap.put("password", "test_password"); + authenticationMap.put("basic", basicMap); + } else if (auth_type.equals(OAUTH2)) { + oauth2Map.put("client_id", "test-client-id"); + oauth2Map.put("client_secret", "test-client-secret"); + oauth2Map.put("access_token", "test-access-token"); + oauth2Map.put("refresh_token", "test-refresh-token"); + authenticationMap.put("oauth2", oauth2Map); + } Map jiraSourceConfigMap = new HashMap<>(); - jiraSourceConfigMap.put("account_url", ACCESSIBLE_RESOURCES); - jiraSourceConfigMap.put("connector_credentials", connectorCredentialsMap); - jiraSourceConfigMap.put("issue_types", issueType); - jiraSourceConfigMap.put("statuses", issueStatus); - jiraSourceConfigMap.put("projects", projectKey); + List hosts = new ArrayList<>(); + hosts.add(ACCESSIBLE_RESOURCES); + + Map filterMap = new HashMap<>(); + Map projectMap = new HashMap<>(); + Map issueTypeMap = new HashMap<>(); + Map statusMap = new HashMap<>(); + + issueTypeMap.put("include", issueType); + filterMap.put("issue_type", issueTypeMap); + + statusMap.put("include", issueStatus); + filterMap.put("status", statusMap); + + Map nameMap = new HashMap<>(); + nameMap.put("include", projectKey); + projectMap.put("key", nameMap); + filterMap.put("project", projectMap); + + jiraSourceConfigMap.put("hosts", hosts); + jiraSourceConfigMap.put("authentication", authenticationMap); + jiraSourceConfigMap.put("filter", filterMap); String jiraSourceConfigJsonString = objectMapper.writeValueAsString(jiraSourceConfigMap); return objectMapper.readValue(jiraSourceConfigJsonString, JiraSourceConfig.class); diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java index 9da7011d0d..35a2450fdb 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import com.fasterxml.jackson.core.JsonProcessingException; @@ -21,54 +31,69 @@ public class JiraSourceConfigTest { private final String refreshToken = "refresh token test"; private final String clientId = "client id test"; private final String clientSecret = "client secret test"; - private final String jiraCredential = "test Jira Credential"; - private final String jiraId = "test Jira Id"; + private final String password = "test Jira Credential"; + private final String username = "test Jira Id"; private final String accountUrl = "https://example.atlassian.net"; private List projectList = new ArrayList<>(); private List issueTypeList = new ArrayList<>(); - private List inclusionPatternList = new ArrayList<>(); - private List exclusionPatternList = new ArrayList<>(); private List statusList = new ArrayList<>(); - private Map connectorCredentialMap = new HashMap<>(); private JiraSourceConfig jiraSourceConfig; private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToken) throws JsonProcessingException { Map configMap = new HashMap<>(); - configMap.put("account_url", accountUrl); - - connectorCredentialMap.put("auth_type", authtype); - if (hasToken) { - connectorCredentialMap.put("access_token", accessToken); - connectorCredentialMap.put("refresh_token", refreshToken); - } else { - connectorCredentialMap.put("refresh_token", ""); + List hosts = new ArrayList<>(); + hosts.add(accountUrl); + + configMap.put("hosts", hosts); + + Map authenticationMap = new HashMap<>(); + Map basicMap = new HashMap<>(); + Map oauth2Map = new HashMap<>(); + if (authtype.equals(BASIC)) { + basicMap.put("username", username); + basicMap.put("password", password); + authenticationMap.put("basic", basicMap); + } else if (authtype.equals(OAUTH2)) { + if (hasToken) { + oauth2Map.put("access_token", accessToken); + oauth2Map.put("refresh_token", refreshToken); + } else { + oauth2Map.put("access_token", null); + oauth2Map.put("refresh_token", null); + } + oauth2Map.put("client_id", clientId); + oauth2Map.put("client_secret", clientSecret); + authenticationMap.put("oauth2", oauth2Map); } - connectorCredentialMap.put("jira_id", jiraId); - connectorCredentialMap.put("jira_credential", jiraCredential); - connectorCredentialMap.put("client_id", clientId); - connectorCredentialMap.put("client_secret", clientSecret); - configMap.put("connector_credentials", connectorCredentialMap); + configMap.put("authentication", authenticationMap); projectList.add("project1"); projectList.add("project2"); - configMap.put("projects", projectList); issueTypeList.add("issue type 1"); issueTypeList.add("issue type 2"); - configMap.put("issue_types", issueTypeList); - - inclusionPatternList.add("pattern 1"); - inclusionPatternList.add("pattern 2"); - configMap.put("inclusion_patterns", inclusionPatternList); - - exclusionPatternList.add("pattern 3"); - exclusionPatternList.add("pattern 4"); - configMap.put("exclusion_patterns", exclusionPatternList); statusList.add("status 1"); statusList.add("status 2"); - configMap.put("statuses", statusList); + + Map filterMap = new HashMap<>(); + Map projectMap = new HashMap<>(); + Map issueTypeMap = new HashMap<>(); + Map statusMap = new HashMap<>(); + + issueTypeMap.put("include", issueTypeList); + filterMap.put("issue_type", issueTypeMap); + + statusMap.put("include", statusList); + filterMap.put("status", statusMap); + + Map nameMap = new HashMap<>(); + nameMap.put("include", projectList); + projectMap.put("key", nameMap); + filterMap.put("project", projectMap); + + configMap.put("filter", filterMap); ObjectMapper objectMapper = new ObjectMapper(); String jsonConfig = objectMapper.writeValueAsString(configMap); @@ -79,40 +104,29 @@ private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToke @Test void testGetters() throws JsonProcessingException { jiraSourceConfig = createJiraSourceConfig(BASIC, false); - assertEquals(jiraSourceConfig.getInclusionPatterns(), inclusionPatternList); - assertEquals(jiraSourceConfig.getIssueType(), issueTypeList); - assertEquals(jiraSourceConfig.getExclusionPatterns(), exclusionPatternList); + assertEquals(jiraSourceConfig.getFilterConfig().getIssueTypeConfig().getInclude(), issueTypeList); assertEquals(jiraSourceConfig.getNumWorkers(), DEFAULT_NUMBER_OF_WORKERS); - assertEquals(jiraSourceConfig.getProject(), projectList); - assertEquals(jiraSourceConfig.getStatus(), statusList); - assertEquals(jiraSourceConfig.getConnectorCredentials(), connectorCredentialMap); + assertEquals(jiraSourceConfig.getFilterConfig().getProjectConfig().getNameConfig().getInclude(), projectList); + assertEquals(jiraSourceConfig.getFilterConfig().getStatusConfig().getInclude(), statusList); assertEquals(jiraSourceConfig.getAccountUrl(), accountUrl); assertNotNull(jiraSourceConfig.getBackOff()); - assertEquals(jiraSourceConfig.getJiraCredential(), jiraCredential); - assertEquals(jiraSourceConfig.getJiraId(), jiraId); + assertEquals(jiraSourceConfig.getAuthenticationConfig().getBasicConfig().getPassword(), password); + assertEquals(jiraSourceConfig.getAuthenticationConfig().getBasicConfig().getUsername(), username); } @Test void testFetchGivenOauthAttributeWrongAuthType() throws JsonProcessingException { jiraSourceConfig = createJiraSourceConfig(BASIC, true); - assertThrows(RuntimeException.class, () -> jiraSourceConfig.getAccessToken()); + assertThrows(RuntimeException.class, () -> jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getAccessToken()); } @Test void testFetchGivenOauthAtrribute() throws JsonProcessingException { jiraSourceConfig = createJiraSourceConfig(OAUTH2, true); - assertEquals(accessToken, jiraSourceConfig.getAccessToken()); - assertEquals(refreshToken, jiraSourceConfig.getRefreshToken()); - assertEquals(clientId, jiraSourceConfig.getClientId()); - assertEquals(clientSecret, jiraSourceConfig.getClientSecret()); - } - - @Test - void testFetchGivenOauthAtrributeMissing() throws JsonProcessingException { - jiraSourceConfig = createJiraSourceConfig(OAUTH2, false); - assertThrows(RuntimeException.class, () -> jiraSourceConfig.getAccessToken()); - assertThrows(RuntimeException.class, () -> jiraSourceConfig.getRefreshToken()); - + assertEquals(accessToken, jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getAccessToken()); + assertEquals(refreshToken, jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getRefreshToken()); + assertEquals(clientId, jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getClientId()); + assertEquals(clientSecret, jiraSourceConfig.getAuthenticationConfig().getOauth2Config().getClientSecret()); } } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceTest.java index 46cf58b7a9..725c91b66e 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira; import org.junit.jupiter.api.Test; @@ -11,6 +21,8 @@ import org.opensearch.dataprepper.model.plugin.PluginFactory; import org.opensearch.dataprepper.model.record.Record; import org.opensearch.dataprepper.model.source.coordinator.enhanced.EnhancedSourceCoordinator; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.BasicConfig; import org.opensearch.dataprepper.plugins.source.jira.rest.auth.JiraAuthConfig; import org.opensearch.dataprepper.plugins.source.source_crawler.base.Crawler; import org.opensearch.dataprepper.plugins.source.source_crawler.base.PluginExecutorServiceProvider; @@ -58,7 +70,12 @@ public class JiraSourceTest { @Mock private ExecutorService executorService; -// = new PluginExecutorServiceProvider(); + + @Mock + AuthenticationConfig authenticationConfig; + + @Mock + BasicConfig basicConfig; @Test void initialization() { @@ -73,8 +90,10 @@ void testStart() { JiraSource source = new JiraSource(pluginMetrics, jiraSourceConfig, jiraOauthConfig, pluginFactory, acknowledgementSetManager, crawler, executorServiceProvider); when(jiraSourceConfig.getAccountUrl()).thenReturn(ACCESSIBLE_RESOURCES); when(jiraSourceConfig.getAuthType()).thenReturn(BASIC); - when(jiraSourceConfig.getJiraId()).thenReturn("Test Id"); - when(jiraSourceConfig.getJiraCredential()).thenReturn("Test Credential"); + when(jiraSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getBasicConfig()).thenReturn(basicConfig); + when(basicConfig.getUsername()).thenReturn("Test Id"); + when(basicConfig.getPassword()).thenReturn("Test Credential"); source.setEnhancedSourceCoordinator(sourceCooridinator); source.start(buffer); @@ -87,8 +106,10 @@ void testStop() { JiraSource source = new JiraSource(pluginMetrics, jiraSourceConfig, jiraOauthConfig, pluginFactory, acknowledgementSetManager, crawler, executorServiceProvider); when(jiraSourceConfig.getAccountUrl()).thenReturn(ACCESSIBLE_RESOURCES); when(jiraSourceConfig.getAuthType()).thenReturn(BASIC); - when(jiraSourceConfig.getJiraId()).thenReturn("Test Id"); - when(jiraSourceConfig.getJiraCredential()).thenReturn("Test Credential"); + when(jiraSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getBasicConfig()).thenReturn(basicConfig); + when(basicConfig.getUsername()).thenReturn("Test Id"); + when(basicConfig.getPassword()).thenReturn("Test Credential"); source.setEnhancedSourceCoordinator(sourceCooridinator); source.start(buffer); diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestExceptionTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestExceptionTest.java index 74f5873af2..91578ec810 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestExceptionTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/BadRequestExceptionTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.exception; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedExceptionTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedExceptionTest.java index ecedff2d60..87c06051e1 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedExceptionTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/exception/UnAuthorizedExceptionTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.exception; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBeanTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBeanTest.java index 0f99ddccbf..812c59c1f7 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBeanTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/IssueBeanTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.models; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResultsTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResultsTest.java index 3a569ca39d..bd0d54e2bf 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResultsTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/models/SearchResultsTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.models; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptorTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptorTest.java index 18c94cb426..a57b879d6d 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptorTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/BasicAuthInterceptorTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import org.junit.jupiter.api.BeforeEach; @@ -6,6 +16,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.BasicConfig; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; @@ -36,6 +48,12 @@ public class BasicAuthInterceptorTest { @Mock private JiraSourceConfig mockConfig; + @Mock + AuthenticationConfig authenticationConfig; + + @Mock + BasicConfig basicConfig; + @Mock private HttpHeaders mockHeaders; @@ -43,8 +61,10 @@ public class BasicAuthInterceptorTest { @BeforeEach void setUp() { - when(mockConfig.getJiraId()).thenReturn("testUser"); - when(mockConfig.getJiraCredential()).thenReturn("testPassword"); + when(mockConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getBasicConfig()).thenReturn(basicConfig); + when(basicConfig.getUsername()).thenReturn("testUser"); + when(basicConfig.getPassword()).thenReturn("testPassword"); when(mockRequest.getHeaders()).thenReturn(mockHeaders); interceptor = new BasicAuthInterceptor(mockConfig); } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfigTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfigTest.java index ce0675f22a..11d29c78c0 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfigTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/CustomRestTemplateConfigTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import org.junit.jupiter.api.BeforeEach; @@ -8,6 +18,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.BasicConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.Oauth2Config; import org.opensearch.dataprepper.plugins.source.jira.rest.auth.JiraAuthConfig; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.InterceptingClientHttpRequestFactory; @@ -19,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.BASIC; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.OAUTH2; @@ -34,6 +48,15 @@ class CustomRestTemplateConfigTest { @Mock private JiraAuthConfig mockAuthConfig; + @Mock + private BasicConfig mockBasicConfig; + + @Mock + private Oauth2Config mockOauth2Config; + + @Mock + private AuthenticationConfig mockAuthenticationConfig; + private static Stream provideAuthTypeAndExpectedInterceptorType() { return Stream.of( Arguments.of(OAUTH2, OAuth2RequestInterceptor.class), @@ -52,6 +75,16 @@ void setUp() { @MethodSource("provideAuthTypeAndExpectedInterceptorType") void testBasicAuthRestTemplateWithOAuth2(String authType, Class interceptorClassType) { when(mockSourceConfig.getAuthType()).thenReturn(authType); + lenient().when(mockSourceConfig.getAuthenticationConfig()).thenReturn(mockAuthenticationConfig); + lenient().when(mockAuthenticationConfig.getOauth2Config()).thenReturn(mockOauth2Config); + lenient().when(mockOauth2Config.getAccessToken()).thenReturn("accessToken"); + lenient().when(mockOauth2Config.getRefreshToken()).thenReturn("refreshToken"); + lenient().when(mockOauth2Config.getClientId()).thenReturn("clientId"); + lenient().when(mockOauth2Config.getClientSecret()).thenReturn("clientSecret"); + lenient().when(mockAuthenticationConfig.getBasicConfig()).thenReturn(mockBasicConfig); + lenient().when(mockBasicConfig.getUsername()).thenReturn("username"); + lenient().when(mockBasicConfig.getPassword()).thenReturn("password"); + RestTemplate restTemplate = config.basicAuthRestTemplate(mockSourceConfig, mockAuthConfig); assertNotNull(restTemplate); assertInstanceOf(InterceptingClientHttpRequestFactory.class, restTemplate.getRequestFactory()); diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClientTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClientTest.java index d294b4f599..3fe0640700 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClientTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/JiraRestClientTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptorTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptorTest.java index 277c42ca2e..01e850fec9 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptorTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/OAuth2RequestInterceptorTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactoryTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactoryTest.java index 566b3ae8ed..5106bd8ad1 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactoryTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraAuthFactoryTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; import org.junit.jupiter.api.BeforeEach; @@ -6,6 +16,8 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.opensearch.dataprepper.plugins.source.jira.JiraSourceConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.AuthenticationConfig; +import org.opensearch.dataprepper.plugins.source.jira.configuration.Oauth2Config; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; @@ -18,6 +30,12 @@ public class JiraAuthFactoryTest { @Mock private JiraSourceConfig sourceConfig; + @Mock + private AuthenticationConfig authenticationConfig; + + @Mock + private Oauth2Config oauth2Config; + private JiraAuthFactory jiraAuthFactory; @BeforeEach @@ -28,6 +46,8 @@ void setUp() { @Test void testGetObjectOauth2() { when(sourceConfig.getAuthType()).thenReturn(OAUTH2); + when(sourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig); + when(authenticationConfig.getOauth2Config()).thenReturn(oauth2Config); assertInstanceOf(JiraOauthConfig.class, jiraAuthFactory.getObject()); } diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfigTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfigTest.java index 60dad25507..8ab10eb0bc 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfigTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraBasicAuthConfigTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; import org.junit.jupiter.api.BeforeEach; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfigTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfigTest.java index 1b648ab404..bafe995801 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfigTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/rest/auth/JiraOauthConfigTest.java @@ -1,5 +1,16 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.rest.auth; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -38,7 +49,13 @@ public class JiraOauthConfigTest { @Mock RestTemplate restTemplateMock; - JiraSourceConfig jiraSourceConfig = createJiraConfigurationFromYaml("oauth2-auth-jira-pipeline.yaml"); + + JiraSourceConfig jiraSourceConfig; + + @BeforeEach + void setUp() { + jiraSourceConfig = createJiraConfigurationFromYaml("oauth2-auth-jira-pipeline.yaml"); + } @Test void testRenewToken() throws InterruptedException { diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidationTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidationTest.java index b6f56a11ee..3c346c8e0e 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidationTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/AddressValidationTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; import org.junit.jupiter.api.Test; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentTypeTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentTypeTest.java index c342e9a3cd..3437ab9319 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentTypeTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/utils/JiraContentTypeTest.java @@ -1,3 +1,13 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + package org.opensearch.dataprepper.plugins.source.jira.utils; import org.junit.jupiter.api.Test; diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/basic-auth-jira-pipeline.yaml b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/basic-auth-jira-pipeline.yaml index 09b15d40d6..0bfa6384e8 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/basic-auth-jira-pipeline.yaml +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/basic-auth-jira-pipeline.yaml @@ -1,6 +1,6 @@ -account_url: "https://jira.com/" -connector_credentials: - auth_type: "Basic" - jira_id: "jiraId" - jira_credential: "jiraApiKey" +hosts: ["https://jira.com/"] +authentication: + basic: + username: "jiraId" + password: "jiraApiKey" diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/oauth2-auth-jira-pipeline.yaml b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/oauth2-auth-jira-pipeline.yaml index ae1f0b508d..09c9e9f2c5 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/oauth2-auth-jira-pipeline.yaml +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/resources/oauth2-auth-jira-pipeline.yaml @@ -1,9 +1,8 @@ -account_url: "https://jira.com/" -connector_credentials: - auth_type: "OAuth2" - jira_id: "jira_id" - client_id: "client_id" - client_secret: "client_secret" - access_token: "access_token" - refresh_token: "refresh_token" +hosts: ["https://jira.com/"] +authentication: + oauth2: + client_id: "client_id" + client_secret: "client_secret" + access_token: "access_token" + refresh_token: "refresh_token"