Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private AzureSpringIdentifier() {
// b2c: for AAD B2C
private static final Logger LOGGER = LoggerFactory.getLogger(AzureSpringIdentifier.class);
public static final String VERSION = getVersion();
public static final int MAX_VERSION_LENGTH = 12;
public static final String AZURE_SPRING_APP_CONFIG = "az-sp-cfg/" + VERSION;
public static final String AZURE_SPRING_EVENT_HUBS = "az-sp-eh/" + VERSION;

Expand Down Expand Up @@ -92,9 +93,24 @@ private static String getVersion() {
Properties properties = PropertiesLoaderUtils.loadProperties(
new ClassPathResource("azure-spring-identifier.properties"));
version = properties.getProperty("version");
//Add this logic to avoid creating app id failed
version = formatVersion(version);
} catch (IOException e) {
LOGGER.warn("Can not get version.");
}
return version;
}

static String formatVersion(String version) {
if (version.length() > MAX_VERSION_LENGTH) {
if (version.contains("beta")) {
version = version.replace("beta", "b");
} else if (version.contains("alpha")) {
version = version.replace("alpha", "a");
} else {
throw new RuntimeException("version is too long to create application id");
}
}
return version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.core.implementation.util;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class AzureSpringIdentifierTests {

@Test
void testFormatVersion() {
Assertions.assertEquals(AzureSpringIdentifier.formatVersion("4.10.0"), "4.10.0");
Assertions.assertEquals(AzureSpringIdentifier.formatVersion("4.9.0-beta.1"), "4.9.0-beta.1");
Assertions.assertEquals(AzureSpringIdentifier.formatVersion("4.10.0-beta.1"), "4.10.0-b.1");
Assertions.assertEquals(AzureSpringIdentifier.formatVersion("4.10.0-alpha.1"), "4.10.0-a.1");
Assertions.assertThrows(RuntimeException.class, () -> AzureSpringIdentifier.formatVersion("4.10.0-SNAPSHOT"));
}

}