Skip to content

Commit

Permalink
create new ApiClient instance for each AppCenterManager instance
Browse files Browse the repository at this point in the history
  • Loading branch information
akamarouski committed Nov 11, 2023
1 parent d77ee46 commit 7cb9a7d
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/zebrunner/carina/appcenter/AppCenterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
public class AppCenterManager implements IArtifactManager {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final Map<String, LazyInitializer<AppCenterApp>> APP_INFO_MAP = new ConcurrentHashMap<>();
private static final ThreadLocal<ApiClient> API_CLIENT = ThreadLocal.withInitial(() -> new ApiClient().addDefaultHeader("x-api-token",
Configuration.getRequired(AppCenterConfiguration.Parameter.APPCENTER_TOKEN,
StandardConfigurationOption.DECRYPT)));
private final ApiClient apiClient;
private static final String INVALID_LINK_MESSAGE = "AppCenter url is not correct: %s%n It should be like: %s.";
private static final String VALID_LINK = "appcenter://appName/platformName/buildType/version";

Expand All @@ -73,10 +71,6 @@ public class AppCenterManager implements IArtifactManager {
private static final String BUILD_TYPE = "buildType";
private static final String APP_VERSION = "version";

private AppCenterManager() {
// hide
}

/**
* Pattern for link like {@code appcenter://appName/platformName/buildType/version}
*/
Expand All @@ -86,6 +80,12 @@ private AppCenterManager() {
+ "(?<" + BUILD_TYPE + ">[a-zA-Z-0-9][^\\/]*)\\/"
+ "(?<" + APP_VERSION + ">[a-zA-Z-0-9][^\\/]*)");

private AppCenterManager() {
apiClient = new ApiClient().addDefaultHeader("x-api-token",
Configuration.getRequired(AppCenterConfiguration.Parameter.APPCENTER_TOKEN,
StandardConfigurationOption.DECRYPT));
}

/**
* Get new instance of {@link AppCenterManager}
*
Expand Down Expand Up @@ -153,7 +153,7 @@ protected AppCenterApp initialize() throws ConcurrentException {
String buildType = matcher.group(BUILD_TYPE);
String version = matcher.group(APP_VERSION);

Map<String, App> appMap = new AccountApi(API_CLIENT.get())
Map<String, App> appMap = new AccountApi(apiClient)
.appsList(null)
.stream()
.filter(a -> StringUtils.equalsIgnoreCase(platformName, a.getOs().toString()) &&
Expand All @@ -178,7 +178,7 @@ protected AppCenterApp initialize() throws ConcurrentException {
String name = entry.getKey();
App app = entry.getValue();

List<ReleasesAvailableToTester> retrieveList = new DistributeApi(API_CLIENT.get())
List<ReleasesAvailableToTester> retrieveList = new DistributeApi(apiClient)
.releasesList(app.getOwner().getName(), name, true,
"tester", null,
null);
Expand All @@ -197,7 +197,7 @@ protected AppCenterApp initialize() throws ConcurrentException {
appCenterApp.setVersion(build.getShortVersion());
appCenterApp.setBuild(build.getVersion());

ReleaseDetailsResponse appBuild = new DistributeApi(API_CLIENT.get()).releasesGetLatestByUser(
ReleaseDetailsResponse appBuild = new DistributeApi(apiClient).releasesGetLatestByUser(
String.valueOf(latestBuildNumber),
app.getOwner().getName(), name, null, null);

Expand Down Expand Up @@ -343,8 +343,8 @@ private static boolean downloadBuild(String fileName, URL downloadLink) throws I
* @param appUpdatedAt passing in of a backup date value if the app we look at doesn't have a build associated to it.
* @return the date value to be used in sorting.
*/
private static String getLatestBuildDate(String app, String appUpdatedAt, String ownerName) {
List<ReleasesAvailableToTester> retrieveList = new DistributeApi(API_CLIENT.get()).releasesList(ownerName, app,
private String getLatestBuildDate(String app, String appUpdatedAt, String ownerName) {
List<ReleasesAvailableToTester> retrieveList = new DistributeApi(apiClient).releasesList(ownerName, app,
true, "tester", null, null);
if (!retrieveList.isEmpty()) {
return retrieveList.get(0).getUploadedAt();
Expand Down

0 comments on commit 7cb9a7d

Please sign in to comment.