From 712ada4bc8621c2e158a5db9c443331f54509b0d Mon Sep 17 00:00:00 2001 From: Madhavan Sridharan Date: Thu, 28 Sep 2023 18:46:45 -0400 Subject: [PATCH] Remove ApiLocator as it got removed in Astra SDK Java 0.6.11 --- .../astra/cli/config/AstraCliConfiguration.java | 6 +++--- .../com/dtsx/astra/cli/config/ConfigCreateCmd.java | 4 ++-- .../com/dtsx/astra/cli/config/ServiceConfig.java | 4 ++-- .../dtsx/astra/cli/core/AbstractConnectedCmd.java | 4 ++-- .../java/com/dtsx/astra/cli/core/CliContext.java | 14 +++++++------- .../java/com/dtsx/astra/cli/core/TokenOptions.java | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/dtsx/astra/cli/config/AstraCliConfiguration.java b/src/main/java/com/dtsx/astra/cli/config/AstraCliConfiguration.java index 7c57e63..5ff82c4 100644 --- a/src/main/java/com/dtsx/astra/cli/config/AstraCliConfiguration.java +++ b/src/main/java/com/dtsx/astra/cli/config/AstraCliConfiguration.java @@ -21,7 +21,7 @@ */ import com.dtsx.astra.cli.core.out.LoggerShell; -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; import com.dtsx.astra.sdk.utils.AstraRc; import java.io.File; @@ -288,9 +288,9 @@ public String renderSection(String sectionName) { * @param token * token to authenticate */ - public void createSectionWithToken(String sectionName, String token, ApiLocator.AstraEnvironment env) { + public void createSectionWithToken(String sectionName, String token, AstraEnvironment env) { updateSectionKey(sectionName, AstraRc.ASTRA_DB_APPLICATION_TOKEN, token); - if (ApiLocator.AstraEnvironment.PROD != env) { + if (AstraEnvironment.PROD != env) { updateSectionKey(sectionName, KEY_ENV, env.name()); } if (!isSectionExists(ASTRARC_DEFAULT)) diff --git a/src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java b/src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java index 43f3e65..4cf6479 100644 --- a/src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java +++ b/src/main/java/com/dtsx/astra/cli/config/ConfigCreateCmd.java @@ -27,7 +27,7 @@ import com.dtsx.astra.cli.core.out.AstraCliConsole; import com.dtsx.astra.sdk.AstraDevopsApiClient; import com.dtsx.astra.sdk.org.domain.Organization; -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; import com.github.rvesse.airline.annotations.Arguments; import com.github.rvesse.airline.annotations.Command; import com.github.rvesse.airline.annotations.Option; @@ -50,7 +50,7 @@ public class ConfigCreateCmd extends AbstractCmd { /** To use Cli on non production environment. */ @Option(name = { "-e", "--env" }, title = "Environment", description = "Environment to use for this section.") - protected ApiLocator.AstraEnvironment env = ApiLocator.AstraEnvironment.PROD; + protected AstraEnvironment env = AstraEnvironment.PROD; /** {@inheritDoc} */ @Override diff --git a/src/main/java/com/dtsx/astra/cli/config/ServiceConfig.java b/src/main/java/com/dtsx/astra/cli/config/ServiceConfig.java index 5bc34e8..ab54c02 100644 --- a/src/main/java/com/dtsx/astra/cli/config/ServiceConfig.java +++ b/src/main/java/com/dtsx/astra/cli/config/ServiceConfig.java @@ -26,7 +26,7 @@ import com.dtsx.astra.cli.core.out.AstraCliConsole; import com.dtsx.astra.cli.core.out.ShellTable; import com.dtsx.astra.cli.core.out.StringBuilderAnsi; -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; import com.dtsx.astra.sdk.utils.AstraRc; import java.util.HashMap; @@ -95,7 +95,7 @@ public static void listConfigurations() { if (isMultiEnv) { rf.put(COLUMN_ENV, Optional.ofNullable(sections.get(section.getKey()) .get(AstraCliConfiguration.KEY_ENV)) - .orElse(ApiLocator.AstraEnvironment.PROD.name())); + .orElse(AstraEnvironment.PROD.name())); } sht.getCellValues().add(rf); } diff --git a/src/main/java/com/dtsx/astra/cli/core/AbstractConnectedCmd.java b/src/main/java/com/dtsx/astra/cli/core/AbstractConnectedCmd.java index b2ec96c..422e887 100644 --- a/src/main/java/com/dtsx/astra/cli/core/AbstractConnectedCmd.java +++ b/src/main/java/com/dtsx/astra/cli/core/AbstractConnectedCmd.java @@ -22,7 +22,7 @@ import com.dtsx.astra.cli.config.AstraCliConfiguration; import com.dtsx.astra.cli.core.out.OutputFormat; -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; import com.github.rvesse.airline.annotations.Option; import java.util.Locale; @@ -43,7 +43,7 @@ public abstract class AbstractConnectedCmd extends AbstractCmd { * Astra Environment, could be DEV or TEST instead of PROD. */ @Option(name = { "--env" }, title = "Environment", description = "Astra Environment to use") - protected ApiLocator.AstraEnvironment env = ApiLocator.AstraEnvironment.PROD; + protected AstraEnvironment env = AstraEnvironment.PROD; /** Section. */ @Option(name = { "-conf","--config" }, diff --git a/src/main/java/com/dtsx/astra/cli/core/CliContext.java b/src/main/java/com/dtsx/astra/cli/core/CliContext.java index ea11ae3..b901fda 100644 --- a/src/main/java/com/dtsx/astra/cli/core/CliContext.java +++ b/src/main/java/com/dtsx/astra/cli/core/CliContext.java @@ -30,7 +30,7 @@ import com.dtsx.astra.sdk.db.AstraDbClient; import com.dtsx.astra.sdk.org.domain.Organization; import com.dtsx.astra.sdk.streaming.AstraStreamingClient; -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; import com.dtsx.astra.sdk.utils.AstraRc; import org.apache.commons.lang3.StringUtils; @@ -148,9 +148,9 @@ private void loadCredentialsFromSection() astraConfig.getSection(tokenOptions.section()) .containsKey(AstraRc.ASTRA_DB_APPLICATION_TOKEN)) { LoggerShell.debug("Configuration: Using token in section %s".formatted(tokenOptions.section())); - ApiLocator.AstraEnvironment targetEnv = ApiLocator.AstraEnvironment.PROD; + AstraEnvironment targetEnv = AstraEnvironment.PROD; if (astraConfig.getSection(tokenOptions.section()).containsKey(AstraCliConfiguration.KEY_ENV)) { - targetEnv = ApiLocator.AstraEnvironment.valueOf( + targetEnv = AstraEnvironment.valueOf( astraConfig.getSection(tokenOptions.section()).get(AstraCliConfiguration.KEY_ENV)); LoggerShell.debug("Configuration: Targeting env %s".formatted(targetEnv)); } @@ -202,7 +202,7 @@ public String getToken() * @throws TokenNotFoundException * token as not been found */ - public ApiLocator.AstraEnvironment getAstraEnvironment() + public AstraEnvironment getAstraEnvironment() throws TokenNotFoundException { if (tokenOptions == null) { return null; @@ -228,7 +228,7 @@ public AstraCliConfiguration getConfiguration() { */ public AstraDevopsApiClient getApiDevops() { AstraDevopsApiClient devopsApiClient = new AstraDevopsApiClient(getToken(), getAstraEnvironment()); - if (!getAstraEnvironment().equals(ApiLocator.AstraEnvironment.PROD)) { + if (!getAstraEnvironment().equals(AstraEnvironment.PROD)) { LoggerShell.info("You are using a non-production environment '%s' ".formatted(getAstraEnvironment())); } validateDevopsClientConnection(devopsApiClient); @@ -243,7 +243,7 @@ public AstraDevopsApiClient getApiDevops() { * @param env * target environment */ - public void validateCredentials(String token, ApiLocator.AstraEnvironment env) { + public void validateCredentials(String token, AstraEnvironment env) { validateDevopsClientConnection(new AstraDevopsApiClient(token, env)); } @@ -253,7 +253,7 @@ public void validateCredentials(String token, ApiLocator.AstraEnvironment env) { private void validateDevopsClientConnection(AstraDevopsApiClient client) { Organization org = client.getOrganization(); if (org.getId() == null) { - if (!client.getEnvironment().equals(ApiLocator.AstraEnvironment.PROD)) { + if (!client.getEnvironment().equals(AstraEnvironment.PROD)) { AstraCliConsole.outputError(ExitCode.CANNOT_CONNECT, "Make sure token targets proper environment '%s'".formatted(client.getEnvironment())); } diff --git a/src/main/java/com/dtsx/astra/cli/core/TokenOptions.java b/src/main/java/com/dtsx/astra/cli/core/TokenOptions.java index 053237e..664df91 100644 --- a/src/main/java/com/dtsx/astra/cli/core/TokenOptions.java +++ b/src/main/java/com/dtsx/astra/cli/core/TokenOptions.java @@ -20,7 +20,7 @@ * #L% */ -import com.dtsx.astra.sdk.utils.ApiLocator; +import com.dtsx.astra.sdk.utils.AstraEnvironment; /** * Options when you need a token. @@ -28,5 +28,5 @@ public record TokenOptions( String token, // Token Value String section, //Section Value - ApiLocator.AstraEnvironment env //Target environment. + AstraEnvironment env //Target environment. ) {}