You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryService.java 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package org.apache.archiva.rest.api.services.v2;
  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. import io.swagger.v3.oas.annotations.Operation;
  20. import io.swagger.v3.oas.annotations.Parameter;
  21. import io.swagger.v3.oas.annotations.media.Content;
  22. import io.swagger.v3.oas.annotations.media.Schema;
  23. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  24. import io.swagger.v3.oas.annotations.security.SecurityRequirement;
  25. import io.swagger.v3.oas.annotations.tags.Tag;
  26. import org.apache.archiva.components.rest.model.PagedResult;
  27. import org.apache.archiva.redback.authorization.RedbackAuthorization;
  28. import org.apache.archiva.rest.api.model.v2.Artifact;
  29. import org.apache.archiva.rest.api.model.v2.ArtifactTransferRequest;
  30. import org.apache.archiva.rest.api.model.v2.Repository;
  31. import org.apache.archiva.rest.api.model.v2.RepositoryStatistics;
  32. import org.apache.archiva.rest.api.model.v2.ScanStatus;
  33. import org.apache.archiva.security.common.ArchivaRoleConstants;
  34. import javax.ws.rs.Consumes;
  35. import javax.ws.rs.DELETE;
  36. import javax.ws.rs.DefaultValue;
  37. import javax.ws.rs.GET;
  38. import javax.ws.rs.POST;
  39. import javax.ws.rs.Path;
  40. import javax.ws.rs.PathParam;
  41. import javax.ws.rs.Produces;
  42. import javax.ws.rs.QueryParam;
  43. import javax.ws.rs.core.MediaType;
  44. import javax.ws.rs.core.Response;
  45. import java.util.List;
  46. import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
  47. import static org.apache.archiva.rest.api.services.v2.RestConfiguration.DEFAULT_PAGE_LIMIT;
  48. /**
  49. * @author Martin Stockhammer <martin_s@apache.org>
  50. * @since 3.0
  51. */
  52. @Path( "repositories" )
  53. @Tag(name = "v2")
  54. @Tag(name = "v2/Repositories")
  55. @Schema(name="RepositoryService",description = "Manage repositories of all types")
  56. public interface RepositoryService
  57. {
  58. @Path( "" )
  59. @GET
  60. @Produces( {APPLICATION_JSON} )
  61. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  62. @Operation( summary = "Returns all managed repositories.",
  63. parameters = {
  64. @Parameter( name = "q", description = "Search term" ),
  65. @Parameter( name = "offset", description = "The offset of the first element returned" ),
  66. @Parameter( name = "limit", description = "Maximum number of items to return in the response" ),
  67. @Parameter( name = "orderBy", description = "List of attribute used for sorting (key, value)" ),
  68. @Parameter( name = "order", description = "The sort order. Either ascending (asc) or descending (desc)" ),
  69. @Parameter( name = "locale", description = "The locale for name and description" )
  70. },
  71. security = {
  72. @SecurityRequirement(
  73. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  74. )
  75. },
  76. responses = {
  77. @ApiResponse( responseCode = "200",
  78. description = "If the list could be returned",
  79. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = PagedResult.class ) )
  80. ),
  81. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  82. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  83. }
  84. )
  85. PagedResult<Repository> getRepositories( @QueryParam( "q" ) @DefaultValue( "" ) String searchTerm,
  86. @QueryParam( "offset" ) @DefaultValue( "0" ) Integer offset,
  87. @QueryParam( "limit" ) @DefaultValue( value = DEFAULT_PAGE_LIMIT ) Integer limit,
  88. @QueryParam( "orderBy" ) @DefaultValue( "id" ) List<String> orderBy,
  89. @QueryParam( "order" ) @DefaultValue( "asc" ) String order,
  90. @QueryParam( "locale" ) String localeString) throws ArchivaRestServiceException;
  91. @Path( "managed/{id}/statistics" )
  92. @GET
  93. @Produces( {APPLICATION_JSON} )
  94. @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
  95. @Operation( summary = "Returns repository statistic data.",
  96. security = {
  97. @SecurityRequirement(
  98. name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
  99. )
  100. },
  101. responses = {
  102. @ApiResponse( responseCode = "200",
  103. description = "If the statistics could be returned",
  104. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryStatistics.class ) )
  105. ),
  106. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  107. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  108. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  109. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  110. }
  111. )
  112. RepositoryStatistics getManagedRepositoryStatistics( @PathParam( "id" ) String repositoryId )
  113. throws ArchivaRestServiceException;
  114. @Path ("managed/{id}/scan/schedule")
  115. @POST
  116. @Produces ({ APPLICATION_JSON })
  117. @Consumes({ APPLICATION_JSON })
  118. @RedbackAuthorization (permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER)
  119. @Operation( summary = "Returns repository statistic data.",
  120. security = {
  121. @SecurityRequirement(
  122. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  123. )
  124. },
  125. responses = {
  126. @ApiResponse( responseCode = "200",
  127. description = "If the statistics could be returned"
  128. ),
  129. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  130. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  131. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  132. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  133. }
  134. )
  135. Response scheduleRepositoryScan( @PathParam ("id") String repositoryId,
  136. @QueryParam ("fullScan") boolean fullScan )
  137. throws ArchivaRestServiceException;
  138. @Path ("managed/{id}/scan/now")
  139. @POST
  140. @Produces ({ APPLICATION_JSON })
  141. @Consumes({ APPLICATION_JSON })
  142. @RedbackAuthorization (permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER)
  143. @Operation( summary = "Runs a repository scan instantly and waits for the response.",
  144. security = {
  145. @SecurityRequirement(
  146. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  147. )
  148. },
  149. responses = {
  150. @ApiResponse( responseCode = "200",
  151. description = "If the statistics could be returned",
  152. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = RepositoryStatistics.class ) )
  153. ),
  154. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  155. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  156. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  157. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  158. }
  159. )
  160. RepositoryStatistics scanRepositoryImmediately( @PathParam ("id") String repositoryId )
  161. throws ArchivaRestServiceException;
  162. /**
  163. * Returns the scan status of the given repository
  164. * @param repositoryId the repository identifier
  165. * @return the status
  166. * @throws ArchivaRestServiceException
  167. * @since 3.0
  168. */
  169. @Path ("managed/{id}/scan/status")
  170. @GET
  171. @Produces ({ APPLICATION_JSON })
  172. @RedbackAuthorization (permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER)
  173. @Operation( summary = "Returns status of running and scheduled scans.",
  174. security = {
  175. @SecurityRequirement(
  176. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  177. )
  178. },
  179. responses = {
  180. @ApiResponse( responseCode = "200",
  181. description = "If the status could be returned",
  182. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ScanStatus.class ) )
  183. ),
  184. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  185. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  186. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  187. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  188. }
  189. )
  190. ScanStatus getScanStatus( @PathParam ("id") String repositoryId )
  191. throws ArchivaRestServiceException;
  192. @Path ("managed/{id}/scan")
  193. @DELETE
  194. @Produces ({ APPLICATION_JSON })
  195. @RedbackAuthorization (permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER)
  196. @Operation( summary = "Removes a scan task from the queue.",
  197. security = {
  198. @SecurityRequirement(
  199. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  200. )
  201. },
  202. responses = {
  203. @ApiResponse( responseCode = "200",
  204. description = "If the task was removed successfully"
  205. ),
  206. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  207. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  208. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  209. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  210. }
  211. )
  212. Response removeScanningTaskFromQueue( @PathParam ("id") String repositoryId )
  213. throws ArchivaRestServiceException;
  214. /**
  215. * permissions are checked in impl
  216. * will copy an artifact from the source repository to the target repository
  217. */
  218. @Path ("managed/{id}/artifact/copy")
  219. @POST
  220. @Produces({APPLICATION_JSON})
  221. @Consumes({ APPLICATION_JSON })
  222. @RedbackAuthorization (noPermission = true)
  223. @Operation( summary = "Copies a artifact between repositories.",
  224. security = {
  225. @SecurityRequirement(
  226. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  227. )
  228. },
  229. responses = {
  230. @ApiResponse( responseCode = "200",
  231. description = "If the artifact was copied"
  232. ),
  233. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  234. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  235. @ApiResponse( responseCode = "404", description = "The repository does not exist, or if the artifact was not found",
  236. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  237. }
  238. )
  239. Response copyArtifact( ArtifactTransferRequest artifactTransferRequest )
  240. throws ArchivaRestServiceException;
  241. @Path ("managed/{id}/index/download/start")
  242. @POST
  243. @Produces ({ APPLICATION_JSON })
  244. @Consumes({ APPLICATION_JSON })
  245. @RedbackAuthorization (permissions = ArchivaRoleConstants.OPERATION_RUN_INDEXER)
  246. @Operation( summary = "Schedules a task for remote index download.",
  247. security = {
  248. @SecurityRequirement(
  249. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  250. )
  251. },
  252. responses = {
  253. @ApiResponse( responseCode = "200",
  254. description = "If the task was scheduled"
  255. ),
  256. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  257. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  258. @ApiResponse( responseCode = "404", description = "The repository does not exist",
  259. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  260. }
  261. )
  262. Response scheduleDownloadRemoteIndex( @PathParam ("id") String repositoryId,
  263. @QueryParam ("now") boolean now,
  264. @QueryParam ("fullDownload") boolean fullDownload )
  265. throws ArchivaRestServiceException;
  266. @Path ("managed/{id}/artifact")
  267. @DELETE
  268. @Consumes ({ APPLICATION_JSON })
  269. @RedbackAuthorization (noPermission = true)
  270. @Operation( summary = "Deletes a artifact in the repository.",
  271. security = {
  272. @SecurityRequirement(
  273. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  274. )
  275. },
  276. responses = {
  277. @ApiResponse( responseCode = "200",
  278. description = "If the artifact was deleted"
  279. ),
  280. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  281. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
  282. @ApiResponse( responseCode = "404", description = "The repository or the artifact does not exist",
  283. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  284. }
  285. )
  286. Response deleteArtifact( Artifact artifact )
  287. throws ArchivaRestServiceException;
  288. @Path ("index_downloads")
  289. @GET
  290. @Produces ({ APPLICATION_JSON })
  291. @RedbackAuthorization (noPermission = true)
  292. @Operation( summary = "Returns a list of running downloads from the remote repository.",
  293. security = {
  294. @SecurityRequirement(
  295. name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
  296. )
  297. },
  298. responses = {
  299. @ApiResponse( responseCode = "200",
  300. description = "If the artifact was deleted"
  301. ),
  302. @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
  303. content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
  304. }
  305. )
  306. List<String> getRunningRemoteDownloads();
  307. }