public void init(FilterConfig config) throws ServletException { ConfigRepository configRepository = ContextLoader.getCurrentWebApplicationContext().getBean(ConfigRepository.class); FileResolver<HttpServletRequest> resolver = new FileResolver<>(); resolver.exportRepository("api/config-repository.git", configRepository.getGitRepo()); setRepositoryResolver(resolver); setReceivePackFactory(null); super.init(config); }
@Override public UploadPack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
/** * Create a new resolver for the given path. * * @param basePath * the base path all repositories are rooted under. * @param exportAll * if true, exports all repositories, ignoring the check for the * {@code git-daemon-export-ok} files. */ public FileResolver(File basePath, boolean exportAll) { this(); exportDirectory(basePath); setExportAll(exportAll); }
public Repository open(C req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { if (isUnreasonableName(name)) throw new RepositoryNotFoundException(name); Repository db = exports.get(nameWithDotGit(name)); if (db != null) { db.incrementOpen(); if (isExportOk(req, name, db)) { throw new ServiceNotEnabledException();
@Override protected void execute(final DaemonClient dc, final Repository db, @Nullable Collection<String> extraParameters) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { ReceivePack rp = receivePackFactory.create(dc, db); InputStream in = dc.getInputStream(); OutputStream out = dc.getOutputStream(); rp.receive(in, out, null); } } };
@Override public void run() { try { final UploadPack rp = uploadPackFactory.create(req, remote); rp.upload(out_r, in_w, null); } catch (ServiceNotEnabledException e) { // Ignored. Client cannot use this repository. } catch (ServiceNotAuthorizedException e) { // Ignored. Client cannot use this repository. } catch (IOException err) { // Client side of the pipes should report the problem. err.printStackTrace(); } catch (RuntimeException err) { // Client side will notice we went away, and report. err.printStackTrace(); } finally { try { out_r.close(); } catch (IOException e2) { // Ignore close failure, we probably crashed above. } try { in_w.close(); } catch (IOException e2) { // Ignore close failure, we probably crashed above. } remote.close(); } } };
Repository openRepository(DaemonClient client, String name) throws ServiceMayNotContinueException { // Assume any attempt to use \ was by a Windows client // and correct to the more typical / used in Git URIs. // name = name.replace('\\', '/'); // git://thishost/path should always be name="/path" here // if (!name.startsWith("/")) //$NON-NLS-1$ return null; try { return repositoryResolver.open(client, name.substring(1)); } catch (RepositoryNotFoundException e) { // null signals it "wasn't found", which is all that is suitable // for the remote client to know. return null; } catch (ServiceNotAuthorizedException e) { // null signals it "wasn't found", which is all that is suitable // for the remote client to know. return null; } catch (ServiceNotEnabledException e) { // null signals it "wasn't found", which is all that is suitable // for the remote client to know. return null; } } }
/** * Add a single repository to the set that is exported by this daemon. * <p> * The existence (or lack-thereof) of <code>git-daemon-export-ok</code> is * ignored by this method. The repository is always published. * * @param name * name the repository will be published under. * @param db * the repository instance. */ public void exportRepository(String name, Repository db) { exports.put(nameWithDotGit(name), db); }
/** * Check if this repository can be served. * <p> * The default implementation of this method returns true only if either * {@link #isExportAll()} is true, or the {@code git-daemon-export-ok} file * is present in the repository's directory. * * @param req * the current HTTP request. * @param repositoryName * name of the repository, as present in the URL. * @param db * the opened repository instance. * @return true if the repository is accessible; false if not. * @throws java.io.IOException * the repository could not be accessed, the caller will claim * the repository does not exist. */ protected boolean isExportOk(C req, String repositoryName, Repository db) throws IOException { if (isExportAll()) return true; else if (db.getDirectory() != null) return new File(db.getDirectory(), "git-daemon-export-ok").exists(); //$NON-NLS-1$ else return false; }
@Override public ReceivePack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
/** * Create a new resolver for the given path. * * @param basePath * the base path all repositories are rooted under. * @param exportAll * if true, exports all repositories, ignoring the check for the * {@code git-daemon-export-ok} files. */ public FileResolver(File basePath, boolean exportAll) { this(); exportDirectory(basePath); setExportAll(exportAll); }
@Override public void run() { try { final ReceivePack rp = receivePackFactory.create(req, remote); rp.receive(out_r, in_w, System.err); } catch (ServiceNotEnabledException e) {
@Override protected void execute(final DaemonClient dc, final Repository db, @Nullable Collection<String> extraParameters) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { UploadPack up = uploadPackFactory.create(dc, db); InputStream in = dc.getInputStream(); OutputStream out = dc.getOutputStream(); if (extraParameters != null) { up.setExtraParameters(extraParameters); } up.upload(in, out, null); } }, new DaemonService("receive-pack", "receivepack") { //$NON-NLS-1$ //$NON-NLS-2$
public ReceivePack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
/** * Create a new resolver for the given path. * * @param basePath * the base path all repositories are rooted under. * @param exportAll * if true, exports all repositories, ignoring the check for the * {@code git-daemon-export-ok} files. */ public FileResolver(final File basePath, final boolean exportAll) { this(); exportDirectory(basePath); setExportAll(exportAll); }
@Override public UploadPack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
public UploadPack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
@Override public void access(HttpServletRequest req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
@Override public ReceivePack create(Object req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };
@Override public void access(HttpServletRequest req, Repository db) throws ServiceNotEnabledException { throw new ServiceNotEnabledException(); } };