]> source.dussan.org Git - archiva.git/blob
98ac75419f7da7c0fda0faa1b733ca1c74ce51be
[archiva.git] /
1 package org.apache.archiva.rest.api.v2.svc.maven;
2 /*
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19
20 import io.swagger.v3.oas.annotations.Operation;
21 import io.swagger.v3.oas.annotations.Parameter;
22 import io.swagger.v3.oas.annotations.headers.Header;
23 import io.swagger.v3.oas.annotations.media.Content;
24 import io.swagger.v3.oas.annotations.media.Schema;
25 import io.swagger.v3.oas.annotations.responses.ApiResponse;
26 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
27 import io.swagger.v3.oas.annotations.tags.Tag;
28 import org.apache.archiva.components.rest.model.PagedResult;
29 import org.apache.archiva.redback.authorization.RedbackAuthorization;
30 import org.apache.archiva.rest.api.v2.model.FileInfo;
31 import org.apache.archiva.rest.api.v2.model.MavenManagedRepository;
32 import org.apache.archiva.rest.api.v2.model.MavenManagedRepositoryUpdate;
33 import org.apache.archiva.rest.api.v2.svc.ArchivaRestError;
34 import org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException;
35 import org.apache.archiva.security.common.ArchivaRoleConstants;
36
37 import javax.ws.rs.Consumes;
38 import javax.ws.rs.DELETE;
39 import javax.ws.rs.DefaultValue;
40 import javax.ws.rs.GET;
41 import javax.ws.rs.POST;
42 import javax.ws.rs.PUT;
43 import javax.ws.rs.Path;
44 import javax.ws.rs.PathParam;
45 import javax.ws.rs.Produces;
46 import javax.ws.rs.QueryParam;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import java.util.List;
50
51 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
52 import static org.apache.archiva.rest.api.v2.svc.RestConfiguration.DEFAULT_PAGE_LIMIT;
53 import static org.apache.archiva.security.common.ArchivaRoleConstants.*;
54
55 /**
56  * Service interface for update, delete, add of Managed Maven Repositories
57  *
58  * @author Martin Stockhammer <martin_s@apache.org>
59  * @since 3.0
60  */
61 @Schema( name = "ManagedRepositoryService", description = "Managing and configuration of managed repositories" )
62 @Path( "repositories/maven/managed" )
63 @Tag(name = "v2")
64 @Tag(name = "v2/Repositories")
65 public interface MavenManagedRepositoryService
66 {
67     @Path( "" )
68     @GET
69     @Produces( {APPLICATION_JSON} )
70     @RedbackAuthorization( permissions = OPERATION_MANAGE_CONFIGURATION )
71     @Operation( summary = "Returns all managed repositories.",
72         parameters = {
73             @Parameter( name = "q", description = "Search term" ),
74             @Parameter( name = "offset", description = "The offset of the first element returned" ),
75             @Parameter( name = "limit", description = "Maximum number of items to return in the response" ),
76             @Parameter( name = "orderBy", description = "List of attribute used for sorting (key, value)" ),
77             @Parameter( name = "order", description = "The sort order. Either ascending (asc) or descending (desc)" )
78         },
79         security = {
80             @SecurityRequirement(
81                 name = OPERATION_MANAGE_CONFIGURATION
82             )
83         },
84         responses = {
85             @ApiResponse( responseCode = "200",
86                 description = "If the list could be returned",
87                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = PagedResult.class ) )
88             ),
89             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
90                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
91         }
92     )
93     PagedResult<MavenManagedRepository> getManagedRepositories(
94         @QueryParam( "q" ) @DefaultValue( "" ) String searchTerm,
95         @QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
96         @QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
97         @QueryParam( "orderBy" ) @DefaultValue( "id" ) List<String> orderBy,
98         @QueryParam( "order" ) @DefaultValue( "asc" ) String order )
99         throws ArchivaRestServiceException;
100
101
102     @Path( "{id}" )
103     @GET
104     @Produces( {MediaType.APPLICATION_JSON} )
105     @RedbackAuthorization(
106         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_READ_REPOSITORY},
107         resource = "{id}"
108     )
109     @Operation( summary = "Returns the managed repository with the given id.",
110         security = {
111             @SecurityRequirement(
112                 name = OPERATION_MANAGE_CONFIGURATION
113             ),
114             @SecurityRequirement(
115                 name = OPERATION_READ_REPOSITORY,
116                 scopes = "{id}"
117             )
118         },
119         responses = {
120             @ApiResponse( responseCode = "200",
121                 description = "If the managed repository could be returned",
122                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
123             ),
124             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
125                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
126             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
127                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
128         }
129     )
130     MavenManagedRepository getManagedRepository( @PathParam( "id" ) String repositoryId )
131         throws ArchivaRestServiceException;
132
133
134     @Path( "{id}" )
135     @DELETE
136     @Produces( {MediaType.APPLICATION_JSON} )
137     @RedbackAuthorization(
138         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_REPOSITORY },
139         resource = "{id}"
140     )
141     @Operation( summary = "Deletes the managed repository with the given id.",
142         security = {
143             @SecurityRequirement(
144                 name = OPERATION_MANAGE_CONFIGURATION
145             ),
146             @SecurityRequirement(
147                 name = OPERATION_DELETE_REPOSITORY,
148                 scopes = "{id}"
149             )
150         },
151         responses = {
152             @ApiResponse( responseCode = "200",
153                 description = "If the managed repository could be returned"
154             ),
155             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
156                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
157             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
158                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
159         }
160     )
161     Response deleteManagedRepository( @PathParam( "id" ) String repositoryId,
162                                       @QueryParam( "deleteContent" ) boolean deleteContent )
163         throws ArchivaRestServiceException;
164
165
166     @Path( "" )
167     @POST
168     @Consumes( {MediaType.APPLICATION_JSON} )
169     @Produces( {MediaType.APPLICATION_JSON} )
170     @RedbackAuthorization(
171         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_ADD_REPOSITORY },
172         resource = "{id}"
173     )
174     @Operation( summary = "Creates the managed repository",
175         security = {
176             @SecurityRequirement(
177                 name = OPERATION_MANAGE_CONFIGURATION
178             ),
179             @SecurityRequirement(
180                 name = OPERATION_ADD_REPOSITORY,
181                 scopes = "{id}"
182             )
183         },
184         responses = {
185             @ApiResponse( responseCode = "201",
186                 description = "If the managed repository could be created",
187                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
188             ),
189             @ApiResponse( responseCode = "303", description = "The repository exists already",
190                 headers = {
191                     @Header( name = "Location", description = "The URL of existing repository ", schema = @Schema( type = "string" ) )
192                 }
193             ),
194             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
195                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
196             @ApiResponse( responseCode = "422", description = "The body data is not valid",
197                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
198         }
199     )
200     MavenManagedRepository addManagedRepository( MavenManagedRepository managedRepository )
201         throws ArchivaRestServiceException;
202
203
204     @Path( "{id}" )
205     @PUT
206     @Consumes( {MediaType.APPLICATION_JSON} )
207     @Produces( {MediaType.APPLICATION_JSON} )
208     @RedbackAuthorization(
209         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_EDIT_REPOSITORY },
210         resource = "{id}"
211     )
212     @Operation( summary = "Updates the managed repository with the given id",
213         security = {
214             @SecurityRequirement(
215                 name = OPERATION_MANAGE_CONFIGURATION
216             ),
217             @SecurityRequirement(
218                 name = OPERATION_EDIT_REPOSITORY,
219                 scopes = "{id}"
220             )
221         },
222         responses = {
223             @ApiResponse( responseCode = "200",
224                 description = "If the managed repository could be updated",
225                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = MavenManagedRepository.class ) )
226             ),
227             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
228                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
229             @ApiResponse( responseCode = "422", description = "The body data is not valid",
230                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
231             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist",
232                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
233         }
234     )
235     MavenManagedRepository updateManagedRepository( @PathParam( "id" ) String repositoryId,  MavenManagedRepositoryUpdate managedRepository )
236         throws ArchivaRestServiceException;
237
238
239     @Path( "{id}/path/{filePath: .+}" )
240     @GET
241     @Produces( {MediaType.APPLICATION_JSON} )
242     @RedbackAuthorization(
243         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_READ_REPOSITORY},
244         resource = "{id}"
245     )
246     @Operation( summary = "Returns the status of a given file in the repository",
247         security = {
248             @SecurityRequirement(
249                 name = OPERATION_MANAGE_CONFIGURATION
250             ),
251             @SecurityRequirement(
252                 name = OPERATION_READ_REPOSITORY,
253                 scopes = "{id}"
254             )
255
256         },
257         responses = {
258             @ApiResponse( responseCode = "200",
259                 description = "If the file status is returned",
260                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = FileInfo.class ) )
261             ),
262             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to add repositories",
263                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
264             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the file does not exist.",
265                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
266         }
267     )
268     FileInfo getFileStatus( @PathParam( "id" ) String repositoryId, @PathParam( "filePath" ) String fileLocation )
269         throws ArchivaRestServiceException;
270
271
272     /**
273      * Permissions are checked in impl
274      * will copy an artifact from the source repository to the target repository
275      */
276     @Path ("{srcId}/path/{path: .+}/copyto/{dstId}")
277     @POST
278     @Produces({APPLICATION_JSON})
279     @RedbackAuthorization (noPermission = true)
280     @Operation( summary = "Copies a artifact from the source repository to the destination repository",
281         security = {
282             @SecurityRequirement(
283                 name = OPERATION_READ_REPOSITORY,
284                 scopes = {
285                     "{srcId}"
286                 }
287             ),
288             @SecurityRequirement(
289                 name= OPERATION_ADD_ARTIFACT,
290                 scopes = {
291                     "{dstId}"
292                 }
293             )
294
295         },
296         responses = {
297             @ApiResponse( responseCode = "200",
298                 description = "If the artifact was copied"
299             ),
300             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
301                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
302             @ApiResponse( responseCode = "404", description = "The repository does not exist, or if the artifact was not found",
303                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
304         }
305     )
306     Response copyArtifact( @PathParam( "srcId" ) String srcRepositoryId, @PathParam( "dstId" ) String dstRepositoryId,
307                            @PathParam( "path" ) String path )
308         throws ArchivaRestServiceException;
309
310
311     @Path ("{id}/path/{path: .+}")
312     @DELETE
313     @Consumes ({ APPLICATION_JSON })
314     @RedbackAuthorization (
315         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_ARTIFACT },
316         resource = "{id}"
317     )
318     @Operation( summary = "Deletes a artifact in the repository.",
319         security = {
320             @SecurityRequirement(
321                 name = OPERATION_MANAGE_CONFIGURATION
322             ),
323             @SecurityRequirement(
324                 name = OPERATION_DELETE_ARTIFACT,
325                 scopes = "{id}"
326             )
327
328         },
329         responses = {
330             @ApiResponse( responseCode = "200",
331                 description = "If the artifact was deleted"
332             ),
333             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
334                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
335             @ApiResponse( responseCode = "404", description = "The repository or the artifact does not exist",
336                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
337         }
338     )
339     Response deleteArtifact( @PathParam( "id" ) String repositoryId, @PathParam( "path" ) String path )
340         throws ArchivaRestServiceException;
341
342     @Path ( "{id}/co/{group}/{project}/{version}" )
343     @DELETE
344     @Produces ({ MediaType.APPLICATION_JSON })
345     @RedbackAuthorization (
346         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_VERSION},
347         resource = "{id}"
348     )
349     @Operation( summary = "Removes a version tree in the repository",
350         security = {
351             @SecurityRequirement(
352                 name = OPERATION_MANAGE_CONFIGURATION
353             ),
354             @SecurityRequirement(
355                 name = OPERATION_DELETE_VERSION,
356                 scopes = "{id}"
357             )
358
359         },
360         responses = {
361             @ApiResponse( responseCode = "200",
362                 description = "If the deletion was successful"
363             ),
364             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete in repositories",
365                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
366             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the version does not exist.",
367                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
368         }
369     )
370     Response removeProjectVersion( @PathParam ( "id" ) String repositoryId,
371                                    @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId,
372                                    @PathParam ( "version" ) String version )
373         throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
374
375
376     @Path ( "{id}/co/{group}/{project}" )
377     @DELETE
378     @Produces ({ MediaType.APPLICATION_JSON })
379     @RedbackAuthorization (noPermission = true)
380     @Operation( summary = "Removes a project tree in the repository",
381         security = {
382             @SecurityRequirement(
383                 name = OPERATION_MANAGE_CONFIGURATION
384             ),
385             @SecurityRequirement(
386                 name = OPERATION_DELETE_PROJECT,
387                 scopes = "{id}"
388             )
389
390         },
391         responses = {
392             @ApiResponse( responseCode = "200",
393                 description = "If the deletion was successful"
394             ),
395             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete in repositories",
396                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
397             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the project does not exist.",
398                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
399         }
400     )
401     Response deleteProject( @PathParam ("id") String repositoryId, @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId )
402         throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
403
404     @Path ( "{id}/co/{namespace}" )
405     @DELETE
406     @Produces ({ MediaType.APPLICATION_JSON })
407     @RedbackAuthorization (
408         permissions = { OPERATION_MANAGE_CONFIGURATION, OPERATION_DELETE_NAMESPACE },
409         resource = "{id}"
410     )
411     @Operation( summary = "Removes a namespace tree in the repository",
412         security = {
413             @SecurityRequirement(
414                 name = OPERATION_MANAGE_CONFIGURATION
415             ),
416             @SecurityRequirement(
417                 name = OPERATION_DELETE_NAMESPACE,
418                 scopes = "{id}"
419             )
420         },
421         responses = {
422             @ApiResponse( responseCode = "200",
423                 description = "If the deletion was successful"
424             ),
425             @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete namespaces in repositories",
426                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
427             @ApiResponse( responseCode = "404", description = "The managed repository with this id does not exist. Or the namespace does not exist.",
428                 content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
429         }
430     )
431     Response deleteNamespace( @PathParam ("id") String repositoryId, @PathParam ( "namespace" ) String namespace )
432         throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
433
434 }