Skip to content
Open
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
17 changes: 10 additions & 7 deletions server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.openvsx.eclipse.EclipseService;
import org.eclipse.openvsx.entities.*;
import org.eclipse.openvsx.json.*;
import org.eclipse.openvsx.migration.MigrationsProperties;
import org.eclipse.openvsx.publish.ExtensionVersionIntegrityService;
import org.eclipse.openvsx.publish.PublishingConfig;
import org.eclipse.openvsx.repositories.RepositoryService;
Expand All @@ -62,6 +63,7 @@
import org.eclipse.openvsx.util.VersionService;
import org.eclipse.openvsx.util.auth.AuthenticatedUser;
import org.eclipse.openvsx.util.auth.LoggedInAuthentication;
import org.eclipse.openvsx.web.WebUiProperties;

import static org.eclipse.openvsx.cache.CacheService.*;
import static org.eclipse.openvsx.entities.FileResource.*;
Expand Down Expand Up @@ -89,6 +91,8 @@ public class LocalRegistryService implements IExtensionRegistry {
private final SimilarityCheckService similarityCheckService;
private final PublishingConfig publishingConfig;
private final TrustedPublishingConfig trustedPublishingConfig;
private final MigrationsProperties migrationsProperties;
private final WebUiProperties webUi;

/**
* How far behind the present the changes feed stops, see {@link #visibleUntil}.
Expand All @@ -111,6 +115,8 @@ public LocalRegistryService(
@Nullable SimilarityCheckService similarityCheckService,
PublishingConfig publishingConfig,
TrustedPublishingConfig trustedPublishingConfig,
MigrationsProperties migrationsProperties,
WebUiProperties webUi,
@Value("${ovsx.changes-feed.lag:PT30S}") Duration changesFeedLag
) {
this.entityManager = entityManager;
Expand All @@ -128,15 +134,11 @@ public LocalRegistryService(
this.similarityCheckService = similarityCheckService;
this.publishingConfig = publishingConfig;
this.trustedPublishingConfig = trustedPublishingConfig;
this.migrationsProperties = migrationsProperties;
this.webUi = webUi;
this.changesFeedLag = changesFeedLag;
}

@Value("${ovsx.webui.url:}")
String webuiUrl;

@Value("${ovsx.registry.version:}")
String registryVersion;

@Override
public NamespaceJson getNamespace(String namespaceName) {
return getNamespace(namespaceName, false);
Expand Down Expand Up @@ -1330,7 +1332,7 @@ private ExtensionReplacementJson toReplacementJson(
return null;
}

var baseUrl = webui ? webuiUrl : UrlUtil.getBaseUrl();
var baseUrl = webui ? webUi.getUrl() : UrlUtil.getBaseUrl();
var segments = new String[] {
webui ? "extension" : "api",
replacement.getExtension().getNamespace().getName(),
Expand Down Expand Up @@ -1377,6 +1379,7 @@ public String getPublicKey(String publicId) {

@Override
public RegistryVersionJson getRegistryVersion() {
var registryVersion = migrationsProperties.getRegistryVersion();
if (StringUtils.isEmpty(registryVersion)) {
throw new NotFoundException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;

import org.eclipse.openvsx.mirror.MirrorConfig;

@Configuration
public class RestTemplateConfig {

Expand Down Expand Up @@ -154,11 +156,11 @@ public RestTemplate backgroundNonRedirectingRestTemplate(

@Bean
public RestTemplate vsCodeIdRestTemplate(
@Value("${ovsx.data.mirror.enabled:false}") boolean mirrorModeEnabled,
MirrorConfig mirrorConfig,
RestTemplate restTemplate,
RestTemplate backgroundRestTemplate
) {
return mirrorModeEnabled ? backgroundRestTemplate : restTemplate;
return mirrorConfig.isEnabled() ? backgroundRestTemplate : restTemplate;
}

private HttpClientBuilder createHttpClientBuilder(HttpConnPoolConfig httpConnPoolConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import org.eclipse.openvsx.mirror.MirrorConfig;

@Configuration
public class AccessTokenConfig {

private final MirrorConfig mirrorConfig;

public AccessTokenConfig(MirrorConfig mirrorConfig) {
this.mirrorConfig = mirrorConfig;
}

/**
* The token prefix to use when generating a new access token.
* <p>
Expand Down Expand Up @@ -116,9 +125,6 @@ public class AccessTokenConfig {
@Value("${ovsx.access-token.token-hash-salt:}")
private String tokenHashSalt;

@Value("${ovsx.data.mirror.enabled:false}")
private boolean mirrorEnabled;

public @NonNull String getPrefix() {
return this.prefix;
}
Expand Down Expand Up @@ -173,7 +179,7 @@ public boolean hasNotificationSchedule() {

@PostConstruct
public void validate() {
if (isTokenExpiryEnabled() && mirrorEnabled) {
if (isTokenExpiryEnabled() && mirrorConfig.isEnabled()) {
throw new IllegalArgumentException(
"ovsx.access-token.expiration can not be enabled when mirror mode is active, got: " + expiration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.openvsx.util.TimeUtil;
import org.eclipse.openvsx.util.UrlUtil;
import org.eclipse.openvsx.util.VersionService;
import org.eclipse.openvsx.web.WebUiProperties;

import static org.eclipse.openvsx.adapter.ExtensionQueryParam.*;
import static org.eclipse.openvsx.adapter.ExtensionQueryParam.Criterion.*;
Expand All @@ -68,6 +69,7 @@ public class LocalVSCodeService implements IVSCodeService {
private final ExtensionVersionIntegrityService integrityService;
private final WebResourceService webResources;
private final CacheService cache;
private final WebUiProperties webUi;

private final Map<String, String> assets = Map.of(
FILE_VSIX,
Expand All @@ -87,9 +89,6 @@ public class LocalVSCodeService implements IVSCodeService {
FILE_SIGNATURE,
DOWNLOAD_SIG);

@Value("${ovsx.webui.url:}")
String webuiUrl;

// See RepositoryService.findActiveExtensionVersions / ExtensionVersionJooqRepository -
// caps how many of an extension's active pre-release versions the version listing below
// fetches per extensionQuery request; regular releases are never capped. A negative value
Expand All @@ -105,7 +104,8 @@ public LocalVSCodeService(
StorageUtilService storageUtil,
ExtensionVersionIntegrityService integrityService,
WebResourceService webResources,
CacheService cache
CacheService cache,
WebUiProperties webUi
) {
this.repositories = repositories;
this.versions = versions;
Expand All @@ -114,6 +114,7 @@ public LocalVSCodeService(
this.integrityService = integrityService;
this.webResources = webResources;
this.cache = cache;
this.webUi = webUi;
}

@Override
Expand Down Expand Up @@ -466,7 +467,11 @@ public String getItemUrl(String namespaceName, String extensionName) {
throw new NotFoundException();
}

return UrlUtil.createApiUrl(webuiUrl, "extension", extension.getNamespace().getName(), extension.getName());
return UrlUtil.createApiUrl(
webUi.getUrl(),
"extension",
extension.getNamespace().getName(),
extension.getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.eclipse.openvsx.UrlConfigService;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.migration.HandlerJobRequest;
import org.eclipse.openvsx.migration.MigrationsProperties;
import org.eclipse.openvsx.mirror.MirrorConfig;
import org.eclipse.openvsx.util.NamingUtil;
import org.eclipse.openvsx.util.TimeUtil;
import org.eclipse.openvsx.util.UUIDService;
Expand All @@ -39,36 +41,36 @@ public class VSCodeIdService {
private final UrlConfigService urlConfigService;
private final JobRequestScheduler scheduler;
private final UUIDService uuidService;

@Value("${ovsx.data.mirror.enabled:false}")
boolean mirrorEnabled;
private final MirrorConfig mirrorConfig;
private final MigrationsProperties migrationsProperties;

@Value("${ovsx.vscode.upstream.update-on-start:false}")
boolean updateOnStart;

@Value("${ovsx.migrations.delay.seconds:0}")
long delay;

public VSCodeIdService(
RestTemplate vsCodeIdRestTemplate,
UrlConfigService urlConfigService,
JobRequestScheduler scheduler,
UUIDService uuidService
UUIDService uuidService,
MirrorConfig mirrorConfig,
MigrationsProperties migrationsProperties
) {
this.vsCodeIdRestTemplate = vsCodeIdRestTemplate;
this.urlConfigService = urlConfigService;
this.scheduler = scheduler;
this.uuidService = uuidService;
this.mirrorConfig = mirrorConfig;
this.migrationsProperties = migrationsProperties;
}

@EventListener
public void applicationStarted(ApplicationStartedEvent event) {
if (mirrorEnabled) {
if (mirrorConfig.isEnabled()) {
return;
}
if (updateOnStart) {
scheduler.schedule(
TimeUtil.getCurrentUTC().plusSeconds(delay),
TimeUtil.getCurrentUTC().plusSeconds(migrationsProperties.getDelaySeconds()),
new HandlerJobRequest<>(VSCodeIdDailyUpdateJobRequestHandler.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.eclipse.openvsx.cache.CacheService;
import org.eclipse.openvsx.entities.UserData;
import org.eclipse.openvsx.migration.HandlerJobRequest;
import org.eclipse.openvsx.migration.MigrationsProperties;
import org.eclipse.openvsx.mirror.MirrorConfig;
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.search.SearchUtilService;
import org.eclipse.openvsx.util.ExtensionId;
Expand All @@ -52,9 +54,8 @@ public class ExtensionControlService {
private final EntityManager entityManager;
private final SearchUtilService search;
private final CacheService cache;

@Value("${ovsx.data.mirror.enabled:false}")
boolean mirrorEnabled;
private final MirrorConfig mirrorConfig;
private final MigrationsProperties migrationsProperties;

@Value("${ovsx.extension-control.enabled:true}")
boolean enabled;
Expand All @@ -65,31 +66,32 @@ public class ExtensionControlService {
@Value("${ovsx.extension-control.update-on-start:false}")
boolean updateOnStart;

@Value("${ovsx.migrations.delay.seconds:0}")
long delay;

public ExtensionControlService(
JobRequestScheduler scheduler,
RepositoryService repositories,
EntityManager entityManager,
SearchUtilService search,
CacheService cache
CacheService cache,
MirrorConfig mirrorConfig,
MigrationsProperties migrationsProperties
) {
this.scheduler = scheduler;
this.repositories = repositories;
this.entityManager = entityManager;
this.search = search;
this.cache = cache;
this.mirrorConfig = mirrorConfig;
this.migrationsProperties = migrationsProperties;
}

@EventListener
public void applicationStarted(ApplicationStartedEvent event) {
if (!enabled || mirrorEnabled) {
if (!enabled || mirrorConfig.isEnabled()) {
scheduler.deleteRecurringJob("UpdateExtensionControl");
} else {
if (updateOnStart) {
scheduler.schedule(
TimeUtil.getCurrentUTC().plusSeconds(delay),
TimeUtil.getCurrentUTC().plusSeconds(migrationsProperties.getDelaySeconds()),
new HandlerJobRequest<>(ExtensionControlJobRequestHandler.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import org.jobrunr.scheduling.JobRequestScheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import org.eclipse.openvsx.admin.RemoveFileJobRequest;
import org.eclipse.openvsx.entities.ExtensionVersion;
import org.eclipse.openvsx.entities.FileResource;
import org.eclipse.openvsx.publish.ExtensionVersionIntegrityService;
import org.eclipse.openvsx.repositories.RepositoryService;

import static org.eclipse.openvsx.entities.FileResource.DOWNLOAD_SIG;
Expand All @@ -39,23 +39,24 @@ public class GenerateKeyPairJobRequestHandler implements JobRequestHandler<Handl
private final RepositoryService repositories;
private final JobRequestScheduler scheduler;
private final GenerateKeyPairJobService service;

@Value("${ovsx.integrity.key-pair:}")
String keyPairMode;
private final ExtensionVersionIntegrityService integrityService;

public GenerateKeyPairJobRequestHandler(
RepositoryService repositories,
JobRequestScheduler scheduler,
GenerateKeyPairJobService service
GenerateKeyPairJobService service,
ExtensionVersionIntegrityService integrityService
) {
this.repositories = repositories;
this.scheduler = scheduler;
this.service = service;
this.integrityService = integrityService;
}

@Override
@Job(retries = 0)
public void run(HandlerJobRequest<?> jobRequest) throws Exception {
var keyPairMode = integrityService.getKeyPairMode();
logger.info("Starting signature key-pair generation in mode {}", keyPairMode);

switch (keyPairMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import org.eclipse.openvsx.mirror.MirrorConfig;

@Component
public class MigrationScheduler implements JobRequestHandler<HandlerJobRequest<?>> {

Expand All @@ -26,9 +28,7 @@ public class MigrationScheduler implements JobRequestHandler<HandlerJobRequest<?

private final OrphanNamespaceMigration orphanNamespaceMigration;
private final JobRequestScheduler scheduler;

@Value("${ovsx.data.mirror.enabled:false}")
boolean mirrorEnabled;
private final MirrorConfig mirrorConfig;

// Default matches JobRunr's Cron.every15minutes(). Configurable so a deployment that's
// bothered by migration-item bursts crowding out real-time jobs (see
Expand All @@ -38,17 +38,19 @@ public class MigrationScheduler implements JobRequestHandler<HandlerJobRequest<?

public MigrationScheduler(
OrphanNamespaceMigration orphanNamespaceMigration,
JobRequestScheduler scheduler
JobRequestScheduler scheduler,
MirrorConfig mirrorConfig
) {
this.orphanNamespaceMigration = orphanNamespaceMigration;
this.scheduler = scheduler;
this.mirrorConfig = mirrorConfig;
}

@Override
@Job(name = "Schedule migrations", retries = 0)
public void run(HandlerJobRequest<?> jobRequest) throws Exception {
orphanNamespaceMigration.fixOrphanNamespaces();
if (!mirrorEnabled) {
if (!mirrorConfig.isEnabled()) {
scheduler.enqueue(new HandlerJobRequest<>(GenerateKeyPairJobRequestHandler.class));
}

Expand Down
Loading