Skip to content

Commit

Permalink
better organized servcice class and helper classes
Browse files Browse the repository at this point in the history
Signed-off-by: Santhosh Gandhe <[email protected]>
  • Loading branch information
san81 committed Oct 17, 2024
1 parent 0ab666c commit 3f9de0f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ public class JiraConfigHelper {
public static final String ISSUE_STATUS_FILTER = "status";
public static final String ISSUE_TYPE_FILTER = "issuetype";

private final OAuth2RestHelper auth2RestHelper;
private final JiraSourceConfig config;

public JiraConfigHelper(OAuth2RestHelper auth2RestHelper, JiraSourceConfig config) {
this.auth2RestHelper = auth2RestHelper;
public JiraConfigHelper(JiraSourceConfig config) {
this.config = config;
}

Expand Down Expand Up @@ -164,16 +162,4 @@ public boolean validateConfig(JiraSourceConfig config) {
}
return true;
}

public String getAuthTypeBasedJiraUrl() {
//For OAuth based flow, we use a different Jira url
String authType = config.getAuthType();
if(OAUTH2.equals(authType)){
String cloudId = this.auth2RestHelper.getJiraAccountCloudId(config);
return OAuth2_URL + cloudId + "/" + REST_API_FETCH_ISSUE;
}else {
return config.getAccountUrl() + REST_API_FETCH_ISSUE + "/";
}
}

}
Original file line number Diff line number Diff line change
@@ -1,69 +1,55 @@
package org.opensearch.dataprepper.plugins.source.saas.jira;

import lombok.Getter;
import lombok.Setter;
import org.opensearch.dataprepper.plugins.source.saas.jira.utils.Constants;
import org.slf4j.Logger;
import org.springframework.util.StringUtils;

import javax.inject.Named;
import java.util.HashMap;
import java.util.Map;

/**
* The type Jira service.
*/

@Setter
@Getter
public class JiraOauthConfig {
/**
* The Jira project cache.
*/
static Map<String, String> jiraProjectCache = new HashMap<>();
/**
* The Access token.
*/
static String accessToken = "";
/**
* The Refresh token.
*/
static String refreshToken = "";
/**
* The Client id.
*/
static String clientId = "";
/**
* The Client secret.
*/
static String clientSecret = "";

private static final Logger appLog =
org.slf4j.LoggerFactory.getLogger(JiraOauthConfig.class);

/**
* Set OauthConfigValues initially.
*/
static synchronized void setOauthConfigValues(String jiraId,
String jiraCredential, String jiraAccessToken,
String jiraRefreshToken) {
appLog.info("Setting OAuth configuration values for Jira Connector.");

if (!jiraId.equals(clientId)) {
clientId = jiraId;
}
if (!jiraCredential.equals(clientSecret)) {
clientSecret = jiraCredential;
}
if (!jiraAccessToken.equals(accessToken)) {
accessToken = jiraAccessToken;
}
if (!jiraRefreshToken.equals(refreshToken)) {
refreshToken = jiraRefreshToken;
}
private String accessToken = "";
private String refreshToken = "";
private String clientId = "";
private String clientSecret = "";

public JiraOauthConfig(String accessToken, String refreshToken, String clientId, String clientSecret) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.clientId = clientId;
this.clientSecret = clientSecret;
}

public JiraOauthConfig(JiraOauthConfig oauthConfig){
this.accessToken = oauthConfig.getAccessToken();
this.refreshToken = oauthConfig.getRefreshToken();
this.clientId = oauthConfig.getClientId();
this.clientSecret = oauthConfig.getClientSecret();
}

/**

/* *//**
* Get changed Access and Refresh Token when old expired.
*/
*//*
static synchronized void changeAccessAndRefreshToken(Object jiraConfiguration) {
appLog.info("Setting access-refresh token for Jira Connector.");
boolean configuaration = true;
if (jiraConfiguration instanceof JiraConfigHelper) {
configuaration = JiraService.reTestConnection((JiraConfigHelper) jiraConfiguration);
configuaration = JiraService. .reTestConnection((JiraConfigHelper) jiraConfiguration);
}
if (!configuaration) {
Expand All @@ -79,15 +65,15 @@ static synchronized void changeAccessAndRefreshToken(Object jiraConfiguration) {
}
}
/**
*//**
* create AccessRefreshToken Pair.
*
* @param clientId the configuration
* @return AccessRefreshToken
*/
*//*
private static HashMap<String, Object> createAccessRefreshTokenPair(
String clientId, String clientSecret, String refreshToken) {
/*appLog.info("Creating access-refresh token pair for Jira Connector.");
*//*appLog.info("Creating access-refresh token pair for Jira Connector.");
OAuthClientRequest accessRequest = null;
HashMap<String, Object> oauthValues = new HashMap<>();
try {
Expand Down Expand Up @@ -120,7 +106,7 @@ private static HashMap<String, Object> createAccessRefreshTokenPair(
throw new ContinuableBadRequestException(e.getMessage(), e);
}
}
return oauthValues;*/
return oauthValues;*//*
return null;
}
}*/
}
Loading

0 comments on commit 3f9de0f

Please sign in to comment.