Skip to content

Commit

Permalink
Check for snapshot if snapshot build
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Oct 7, 2024
1 parent 8a11171 commit 2fa838d
Showing 1 changed file with 3 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
*/
class InstallPluginCommand extends EnvironmentAwareCommand {

private static final String PROPERTY_STAGING_ID = "opensearch.plugins.staging";

// exit codes for install
/** A plugin with the same name is already installed. */
static final int PLUGIN_EXISTS = 1;
Expand Down Expand Up @@ -307,14 +305,7 @@ void execute(Terminal terminal, List<String> pluginIds, boolean isBatch, Environ
private Path download(Terminal terminal, String pluginId, Path tmpDir, boolean isBatch) throws Exception {

if (OFFICIAL_PLUGINS.contains(pluginId)) {
final String url = getOpenSearchUrl(
terminal,
getStagingHash(),
Version.CURRENT,
isSnapshot(),
pluginId,
Platforms.PLATFORM_NAME
);
final String url = getOpenSearchUrl(terminal, Version.CURRENT, isSnapshot(), pluginId, Platforms.PLATFORM_NAME);
terminal.println("-> Downloading " + pluginId + " from opensearch");
return downloadAndValidate(terminal, url, tmpDir, true, isBatch);
}
Expand All @@ -341,39 +332,21 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir, boolean i
return downloadZip(terminal, pluginId, tmpDir, isBatch);
}

// pkg private so tests can override
String getStagingHash() {
return System.getProperty(PROPERTY_STAGING_ID);
}

boolean isSnapshot() {
return Build.CURRENT.isSnapshot();
}

/** Returns the url for an official opensearch plugin. */
private String getOpenSearchUrl(
final Terminal terminal,
final String stagingHash,
final Version version,
final boolean isSnapshot,
final String pluginId,
final String platform
) throws IOException, UserException {
final String baseUrl;
if (isSnapshot && stagingHash == null) {
throw new UserException(
ExitCodes.CONFIG,
"attempted to install release build of official plugin on snapshot build of OpenSearch"
);
}
if (stagingHash != null) {
baseUrl = String.format(
Locale.ROOT,
"https://artifacts.opensearch.org/snapshots/plugins/%s/%s-%s",
pluginId,
version,
stagingHash
);
if (isSnapshot) {
baseUrl = String.format(Locale.ROOT, "https://artifacts.opensearch.org/snapshots/plugins/%s/%s", pluginId, version);
} else {
baseUrl = String.format(
Locale.ROOT,
Expand Down

0 comments on commit 2fa838d

Please sign in to comment.