| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package com.google.gitiles; |
| 16 | |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 17 | import java.io.IOException; |
| 18 | import java.util.Map; |
| 19 | import java.util.Set; |
| Shawn Pearce | c709c4c | 2015-08-28 15:30:42 -0700 | [diff] [blame] | 20 | import javax.annotation.Nullable; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 21 | import javax.servlet.http.HttpServletRequest; |
| Dave Borowitz | 3b744b1 | 2016-08-19 16:11:10 -0400 | [diff] [blame] | 22 | import org.eclipse.jgit.lib.Config; |
| 23 | import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; |
| 24 | import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Git storage interface for Gitiles. |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 28 | * |
| 29 | * <p>Each instance is associated with a single end-user request, which implicitly includes |
| 30 | * information about the host and repository. |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 31 | */ |
| 32 | public interface GitilesAccess { |
| 33 | /** Factory for per-request access. */ |
| 34 | public interface Factory { |
| David Pursehouse | e3d3ec8 | 2016-06-15 22:10:48 +0900 | [diff] [blame] | 35 | GitilesAccess forRequest(HttpServletRequest req); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /** |
| 39 | * List repositories on the host. |
| 40 | * |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 41 | * @param prefix repository base path to list. Trailing "/" is implicitly added if missing. Null |
| 42 | * or empty string will match all repositories. |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 43 | * @param branches branches to list along with each repository. |
| 44 | * @return map of repository names to descriptions. |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 45 | * @throws ServiceNotEnabledException to trigger an HTTP 403 Forbidden (matching behavior in |
| 46 | * {@link org.eclipse.jgit.http.server.RepositoryFilter}). |
| 47 | * @throws ServiceNotAuthorizedException to trigger an HTTP 401 Unauthorized (matching behavior in |
| 48 | * {@link org.eclipse.jgit.http.server.RepositoryFilter}). |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 49 | * @throws IOException if an error occurred. |
| 50 | */ |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 51 | Map<String, RepositoryDescription> listRepositories(@Nullable String prefix, Set<String> branches) |
| Han-Wen Nienhuys | c0200f6 | 2016-05-02 17:34:51 +0200 | [diff] [blame] | 52 | throws ServiceNotEnabledException, ServiceNotAuthorizedException, IOException; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 55 | * @return an opaque object that uniquely identifies the end-user making the request, and supports |
| 56 | * {@link Object#equals(Object)} and {@link Object#hashCode()}. Never null. |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 57 | */ |
| David Pursehouse | e3d3ec8 | 2016-06-15 22:10:48 +0900 | [diff] [blame] | 58 | Object getUserKey(); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 59 | |
| 60 | /** @return the repository name associated with the request. */ |
| David Pursehouse | e3d3ec8 | 2016-06-15 22:10:48 +0900 | [diff] [blame] | 61 | String getRepositoryName(); |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * @return the description attached to the repository of this request. |
| Dave Borowitz | 40255d5 | 2016-08-19 16:16:22 -0400 | [diff] [blame] | 65 | * @throws IOException an error occurred reading the description string from the repository. |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 66 | */ |
| David Pursehouse | e3d3ec8 | 2016-06-15 22:10:48 +0900 | [diff] [blame] | 67 | RepositoryDescription getRepositoryDescription() throws IOException; |
| Dave Borowitz | ded109a | 2014-03-03 15:25:39 -0500 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * @return configuration to apply to the host/repository for this request. |
| 71 | * @throws IOException an error occurred reading the configuration. |
| 72 | */ |
| David Pursehouse | e3d3ec8 | 2016-06-15 22:10:48 +0900 | [diff] [blame] | 73 | Config getConfig() throws IOException; |
| Dave Borowitz | 9de6595 | 2012-08-13 16:09:45 -0700 | [diff] [blame] | 74 | } |