chore: Package registry refactoring

This commit is contained in:
Robin Shen 2025-10-08 20:36:37 +08:00
parent 25e3991ba9
commit 0a5860d153
28 changed files with 127 additions and 124 deletions

View File

@ -630,7 +630,6 @@ public class CoreModule extends AbstractPluginModule {
contributeFromPackage(LogInstruction.class, LogInstruction.class); contributeFromPackage(LogInstruction.class, LogInstruction.class);
contribute(CodeProblemContribution.class, (build, blobPath, reportName) -> newArrayList()); contribute(CodeProblemContribution.class, (build, blobPath, reportName) -> newArrayList());
contribute(LineCoverageContribution.class, (build, blobPath, reportName) -> new HashMap<>()); contribute(LineCoverageContribution.class, (build, blobPath, reportName) -> new HashMap<>());

View File

@ -33,26 +33,20 @@ import io.onedev.server.security.ExceptionHandleFilter;
@Singleton @Singleton
public class PackFilter extends ExceptionHandleFilter { public class PackFilter extends ExceptionHandleFilter {
private final AccessTokenService accessTokenService; @Inject
private AccessTokenService accessTokenService;
private final ProjectService projectService;
private final JobService jobService;
private final SessionService sessionService;
private final Set<PackService> packServices;
@Inject @Inject
public PackFilter(AccessTokenService accessTokenService, ProjectService projectService, private ProjectService projectService;
JobService jobService, SessionService sessionService,
Set<PackService> packServices) { @Inject
this.accessTokenService = accessTokenService; private JobService jobService;
this.projectService = projectService;
this.jobService = jobService; @Inject
this.sessionService = sessionService; private SessionService sessionService;
this.packServices = packServices;
} @Inject
private Set<PackHandler> packHandlers;
@Sessional @Sessional
@Override @Override
@ -61,13 +55,13 @@ public class PackFilter extends ExceptionHandleFilter {
var httpResponse = (HttpServletResponse) response; var httpResponse = (HttpServletResponse) response;
var pathSegments = Splitter.on('/').trimResults().omitEmptyStrings() var pathSegments = Splitter.on('/').trimResults().omitEmptyStrings()
.splitToList(httpRequest.getRequestURI()); .splitToList(httpRequest.getRequestURI());
for (var packService: packServices) { for (var packHandler: packHandlers) {
var serviceMark = "~" + packService.getServiceId(); var handlerMark = "~" + packHandler.getHandlerId();
if (pathSegments.contains(serviceMark)) { if (pathSegments.contains(handlerMark)) {
pathSegments = packService.normalize(pathSegments); pathSegments = packHandler.normalize(pathSegments);
var serviceMarkIndex = pathSegments.indexOf(serviceMark); var handlerMarkIndex = pathSegments.indexOf(handlerMark);
request.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, Boolean.FALSE); request.setAttribute(DefaultSubjectContext.SESSION_CREATION_ENABLED, Boolean.FALSE);
var projectPath = Joiner.on('/').join(pathSegments.subList(0, serviceMarkIndex)); var projectPath = Joiner.on('/').join(pathSegments.subList(0, handlerMarkIndex));
var projectId = sessionService.call(() -> { var projectId = sessionService.call(() -> {
var project = projectService.findByPath(projectPath); var project = projectService.findByPath(projectPath);
if (project != null) if (project != null)
@ -77,7 +71,7 @@ public class PackFilter extends ExceptionHandleFilter {
}); });
Long buildId = null; Long buildId = null;
var apiKey = packService.getApiKey(httpRequest); var apiKey = packHandler.getApiKey(httpRequest);
if (apiKey != null) { if (apiKey != null) {
var colonIndex = apiKey.indexOf(':'); var colonIndex = apiKey.indexOf(':');
String jobToken; String jobToken;
@ -121,8 +115,8 @@ public class PackFilter extends ExceptionHandleFilter {
} }
} }
packService.service(httpRequest, httpResponse, projectId, buildId, packHandler.handle(httpRequest, httpResponse, projectId, buildId,
pathSegments.subList(serviceMarkIndex + 1, pathSegments.size())); pathSegments.subList(handlerMarkIndex + 1, pathSegments.size()));
return false; return false;
} }
} }

View File

@ -8,11 +8,11 @@ import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
@ExtensionPoint @ExtensionPoint
public interface PackService { public interface PackHandler {
String getServiceId(); String getHandlerId();
void service(HttpServletRequest request, HttpServletResponse response, void handle(HttpServletRequest request, HttpServletResponse response,
Long projectId, @Nullable Long buildId, List<String> pathSegments); Long projectId, @Nullable Long buildId, List<String> pathSegments);
@Nullable @Nullable

View File

@ -64,10 +64,15 @@ public class ContainerAuthenticationFilter extends ExceptionHandleFilter {
} }
} else if (authHeader.toLowerCase().startsWith("bearer ")) { } else if (authHeader.toLowerCase().startsWith("bearer ")) {
var authValue = substringAfter(authHeader, " "); var authValue = substringAfter(authHeader, " ");
String bearerToken;
if (authValue.contains(":")) {
var jobContext = jobService.getJobContext(substringBefore(authValue, ":"), false); var jobContext = jobService.getJobContext(substringBefore(authValue, ":"), false);
if (jobContext != null) if (jobContext != null)
request.setAttribute(ATTR_BUILD_ID, jobContext.getBuildId()); request.setAttribute(ATTR_BUILD_ID, jobContext.getBuildId());
var bearerToken = substringAfter(authValue, ":"); bearerToken = substringAfter(authValue, ":");
} else {
bearerToken = authValue;
}
var accessToken = accessTokenService.findByValue(bearerToken); var accessToken = accessTokenService.findByValue(bearerToken);
// Do not throw IncorrectCredentialException if no access token found // Do not throw IncorrectCredentialException if no access token found
// as the bearer token can be a faked token for anonymous access // as the bearer token can be a faked token for anonymous access

View File

@ -1,6 +1,6 @@
package io.onedev.server.plugin.pack.gem; package io.onedev.server.plugin.pack.gem;
import static io.onedev.server.plugin.pack.gem.GemPackService.SERVICE_ID; import static io.onedev.server.plugin.pack.gem.GemPackHandler.HANDLER_ID;
import static io.onedev.server.web.translation.Translation._T; import static io.onedev.server.web.translation.Translation._T;
import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.markup.html.panel.Panel;
@ -23,7 +23,7 @@ public class GemHelpPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + projectPath + "/~" + SERVICE_ID; var registryUrl = getServerUrl() + "/" + projectPath + "/~" + HANDLER_ID;
var addSourceCommands = "" + var addSourceCommands = "" +
"---\n" + "---\n" +
registryUrl + ": Bearer <onedev_access_token>"; registryUrl + ": Bearer <onedev_access_token>";

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.gem; package io.onedev.server.plugin.pack.gem;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class GemModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(GemPackService.class); bind(GemPackHandler.class);
contribute(PackService.class, GemPackService.class); contribute(PackHandler.class, GemPackHandler.class);
contribute(PackSupport.class, new GemPackSupport()); contribute(PackSupport.class, new GemPackSupport());
} }

View File

@ -4,6 +4,7 @@ import io.onedev.commons.utils.ExplicitException;
import io.onedev.commons.utils.FileUtils; import io.onedev.commons.utils.FileUtils;
import io.onedev.commons.utils.LockUtils; import io.onedev.commons.utils.LockUtils;
import io.onedev.commons.utils.StringUtils; import io.onedev.commons.utils.StringUtils;
import io.onedev.server.pack.PackHandler;
import io.onedev.server.service.BuildService; import io.onedev.server.service.BuildService;
import io.onedev.server.service.PackBlobService; import io.onedev.server.service.PackBlobService;
import io.onedev.server.service.PackService; import io.onedev.server.service.PackService;
@ -56,9 +57,8 @@ import static java.util.stream.Collectors.toList;
import static javax.servlet.http.HttpServletResponse.*; import static javax.servlet.http.HttpServletResponse.*;
@Singleton @Singleton
public class GemPackService implements io.onedev.server.pack.PackService { public class GemPackHandler implements PackHandler {
public static final String HANDLER_ID = "rubygems";
public static final String SERVICE_ID = "rubygems";
private static final int MAX_METADATA_SIZE = 10000000; private static final int MAX_METADATA_SIZE = 10000000;
@ -75,7 +75,7 @@ public class GemPackService implements io.onedev.server.pack.PackService {
private final BuildService buildService; private final BuildService buildService;
@Inject @Inject
public GemPackService(SessionService sessionService, TransactionService transactionService, public GemPackHandler(SessionService sessionService, TransactionService transactionService,
PackBlobService packBlobService, PackService packService, PackBlobService packBlobService, PackService packService,
ProjectService projectService, BuildService buildService) { ProjectService projectService, BuildService buildService) {
this.sessionService = sessionService; this.sessionService = sessionService;
@ -87,8 +87,8 @@ public class GemPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
private String getLockName(Long projectId, String name) { private String getLockName(Long projectId, String name) {
@ -97,7 +97,7 @@ public class GemPackService implements io.onedev.server.pack.PackService {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, Long projectId, public void handle(HttpServletRequest request, HttpServletResponse response, Long projectId,
Long buildId, List<String> pathSegments) { Long buildId, List<String> pathSegments) {
var method = request.getMethod(); var method = request.getMethod();

View File

@ -22,7 +22,7 @@ public class HelmHelpPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + projectPath + "/~" + HelmPackService.SERVICE_ID; var registryUrl = getServerUrl() + "/" + projectPath + "/~" + HelmPackHandler.HANDLER_ID;
add(new CodeSnippetPanel("pushChart", Model.of("$ curl -u <onedev_account_name>:<onedev_password_or_access_token> -X POST --upload-file /path/to/chart.tgz " + registryUrl))); add(new CodeSnippetPanel("pushChart", Model.of("$ curl -u <onedev_account_name>:<onedev_password_or_access_token> -X POST --upload-file /path/to/chart.tgz " + registryUrl)));
add(new CodeSnippetPanel("jobCommands", Model.of("" + add(new CodeSnippetPanel("jobCommands", Model.of("" +

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.helm; package io.onedev.server.plugin.pack.helm;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class HelmModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(HelmPackService.class); bind(HelmPackHandler.class);
contribute(PackService.class, HelmPackService.class); contribute(PackHandler.class, HelmPackHandler.class);
contribute(PackSupport.class, new HelmPackSupport()); contribute(PackSupport.class, new HelmPackSupport());
} }

View File

@ -21,6 +21,7 @@ import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import io.onedev.server.pack.PackHandler;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.shiro.authz.UnauthorizedException; import org.apache.shiro.authz.UnauthorizedException;
@ -46,9 +47,9 @@ import io.onedev.server.util.IOUtils;
import io.onedev.server.util.Pair; import io.onedev.server.util.Pair;
@Singleton @Singleton
public class HelmPackService implements io.onedev.server.pack.PackService { public class HelmPackHandler implements PackHandler {
public static final String SERVICE_ID = "helm"; public static final String HANDLER_ID = "helm";
private static final int MAX_FILE_SIZE = 10 * 1024 * 1024; private static final int MAX_FILE_SIZE = 10 * 1024 * 1024;
@ -65,7 +66,7 @@ public class HelmPackService implements io.onedev.server.pack.PackService {
private final BuildService buildService; private final BuildService buildService;
@Inject @Inject
public HelmPackService(ProjectService projectService, PackService packService, public HelmPackHandler(ProjectService projectService, PackService packService,
PackBlobService packBlobService, SessionService sessionService, PackBlobService packBlobService, SessionService sessionService,
TransactionService transactionService, BuildService buildService) { TransactionService transactionService, BuildService buildService) {
this.projectService = projectService; this.projectService = projectService;
@ -77,12 +78,12 @@ public class HelmPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, public void handle(HttpServletRequest request, HttpServletResponse response,
Long projectId, Long buildId, List<String> pathSegments) { Long projectId, Long buildId, List<String> pathSegments) {
if (request.getMethod().equals("GET")) { if (request.getMethod().equals("GET")) {
if (pathSegments.size() == 1) { if (pathSegments.size() == 1) {

View File

@ -28,7 +28,7 @@ public class HelmPackPanel extends GenericPanel<Pack> {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + HelmPackService.SERVICE_ID; var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + HelmPackHandler.HANDLER_ID;
add(new Label("addRepo", "$ helm repo add onedev --username <onedev_account_name> --password <onedev_password_or_access_token> " + registryUrl)); add(new Label("addRepo", "$ helm repo add onedev --username <onedev_account_name> --password <onedev_password_or_access_token> " + registryUrl));
add(new Label("installChart", "$ helm install " + getPack().getName() + " onedev/" + getPack().getName() + " --version " + getPack().getVersion())); add(new Label("installChart", "$ helm install " + getPack().getName() + " onedev/" + getPack().getName() + " --version " + getPack().getVersion()));

View File

@ -31,7 +31,7 @@ public class MavenHelpPanel extends Panel {
var serverUrl = OneDev.getInstance(SettingService.class).getSystemSetting().getServerUrl(); var serverUrl = OneDev.getInstance(SettingService.class).getSystemSetting().getServerUrl();
var bindings = new HashMap<String, Object>(); var bindings = new HashMap<String, Object>();
bindings.put("url", serverUrl + "/" + projectPath + "/~" + MavenPackService.SERVICE_ID); bindings.put("url", serverUrl + "/" + projectPath + "/~" + MavenPackHandler.HANDLER_ID);
bindings.put("permission", "write"); bindings.put("permission", "write");
try { try {

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.maven; package io.onedev.server.plugin.pack.maven;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class MavenModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(MavenPackService.class); bind(MavenPackHandler.class);
contribute(PackService.class, MavenPackService.class); contribute(PackHandler.class, MavenPackHandler.class);
contribute(PackSupport.class, new MavenPackSupport()); contribute(PackSupport.class, new MavenPackSupport());
} }

View File

@ -2,6 +2,7 @@ package io.onedev.server.plugin.pack.maven;
import io.onedev.commons.utils.LockUtils; import io.onedev.commons.utils.LockUtils;
import io.onedev.commons.utils.StringUtils; import io.onedev.commons.utils.StringUtils;
import io.onedev.server.pack.PackHandler;
import io.onedev.server.service.*; import io.onedev.server.service.*;
import io.onedev.server.event.ListenerRegistry; import io.onedev.server.event.ListenerRegistry;
import io.onedev.server.event.project.pack.PackPublished; import io.onedev.server.event.project.pack.PackPublished;
@ -45,9 +46,9 @@ import static javax.servlet.http.HttpServletResponse.*;
import static javax.ws.rs.core.HttpHeaders.LAST_MODIFIED; import static javax.ws.rs.core.HttpHeaders.LAST_MODIFIED;
@Singleton @Singleton
public class MavenPackService implements io.onedev.server.pack.PackService { public class MavenPackHandler implements PackHandler {
public static final String SERVICE_ID = "maven"; public static final String HANDLER_ID = "maven";
private static final int MAX_CHECKSUM_LEN = 1000; private static final int MAX_CHECKSUM_LEN = 1000;
@ -91,7 +92,7 @@ public class MavenPackService implements io.onedev.server.pack.PackService {
private final BuildService buildService; private final BuildService buildService;
@Inject @Inject
public MavenPackService(SessionService sessionService, TransactionService transactionService, public MavenPackHandler(SessionService sessionService, TransactionService transactionService,
PackBlobService packBlobService, PackService packService, PackBlobService packBlobService, PackService packService,
PackBlobReferenceService packBlobReferenceService, PackBlobReferenceService packBlobReferenceService,
ProjectService projectService, ListenerRegistry listenerRegistry, ProjectService projectService, ListenerRegistry listenerRegistry,
@ -107,12 +108,12 @@ public class MavenPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, Long projectId, public void handle(HttpServletRequest request, HttpServletResponse response, Long projectId,
Long buildId, List<String> pathSegments) { Long buildId, List<String> pathSegments) {
var method = request.getMethod(); var method = request.getMethod();

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.maven; package io.onedev.server.plugin.pack.maven;
import static io.onedev.server.plugin.pack.maven.MavenPackService.FILE_METADATA; import static io.onedev.server.plugin.pack.maven.MavenPackHandler.FILE_METADATA;
import static io.onedev.server.plugin.pack.maven.MavenPackService.NONE; import static io.onedev.server.plugin.pack.maven.MavenPackHandler.NONE;
import static io.onedev.server.util.GroovyUtils.evalTemplate; import static io.onedev.server.util.GroovyUtils.evalTemplate;
import static io.onedev.server.web.translation.Translation._T; import static io.onedev.server.web.translation.Translation._T;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
@ -120,7 +120,7 @@ public class MavenPackPanel extends GenericPanel<Pack> {
bindings.put("artifactId", substringAfter(getPack().getName(), ":")); bindings.put("artifactId", substringAfter(getPack().getName(), ":"));
bindings.put("version", getPack().getVersion()); bindings.put("version", getPack().getVersion());
var serverUrl = OneDev.getInstance(SettingService.class).getSystemSetting().getServerUrl(); var serverUrl = OneDev.getInstance(SettingService.class).getSystemSetting().getServerUrl();
bindings.put("url", serverUrl + "/" + getPack().getProject().getPath() + "/~" + MavenPackService.SERVICE_ID); bindings.put("url", serverUrl + "/" + getPack().getProject().getPath() + "/~" + MavenPackHandler.HANDLER_ID);
bindings.put("permission", "read"); bindings.put("permission", "read");
if (packaging.equals("jar") || packaging.equals("maven-plugin") || packaging.equals("pom")) { if (packaging.equals("jar") || packaging.equals("maven-plugin") || packaging.equals("pom")) {

View File

@ -1,6 +1,6 @@
package io.onedev.server.plugin.pack.maven; package io.onedev.server.plugin.pack.maven;
import static io.onedev.server.plugin.pack.maven.MavenPackService.NONE; import static io.onedev.server.plugin.pack.maven.MavenPackHandler.NONE;
import static io.onedev.server.web.translation.Translation._T; import static io.onedev.server.web.translation.Translation._T;
import static org.apache.commons.lang3.StringUtils.substringBeforeLast; import static org.apache.commons.lang3.StringUtils.substringBeforeLast;

View File

@ -23,7 +23,7 @@ public class NpmHelpPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + projectPath + "/~" + NpmPackService.SERVICE_ID + "/"; var registryUrl = getServerUrl() + "/" + projectPath + "/~" + NpmPackHandler.HANDLER_ID + "/";
add(new CodeSnippetPanel("scopeRegistry", Model.of("$ npm config set @myscope:registry " + registryUrl))); add(new CodeSnippetPanel("scopeRegistry", Model.of("$ npm config set @myscope:registry " + registryUrl)));
add(new CodeSnippetPanel("registryAuth", Model.of("$ npm config set -- '" + substringAfter(registryUrl, ":") + ":_authToken' \"onedev_access_token\""))); add(new CodeSnippetPanel("registryAuth", Model.of("$ npm config set -- '" + substringAfter(registryUrl, ":") + ":_authToken' \"onedev_access_token\"")));
add(new CodeSnippetPanel("publishCommand", Model.of("$ npm publish"))); add(new CodeSnippetPanel("publishCommand", Model.of("$ npm publish")));

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.npm; package io.onedev.server.plugin.pack.npm;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class NpmModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(NpmPackService.class); bind(NpmPackHandler.class);
contribute(PackService.class, NpmPackService.class); contribute(PackHandler.class, NpmPackHandler.class);
contribute(PackSupport.class, new NpmPackSupport()); contribute(PackSupport.class, new NpmPackSupport());
} }

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import io.onedev.commons.utils.LockUtils; import io.onedev.commons.utils.LockUtils;
import io.onedev.commons.utils.StringUtils; import io.onedev.commons.utils.StringUtils;
import io.onedev.server.pack.PackHandler;
import io.onedev.server.service.BuildService; import io.onedev.server.service.BuildService;
import io.onedev.server.service.PackBlobService; import io.onedev.server.service.PackBlobService;
import io.onedev.server.service.PackService; import io.onedev.server.service.PackService;
@ -47,9 +48,9 @@ import static org.apache.commons.codec.binary.Base64.encodeBase64String;
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.*;
@Singleton @Singleton
public class NpmPackService implements io.onedev.server.pack.PackService { public class NpmPackHandler implements PackHandler {
public static final String SERVICE_ID = "npm"; public static final String HANDLER_ID = "npm";
private static final int MAX_UPLOAD_METADATA_LEN = 10000000; private static final int MAX_UPLOAD_METADATA_LEN = 10000000;
@ -74,7 +75,7 @@ public class NpmPackService implements io.onedev.server.pack.PackService {
private final UrlService urlService; private final UrlService urlService;
@Inject @Inject
public NpmPackService(SessionService sessionService, TransactionService transactionService, public NpmPackHandler(SessionService sessionService, TransactionService transactionService,
PackBlobService packBlobService, PackService packService, PackBlobService packBlobService, PackService packService,
ProjectService projectService, BuildService buildService, ProjectService projectService, BuildService buildService,
ObjectMapper objectMapper, UrlService urlService) { ObjectMapper objectMapper, UrlService urlService) {
@ -89,8 +90,8 @@ public class NpmPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
private String getLockName(Long projectId, String name) { private String getLockName(Long projectId, String name) {
@ -122,7 +123,7 @@ public class NpmPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, Long projectId, public void handle(HttpServletRequest request, HttpServletResponse response, Long projectId,
Long buildId, List<String> pathSegments) { Long buildId, List<String> pathSegments) {
var method = request.getMethod(); var method = request.getMethod();
@ -290,7 +291,7 @@ public class NpmPackService implements io.onedev.server.pack.PackService {
var project = checkProject(projectId, false); var project = checkProject(projectId, false);
sessionService.run(() -> { sessionService.run(() -> {
var packs = packService.queryByName(project, TYPE, packageName, null); var packs = packService.queryByName(project, TYPE, packageName, null);
var npmUrl = urlService.urlFor(project, true) + "/~" + getServiceId() + "/" + encodePath(packageName); var npmUrl = urlService.urlFor(project, true) + "/~" + getHandlerId() + "/" + encodePath(packageName);
var distTagsNode = objectMapper.createObjectNode(); var distTagsNode = objectMapper.createObjectNode();
var versionsNode = objectMapper.createObjectNode(); var versionsNode = objectMapper.createObjectNode();
NpmData latestPackData = null; NpmData latestPackData = null;

View File

@ -28,7 +28,7 @@ public class NpmPackPanel extends GenericPanel<Pack> {
@Override @Override
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + NpmPackService.SERVICE_ID + "/"; var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + NpmPackHandler.HANDLER_ID + "/";
if (getPack().getName().contains("/")) { if (getPack().getName().contains("/")) {
var scope = substringBefore(getPack().getName(), "/"); var scope = substringBefore(getPack().getName(), "/");
add(new Label("registryConfig", "$ npm config set " + scope + ":registry " + registryUrl)); add(new Label("registryConfig", "$ npm config set " + scope + ":registry " + registryUrl));

View File

@ -7,7 +7,7 @@ import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model; import org.apache.wicket.model.Model;
import static io.onedev.server.plugin.pack.nuget.NugetPackService.SERVICE_ID; import static io.onedev.server.plugin.pack.nuget.NugetPackHandler.HANDLER_ID;
import static io.onedev.server.web.translation.Translation._T; import static io.onedev.server.web.translation.Translation._T;
public class NugetHelpPanel extends Panel { public class NugetHelpPanel extends Panel {
@ -23,7 +23,7 @@ public class NugetHelpPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + projectPath + "/~" + SERVICE_ID + "/index.json"; var registryUrl = getServerUrl() + "/" + projectPath + "/~" + HANDLER_ID + "/index.json";
add(new CodeSnippetPanel("addSource", Model.of("$ dotnet nuget add source --name onedev --username <onedev_account_name> --password <onedev_account_password> --store-password-in-clear-text " + registryUrl))); add(new CodeSnippetPanel("addSource", Model.of("$ dotnet nuget add source --name onedev --username <onedev_account_name> --password <onedev_account_password> --store-password-in-clear-text " + registryUrl)));
add(new CodeSnippetPanel("pushCommand", Model.of("$ dotnet nuget push -s onedev /path/to/<PackageId>.<PackageVersion>.nupkg"))); add(new CodeSnippetPanel("pushCommand", Model.of("$ dotnet nuget push -s onedev /path/to/<PackageId>.<PackageVersion>.nupkg")));

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.nuget; package io.onedev.server.plugin.pack.nuget;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class NugetModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(NugetPackService.class); bind(NugetPackHandler.class);
contribute(PackService.class, NugetPackService.class); contribute(PackHandler.class, NugetPackHandler.class);
contribute(PackSupport.class, new NugetPackSupport()); contribute(PackSupport.class, new NugetPackSupport());
} }

View File

@ -43,6 +43,7 @@ import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import io.onedev.server.pack.PackHandler;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -77,11 +78,11 @@ import io.onedev.server.util.XmlUtils;
import io.onedev.server.web.UrlService; import io.onedev.server.web.UrlService;
@Singleton @Singleton
public class NugetPackService implements io.onedev.server.pack.PackService { public class NugetPackHandler implements PackHandler {
public static final String SERVICE_ID = "nuget"; public static final String HANDLER_ID = "nuget";
private static final Logger logger = LoggerFactory.getLogger(NugetPackService.class); private static final Logger logger = LoggerFactory.getLogger(NugetPackHandler.class);
private static final String HEADER_API_KEY = "X-NuGet-ApiKey"; private static final String HEADER_API_KEY = "X-NuGet-ApiKey";
@ -114,7 +115,7 @@ public class NugetPackService implements io.onedev.server.pack.PackService {
private final UrlService urlService; private final UrlService urlService;
@Inject @Inject
public NugetPackService(SessionService sessionService, TransactionService transactionService, public NugetPackHandler(SessionService sessionService, TransactionService transactionService,
PackBlobService packBlobService, PackService packService, PackBlobService packBlobService, PackService packService,
ProjectService projectService, BuildService buildService, ProjectService projectService, BuildService buildService,
ObjectMapper objectMapper, UrlService urlService) { ObjectMapper objectMapper, UrlService urlService) {
@ -129,8 +130,8 @@ public class NugetPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
private String getLockName(Long projectId, String name) { private String getLockName(Long projectId, String name) {
@ -146,7 +147,7 @@ public class NugetPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, Long projectId, public void handle(HttpServletRequest request, HttpServletResponse response, Long projectId,
Long buildId, List<String> pathSegments) { Long buildId, List<String> pathSegments) {
var method = request.getMethod(); var method = request.getMethod();
@ -585,7 +586,7 @@ public class NugetPackService implements io.onedev.server.pack.PackService {
} }
private String getBaseUrl(Project project) { private String getBaseUrl(Project project) {
return urlService.urlFor(project, true) + "/~" + SERVICE_ID; return urlService.urlFor(project, true) + "/~" + HANDLER_ID;
} }
private String getRegistrationIndexUrl(String baseUrl, String name) { private String getRegistrationIndexUrl(String baseUrl, String name) {

View File

@ -23,7 +23,7 @@ public class NugetPackPanel extends GenericPanel<Pack> {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + NugetPackService.SERVICE_ID + "/index.json"; var registryUrl = getServerUrl() + "/" + getPack().getProject().getPath() + "/~" + NugetPackHandler.HANDLER_ID + "/index.json";
add(new Label("addSource", "$ dotnet nuget add source --name onedev --username <onedev_account_name> --password <onedev_password_or_access_token> --store-password-in-clear-text " + registryUrl)); add(new Label("addSource", "$ dotnet nuget add source --name onedev --username <onedev_account_name> --password <onedev_password_or_access_token> --store-password-in-clear-text " + registryUrl));
add(new Label("addPack", "$ dotnet add package " + getPack().getName() + " -v " + getPack().getVersion())); add(new Label("addPack", "$ dotnet add package " + getPack().getName() + " -v " + getPack().getVersion()));

View File

@ -24,7 +24,7 @@ public class PypiHelpPanel extends Panel {
protected void onInitialize() { protected void onInitialize() {
super.onInitialize(); super.onInitialize();
var registryUrl = getServerUrl() + "/" + projectPath + "/~" + PypiPackService.SERVICE_ID; var registryUrl = getServerUrl() + "/" + projectPath + "/~" + PypiPackHandler.HANDLER_ID;
add(new CodeSnippetPanel("addRepository", new AbstractReadOnlyModel<>() { add(new CodeSnippetPanel("addRepository", new AbstractReadOnlyModel<>() {
@Override @Override
public String getObject() { public String getObject() {

View File

@ -1,7 +1,7 @@
package io.onedev.server.plugin.pack.pypi; package io.onedev.server.plugin.pack.pypi;
import io.onedev.commons.loader.AbstractPluginModule; import io.onedev.commons.loader.AbstractPluginModule;
import io.onedev.server.pack.PackService; import io.onedev.server.pack.PackHandler;
import io.onedev.server.pack.PackSupport; import io.onedev.server.pack.PackSupport;
/** /**
@ -14,8 +14,8 @@ public class PypiModule extends AbstractPluginModule {
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(PypiPackService.class); bind(PypiPackHandler.class);
contribute(PackService.class, PypiPackService.class); contribute(PackHandler.class, PypiPackHandler.class);
contribute(PackSupport.class, new PypiPackSupport()); contribute(PackSupport.class, new PypiPackSupport());
} }

View File

@ -5,6 +5,7 @@ import com.google.common.io.Resources;
import io.onedev.commons.utils.ExplicitException; import io.onedev.commons.utils.ExplicitException;
import io.onedev.commons.utils.LockUtils; import io.onedev.commons.utils.LockUtils;
import io.onedev.commons.utils.StringUtils; import io.onedev.commons.utils.StringUtils;
import io.onedev.server.pack.PackHandler;
import io.onedev.server.service.BuildService; import io.onedev.server.service.BuildService;
import io.onedev.server.service.PackBlobService; import io.onedev.server.service.PackBlobService;
import io.onedev.server.service.PackService; import io.onedev.server.service.PackService;
@ -40,9 +41,9 @@ import static java.util.stream.Collectors.toList;
import static javax.servlet.http.HttpServletResponse.*; import static javax.servlet.http.HttpServletResponse.*;
@Singleton @Singleton
public class PypiPackService implements io.onedev.server.pack.PackService { public class PypiPackHandler implements PackHandler {
public static final String SERVICE_ID = "pypi"; public static final String HANDLER_ID = "pypi";
private static final String CONTENT_TYPE_SIMPLE = "application/vnd.pypi.simple.v1+html"; private static final String CONTENT_TYPE_SIMPLE = "application/vnd.pypi.simple.v1+html";
@ -61,7 +62,7 @@ public class PypiPackService implements io.onedev.server.pack.PackService {
private final BuildService buildService; private final BuildService buildService;
@Inject @Inject
public PypiPackService(SessionService sessionService, TransactionService transactionService, public PypiPackHandler(SessionService sessionService, TransactionService transactionService,
PackBlobService packBlobService, PackService packService, PackBlobService packBlobService, PackService packService,
ProjectService projectService, BuildService buildService) { ProjectService projectService, BuildService buildService) {
this.sessionService = sessionService; this.sessionService = sessionService;
@ -73,8 +74,8 @@ public class PypiPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public String getServiceId() { public String getHandlerId() {
return SERVICE_ID; return HANDLER_ID;
} }
private String getLockName(Long projectId, String name) { private String getLockName(Long projectId, String name) {
@ -89,7 +90,7 @@ public class PypiPackService implements io.onedev.server.pack.PackService {
} }
@Override @Override
public void service(HttpServletRequest request, HttpServletResponse response, Long projectId, public void handle(HttpServletRequest request, HttpServletResponse response, Long projectId,
Long buildId, List<String> pathSegments) { Long buildId, List<String> pathSegments) {
var method = request.getMethod(); var method = request.getMethod();
@ -220,7 +221,7 @@ public class PypiPackService implements io.onedev.server.pack.PackService {
var packs = packService.queryByName(project, TYPE, name, VERSION_COMPARATOR); var packs = packService.queryByName(project, TYPE, name, VERSION_COMPARATOR);
if (!packs.isEmpty()) { if (!packs.isEmpty()) {
var bindings = new HashMap<String, Object>(); var bindings = new HashMap<String, Object>();
bindings.put("baseUrl", "/" + project.getPath() + "/~" + SERVICE_ID + "/files/" + UrlUtils.encodePath(name)); bindings.put("baseUrl", "/" + project.getPath() + "/~" + HANDLER_ID + "/files/" + UrlUtils.encodePath(name));
bindings.put("packs", packs); bindings.put("packs", packs);
try { try {
URL tplUrl = Resources.getResource(getClass(), "package-versions.tpl"); URL tplUrl = Resources.getResource(getClass(), "package-versions.tpl");

View File

@ -41,7 +41,7 @@ public class PypiPackPanel extends GenericPanel<Pack> {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
var indexUrl = protocol + "://<OneDev_account_name>:<OneDev_password>@" + UrlUtils.getServer(serverUrl) var indexUrl = protocol + "://<OneDev_account_name>:<OneDev_password>@" + UrlUtils.getServer(serverUrl)
+ "/" + getPack().getProject().getPath() + "/~" + PypiPackService.SERVICE_ID + "/simple/"; + "/" + getPack().getProject().getPath() + "/~" + PypiPackHandler.HANDLER_ID + "/simple/";
var installCmd = "$ python3 -m pip install --extra-index-url " + indexUrl; var installCmd = "$ python3 -m pip install --extra-index-url " + indexUrl;
if (protocol.equals("http")) if (protocol.equals("http"))
installCmd += " --trusted-host " + host; installCmd += " --trusted-host " + host;
@ -49,7 +49,7 @@ public class PypiPackPanel extends GenericPanel<Pack> {
add(new Label("install", installCmd)); add(new Label("install", installCmd));
indexUrl = protocol + "://@job_token@:@secret:access-token@@@" + UrlUtils.getServer(serverUrl) indexUrl = protocol + "://@job_token@:@secret:access-token@@@" + UrlUtils.getServer(serverUrl)
+ "/" + getPack().getProject().getPath() + "/~" + PypiPackService.SERVICE_ID + "/simple/"; + "/" + getPack().getProject().getPath() + "/~" + PypiPackHandler.HANDLER_ID + "/simple/";
var jobCommands = "" + var jobCommands = "" +
"# " + _T("Use job token to tell OneDev the build using the package") + "\n" + "# " + _T("Use job token to tell OneDev the build using the package") + "\n" +
"# " + _T("Job secret 'access-token' should be defined in project build setting as an access token with package read permission") + "\n\n" + "# " + _T("Job secret 'access-token' should be defined in project build setting as an access token with package read permission") + "\n\n" +