Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Feat: Add support for the new property "Git Project" of the ADITO SSP…
Browse files Browse the repository at this point in the history
… that creates a new Git Repository for the specific SSP system
  • Loading branch information
L1nc0ln committed Sep 14, 2021
1 parent 78034d1 commit 66959c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/main/java/de/adito/nbm/ssp/checkout/SSPCheckoutExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.*;
import java.util.stream.*;
import java.util.stream.Collectors;

/**
* Performs the git checkout and writes the config files
Expand Down Expand Up @@ -76,11 +76,13 @@ static FileObject execute(@NotNull ProgressHandle pHandle, @NotNull ISSPSystemDe
Optional<String> tunnelConfigContentsOpt = getTunnelConfigContents(pHandle, pSystemDetails);
if (pIsCheckoutDeployedState && serverConfigContentsOpt.isPresent() && tunnelConfigContentsOpt.isPresent())
{
_checkoutDeployedState(pHandle, pSystemDetails, pTarget, serverConfigContentsOpt.get(), tunnelConfigContentsOpt.get());
_checkoutDeployedState(pHandle, pSystemDetails, _getGitProject(ISSPFacade.getInstance(), pSystemDetails, currentCredentials), pTarget,
serverConfigContentsOpt.get(), tunnelConfigContentsOpt.get());
}
else
{
boolean cloneSuccess = performGitClone(pHandle, pSystemDetails.getGitRepoUrl(), pSystemDetails.getGitBranch(), null, "origin", pTarget);
boolean cloneSuccess = performGitClone(pHandle, _getGitProject(ISSPFacade.getInstance(), pSystemDetails, currentCredentials),
pSystemDetails.getGitBranch(), null, "origin", pTarget);
if (cloneSuccess)
writeConfigs(pHandle, pSystemDetails, pTarget, currentCredentials);
else
Expand All @@ -97,8 +99,8 @@ static FileObject execute(@NotNull ProgressHandle pHandle, @NotNull ISSPSystemDe
return FileUtil.toFileObject(pTarget);
}

private static void _checkoutDeployedState(@NotNull ProgressHandle pHandle, @NotNull ISSPSystemDetails pSystemDetails, @NotNull File pTarget,
@NotNull String pServerConfigContents, @NotNull String pTunnelConfigContents)
private static void _checkoutDeployedState(@NotNull ProgressHandle pHandle, @NotNull ISSPSystemDetails pSystemDetails, @NotNull String pGitProjectUrl,
@NotNull File pTarget, @NotNull String pServerConfigContents, @NotNull String pTunnelConfigContents)
{
pHandle.setDisplayName("Starting tunnels");
boolean isTunnelsGo = _startTunnels(pTunnelConfigContents);
Expand All @@ -109,7 +111,7 @@ private static void _checkoutDeployedState(@NotNull ProgressHandle pHandle, @Not
Path tempServerConfigFile = Files.createTempFile("", "");
writeFileData(tempServerConfigFile.toFile(), pServerConfigContents);
Optional<String> deployedBranchName = _getDeployedBranch(tempServerConfigFile.toFile());
boolean cloneSuccess = performGitClone(pHandle, pSystemDetails.getGitRepoUrl(), deployedBranchName.orElse(pSystemDetails.getGitBranch()), null,
boolean cloneSuccess = performGitClone(pHandle, pGitProjectUrl, deployedBranchName.orElse(pSystemDetails.getGitBranch()), null,
"origin", pTarget);
if (cloneSuccess)
{
Expand Down Expand Up @@ -163,6 +165,27 @@ private static Optional<String> _getDeployedBranch(@NotNull File pServerConfigFi
return Optional.empty();
}

/**
* @param pSspFacade ISSPFacade that contains the methods for interacting with the SSP
* @param pSystemDetails ISSPSystemDetails that contain the information about the selected SSP system
* @param pCurrentCredentials JWT containing the credentials for authenticating with the SSP
* @return the git repository to use for cloning
*/
private static String _getGitProject(@NotNull ISSPFacade pSspFacade, @NotNull ISSPSystemDetails pSystemDetails, @NotNull DecodedJWT pCurrentCredentials)
{
Map<String, String> configMap = null;
try
{
configMap = pSspFacade.getConfigMap(pCurrentCredentials.getSubject(), pCurrentCredentials, pSystemDetails);
}
catch (UnirestException | AditoSSPException pE)
{
logger.log(Level.WARNING, pE, () -> SSPCheckoutProjectWizardIterator.getMessage(SSPCheckoutExecutor.class, "TXT.SSPCheckoutExecutor.update.error.configMap",
ExceptionUtils.getStackTrace(pE)));
}
return Optional.ofNullable(configMap).map(pConfigMap -> pConfigMap.get("linked_git_project")).orElseGet(pSystemDetails::getGitRepoUrl);
}

private static boolean _startTunnels(@NotNull String pTunnelConfigContents)
{
ISSHTunnelProvider tunnelProvider = Lookup.getDefault().lookup(ISSHTunnelProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TXT.SSPCheckoutExecutor.update.write.serverConfig=writing server config
TXT.SSPCheckoutExecutor.update.fetch.tunnelConfig=fetching tunnel config
TXT.SSPCheckoutExecutor.update.fetch.tunnelConfig.error=Cloudplugin: Encountered a problem while trying to fetch the tunnel config.\n{0}
TXT.SSPCheckoutExecutor.update.write.tunnelConfig=writing tunnel config
TXT.SSPCheckoutExecutor.update.error.configMap=Cloudplugin: Encountered a problem while trying to retrieve the config map.\n{0}
TXT.SSPCheckoutExecutor.update.error.serverConfig=Cloudplugin: Encountered a problem while trying to write the server config.\n{0}
TXT.SSPCheckoutExecutor.update.error.tunnelConfig=Cloudplugin: Encountered a problem while trying to write the tunnel config.\n{0}
TXT.SSPCheckoutExecutor.update.error.serverAddress=CloudPlugin: Could not parse URL of the serverAddress\n{0}
Expand Down

0 comments on commit 66959c6

Please sign in to comment.