1 package org.apache.archiva.proxy.model;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.archiva.model.ArtifactReference;
23 import org.apache.archiva.policies.Policy;
24 import org.apache.archiva.policies.ProxyDownloadException;
25 import org.apache.archiva.repository.ManagedRepository;
26 import org.apache.archiva.repository.RepositoryType;
27 import org.apache.archiva.repository.storage.StorageAsset;
28
29 import java.util.List;
30 import java.util.Map;
31
32 /**
33 * A repository proxy handler is used to fetch remote artifacts from different remote repositories.
34 * A proxy handler is connected to one managed repository and a list of remote repositories.
35 *
36 * Repository proxies should not be confused with network proxies. Network are proxies for specific network protocols,
37 * like HTTP. A repository proxy delegates the repository requests to remote repositories and caches artifacts.
38 *
39 * If a artifact is requested for the managed repository and the artifact is not cached locally, the handler goes through
40 * the list of remotes and tries to download the artifact. If a download was successful the artifact is cached locally.
41 *
42 * The connection between managed and remote repositories is defined by list of {@link ProxyConnector} each defines a one-to-one relationship.
43 *
44 * A proxy connector defines specifics about the download behaviour:
45 * <ul>
46 * <li>Policies {@link org.apache.archiva.policies.Policy} define the behaviour for different cases (errors, not available, caching lifetime).</li>
47 * <li>Black- and Whitelists are used to ban or allow certain paths on the remote repositories.
48 * </ul>
49 *
50 * The policies and black- and whitelist are set on the {@link ProxyConnector}
51 *
52 * There may be network proxies needed to connect the remote repositories.
53 *
54 */
55 public interface RepositoryProxyHandler
56 {
57
58 List<RepositoryType> supports( );
59
60 /**
61 * Performs the artifact fetch operation against the target repositories
62 * of the provided source repository.
63 * <p>
64 * If the artifact is found, it is downloaded and placed into the source repository
65 * filesystem.
66 *
67 * @param repository the source repository to use. (must be a managed repository)
68 * @param artifact the artifact to fetch.
69 * @return the file that was obtained, or null if no content was obtained
70 * @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
71 */
72 StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
73 throws ProxyDownloadException;
74
75 /**
76 * Performs the metadata fetch operation against the target repositories
77 * of the provided source repository.
78 * <p>
79 * If the metadata is found, it is downloaded and placed into the source repository
80 * filesystem.
81 *
82 * @param repository the source repository to use. (must be a managed repository)
83 * @param logicalPath the metadata to fetch.
84 * @return the file that was obtained, or null if no content was obtained
85 */
86 ProxyFetchResult fetchMetadataFromProxies( ManagedRepository repository, String logicalPath );
87
88 /**
89 * Performs the fetch operation against the target repositories
90 * of the provided source repository by a specific path.
91 *
92 * @param managedRepository the source repository to use. (must be a managed repository)
93 * @param path the path of the resource to fetch
94 * @return the file that was obtained, or null if no content was obtained
95 */
96 StorageAsset fetchFromProxies( ManagedRepository managedRepository, String path );
97
98 /**
99 * Get the List of {@link ProxyConnector} objects of the source repository.
100 *
101 * @param repository the source repository to look for.
102 * @return the List of {@link ProxyConnector} objects.
103 */
104 List<ProxyConnector> getProxyConnectors( ManagedRepository repository );
105
106 /**
107 * Tests to see if the provided repository is a source repository for
108 * any {@link ProxyConnector} objects.
109 *
110 * @param repository the source repository to look for.
111 * @return true if there are proxy connectors that use the provided
112 * repository as a source repository.
113 */
114 boolean hasProxies( ManagedRepository repository );
115
116 /**
117 * Sets network proxies (normally HTTP proxies) to access the remote repositories.
118 *
119 * @param networkProxies A map of (repository id, network proxy) where the repository id must be the id of an
120 * existing remote repository.
121 */
122 void setNetworkProxies( Map<String, NetworkProxy> networkProxies );
123
124 /**
125 * Adds a network proxy that is used to access the remote repository.
126 *
127 * @param id The repository id
128 * @param networkProxy The network proxy to use
129 */
130 void addNetworkproxy( String id, NetworkProxy networkProxy);
131
132 /**
133 * Returns a map of the defined network proxies, or a empty map, if no proxy is defined.
134 *
135 * @return A map (repository id, network proxy). If none is defined, a empty map is returned.
136 */
137 Map<String, NetworkProxy> getNetworkProxies( );
138
139 /**
140 * Returns the network proxy that is defined for the given repository id.
141 * @param id The remote repository id
142 * @return A network proxy or <code>null</code> if no one is defined for this id.
143 */
144 NetworkProxy getNetworkProxy( String id );
145
146 /**
147 * Returns the proxy handler implementation. This can be used, if the underlying implementation for a specific
148 * repository type is needed.
149 *
150 * @param clazz The class to convert to
151 * @param <T> The type
152 * @return The handler
153 */
154 <T extends RepositoryProxyHandler> T getHandler( Class<T> clazz ) throws IllegalArgumentException;
155
156 /**
157 * Sets the policies that this handler should validate.
158 * @param policyList
159 */
160 void setPolicies(List<Policy> policyList);
161
162 /**
163 * Adds a policy
164 * @param policy
165 */
166 void addPolicy( Policy policy );
167
168 /**
169 * Removes a policy
170 * @param policy
171 */
172 void removePolicy( Policy policy );
173
174 void addProxyConnector(ProxyConnector connector);
175
176 void setProxyConnectors( List<ProxyConnector> proxyConnectors );
177 }