blob: 505098a04b0f9403e003c5452aa6907b7ba21608 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
Dave Borowitz9de65952012-08-13 16:09:45 -070017import java.io.IOException;
18import java.util.Map;
Shawn Pearcedb394cc2017-07-01 11:45:20 -070019import java.util.Optional;
Dave Borowitz9de65952012-08-13 16:09:45 -070020import java.util.Set;
Shawn Pearcec709c4c2015-08-28 15:30:42 -070021import javax.annotation.Nullable;
Dave Borowitz9de65952012-08-13 16:09:45 -070022import javax.servlet.http.HttpServletRequest;
Dave Borowitz3b744b12016-08-19 16:11:10 -040023import org.eclipse.jgit.lib.Config;
24import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
25import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
Dave Borowitz9de65952012-08-13 16:09:45 -070026
27/**
28 * Git storage interface for Gitiles.
Dave Borowitz40255d52016-08-19 16:16:22 -040029 *
30 * <p>Each instance is associated with a single end-user request, which implicitly includes
31 * information about the host and repository.
Dave Borowitz9de65952012-08-13 16:09:45 -070032 */
33public interface GitilesAccess {
Shawn Pearcedb394cc2017-07-01 11:45:20 -070034 /** Access for the current request, if it has been initialized. */
35 public static Optional<GitilesAccess> getAccess(HttpServletRequest req) {
36 return Optional.ofNullable((GitilesAccess) req.getAttribute(GitilesAccess.class.getName()));
37 }
38
39 /** Access for the current request. */
40 public static GitilesAccess getAccess(HttpServletRequest req, Factory factory) {
41 GitilesAccess access = getAccess(req).orElse(null);
42 if (access == null) {
43 access = factory.forRequest(req);
44 req.setAttribute(GitilesAccess.class.getName(), access);
45 }
46 return access;
47 }
48
Dave Borowitz9de65952012-08-13 16:09:45 -070049 /** Factory for per-request access. */
50 public interface Factory {
David Pursehousee3d3ec82016-06-15 22:10:48 +090051 GitilesAccess forRequest(HttpServletRequest req);
Dave Borowitz9de65952012-08-13 16:09:45 -070052 }
53
54 /**
55 * List repositories on the host.
56 *
Dave Borowitz40255d52016-08-19 16:16:22 -040057 * @param prefix repository base path to list. Trailing "/" is implicitly added if missing. Null
58 * or empty string will match all repositories.
Dave Borowitz9de65952012-08-13 16:09:45 -070059 * @param branches branches to list along with each repository.
60 * @return map of repository names to descriptions.
Dave Borowitz40255d52016-08-19 16:16:22 -040061 * @throws ServiceNotEnabledException to trigger an HTTP 403 Forbidden (matching behavior in
62 * {@link org.eclipse.jgit.http.server.RepositoryFilter}).
63 * @throws ServiceNotAuthorizedException to trigger an HTTP 401 Unauthorized (matching behavior in
64 * {@link org.eclipse.jgit.http.server.RepositoryFilter}).
Dave Borowitz9de65952012-08-13 16:09:45 -070065 * @throws IOException if an error occurred.
66 */
Dave Borowitz40255d52016-08-19 16:16:22 -040067 Map<String, RepositoryDescription> listRepositories(@Nullable String prefix, Set<String> branches)
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +020068 throws ServiceNotEnabledException, ServiceNotAuthorizedException, IOException;
Dave Borowitz9de65952012-08-13 16:09:45 -070069
70 /**
Dave Borowitz40255d52016-08-19 16:16:22 -040071 * @return an opaque object that uniquely identifies the end-user making the request, and supports
72 * {@link Object#equals(Object)} and {@link Object#hashCode()}. Never null.
Dave Borowitz9de65952012-08-13 16:09:45 -070073 */
David Pursehousee3d3ec82016-06-15 22:10:48 +090074 Object getUserKey();
Dave Borowitz9de65952012-08-13 16:09:45 -070075
76 /** @return the repository name associated with the request. */
David Pursehousee3d3ec82016-06-15 22:10:48 +090077 String getRepositoryName();
Dave Borowitz9de65952012-08-13 16:09:45 -070078
79 /**
80 * @return the description attached to the repository of this request.
Dave Borowitz40255d52016-08-19 16:16:22 -040081 * @throws IOException an error occurred reading the description string from the repository.
Dave Borowitz9de65952012-08-13 16:09:45 -070082 */
David Pursehousee3d3ec82016-06-15 22:10:48 +090083 RepositoryDescription getRepositoryDescription() throws IOException;
Dave Borowitzded109a2014-03-03 15:25:39 -050084
85 /**
86 * @return configuration to apply to the host/repository for this request.
87 * @throws IOException an error occurred reading the configuration.
88 */
David Pursehousee3d3ec82016-06-15 22:10:48 +090089 Config getConfig() throws IOException;
Dave Borowitz9de65952012-08-13 16:09:45 -070090}