@Test @ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) public void testDownloadPackage(@PypiTestRepository(repositoryId = REPOSITORY_RELEASES, storageId = REPOSITORY_STORAGE) Repository repository, @PypiTestArtifact(repositoryId = REPOSITORY_RELEASES, storageId = REPOSITORY_STORAGE, id = "hello_world_pypi", versions = { "1.0", "2.0", "3.0", "3.1", "3.2", "3.4", "5.1" }) List<Path> packagePaths) throws IOException { final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); final String invalidPackageName = "helloworldpypi"; final String packageNameNotUploaded = "helloworldpypi-1.0-py3-none-any.whl"; final String url = getContextBaseUrl() + "/storages/{storageId}/{repositoryId}/packages/{packageName}"; mockMvc.when() .get(url, storageId, repositoryId, invalidPackageName) .then() .log() .all() .statusCode(HttpStatus.BAD_REQUEST.value()); mockMvc.when() .get(url, storageId, repositoryId, packageNameNotUploaded) .then() .log() .all() .statusCode(HttpStatus.NOT_FOUND.value()); packagePaths.stream().forEach(path -> { long size; try { size = Files.size(path.normalize()); } catch (IOException e) { throw new RuntimeException(e); } mockMvc.when() .get(url, storageId, repositoryId, path.getFileName().toString()) .then() .log() .status() .log() .headers() .statusCode(HttpStatus.OK.value()) .contentType(MediaType.APPLICATION_OCTET_STREAM_VALUE) .header(HttpHeaders.CONTENT_LENGTH, Matchers.equalTo(String.valueOf(size))); }); }
@ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) public ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository, @PathVariable(name = "packageName") String packageName, HttpServletRequest request) { logger.info("install package request for storageId -> [{}] , repositoryId -> [{}], packageName -> [{}]", repository.getStorage().getId(), repository.getId(), packageName); final Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("storageId", repository.getStorage().getId()); uriVariables.put("repositoryId", repository.getId()); uriVariables.put("packageName", packageName); final URI location = ServletUriComponentsBuilder .fromCurrentServletMapping() .path("/storages/{storageId}/{repositoryId}/simple/{packageName}/") .build() .expand(uriVariables) .toUri(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return ResponseEntity.status(HttpStatus.SEE_OTHER) .headers(headers) .body(HttpStatus.SEE_OTHER.getReasonPhrase()); }
PypiArtifactController extends BaseArtifactController { @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) public ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository, @PathVariable(name = "packageName") String packageName, HttpServletRequest request) { logger.info("install package request for storageId -> [{}] , repositoryId -> [{}], packageName -> [{}]", repository.getStorage().getId(), repository.getId(), packageName); final Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("storageId", repository.getStorage().getId()); uriVariables.put("repositoryId", repository.getId()); uriVariables.put("packageName", packageName); final URI location = ServletUriComponentsBuilder .fromCurrentServletMapping() .path("/storages/{storageId}/{repositoryId}/simple/{packageName}/") .build() .expand(uriVariables) .toUri(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return ResponseEntity.status(HttpStatus.SEE_OTHER) .headers(headers) .body(HttpStatus.SEE_OTHER.getReasonPhrase()); } }
PypiArtifactController extends BaseArtifactController { @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) public ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository, @PathVariable(name = "packageName") String packageName, HttpServletRequest request) { logger.info("install package request for storageId -> [{}] , repositoryId -> [{}], packageName -> [{}]", repository.getStorage().getId(), repository.getId(), packageName); final Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("storageId", repository.getStorage().getId()); uriVariables.put("repositoryId", repository.getId()); uriVariables.put("packageName", packageName); final URI location = ServletUriComponentsBuilder .fromCurrentServletMapping() .path("/storages/{storageId}/{repositoryId}/simple/{packageName}/") .build() .expand(uriVariables) .toUri(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return ResponseEntity.status(HttpStatus.SEE_OTHER) .headers(headers) .body(HttpStatus.SEE_OTHER.getReasonPhrase()); }  }
PypiArtifactController extends BaseArtifactController { @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) public ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository, @PathVariable(name = "packageName") String packageName, HttpServletRequest request) { logger.info("install package request for storageId -> [{}] , repositoryId -> [{}], packageName -> [{}]", repository.getStorage().getId(), repository.getId(), packageName); final Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("storageId", repository.getStorage().getId()); uriVariables.put("repositoryId", repository.getId()); uriVariables.put("packageName", packageName); final URI location = ServletUriComponentsBuilder .fromCurrentServletMapping() .path("/storages/{storageId}/{repositoryId}/simple/{packageName}/") .build() .expand(uriVariables) .toUri(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return ResponseEntity.status(HttpStatus.SEE_OTHER) .headers(headers) .body(HttpStatus.SEE_OTHER.getReasonPhrase()); }  @ApiOperation(value = "This end point will be used to upload/deploy python package.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "python package was deployed successfully."), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @RequestMapping(path = "/{storageId}/{repositoryId}", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA) ResponseEntity<String> uploadPackage(
                                                @RepositoryMapping Repository repository,
                                                @RequestPart(name = "comment", required = false) String comment,
                                                @RequestPart(name = "metadata_version", required = true) String metadataVersion,
                                                @RequestPart(name = "filetype", required = true) String filetype,
                                                @RequestPart(name = "protcol_version", required = false) String protcolVersion,
                                                @RequestPart(name = "author", required = false) String author,
                                                @RequestPart(name = "home_page", required = false) String homePage,
                                                @RequestPart(name = "download_url", required = false) String downloadUrl,
                                                @RequestPart(name = "platform", required = false) String platform,
                                                @RequestPart(name = "version", required = false) String version,
                                                @RequestPart(name = "description", required = false) String description,
                                                @RequestPart(name = "md5_digest", required = false) String md5Digest,
                                                @RequestPart(name = ":action", required = true) String action,
                                                @RequestPart(name = "name", required = true) String name,
                                                @RequestPart(name = "license", required = false) String license,
                                                @RequestPart(name = "pyversion", required = false) String pyversion,
                                                @RequestPart(name = "summary", required = false) String summary,
                                                @RequestPart(name = "author_email", required = false) String authorEmail,
                                                @RequestPart(name = "content", required = true) MultipartFile file,
                                                HttpServletRequest request); @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository,
                                                  @PathVariable(name = "packageName") String packageName,
                                                  HttpServletRequest request); @ApiOperation(value = "This Endpoint will be used to retreive pypi artifact/.whl file") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/packages/{artifactName}", method = RequestMethod.GET) void downloadPackage(@RepositoryMapping Repository repository,
                                @PathVariable(name = "artifactName") String artifactName,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                @RequestHeader HttpHeaders headers); @ApiOperation(value = "This Endpoint will be used to retreive all the versions of packages present in artifactory.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/simple/{packageName}", method = RequestMethod.GET, produces = MediaType.TEXT_HTML) ResponseEntity<String> browsePackage(@RepositoryMapping Repository repository,
                                                @PathVariable(name = "packageName") String packageName,
                                                HttpServletRequest request,
                                                HttpServletResponse response,
                                                @RequestHeader HttpHeaders headers); }
PypiArtifactController extends BaseArtifactController { @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) public ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository, @PathVariable(name = "packageName") String packageName, HttpServletRequest request) { logger.info("install package request for storageId -> [{}] , repositoryId -> [{}], packageName -> [{}]", repository.getStorage().getId(), repository.getId(), packageName); final Map<String, String> uriVariables = new HashMap<String, String>(); uriVariables.put("storageId", repository.getStorage().getId()); uriVariables.put("repositoryId", repository.getId()); uriVariables.put("packageName", packageName); final URI location = ServletUriComponentsBuilder .fromCurrentServletMapping() .path("/storages/{storageId}/{repositoryId}/simple/{packageName}/") .build() .expand(uriVariables) .toUri(); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return ResponseEntity.status(HttpStatus.SEE_OTHER) .headers(headers) .body(HttpStatus.SEE_OTHER.getReasonPhrase()); }  @ApiOperation(value = "This end point will be used to upload/deploy python package.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "python package was deployed successfully."), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @RequestMapping(path = "/{storageId}/{repositoryId}", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA) ResponseEntity<String> uploadPackage(
                                                @RepositoryMapping Repository repository,
                                                @RequestPart(name = "comment", required = false) String comment,
                                                @RequestPart(name = "metadata_version", required = true) String metadataVersion,
                                                @RequestPart(name = "filetype", required = true) String filetype,
                                                @RequestPart(name = "protcol_version", required = false) String protcolVersion,
                                                @RequestPart(name = "author", required = false) String author,
                                                @RequestPart(name = "home_page", required = false) String homePage,
                                                @RequestPart(name = "download_url", required = false) String downloadUrl,
                                                @RequestPart(name = "platform", required = false) String platform,
                                                @RequestPart(name = "version", required = false) String version,
                                                @RequestPart(name = "description", required = false) String description,
                                                @RequestPart(name = "md5_digest", required = false) String md5Digest,
                                                @RequestPart(name = ":action", required = true) String action,
                                                @RequestPart(name = "name", required = true) String name,
                                                @RequestPart(name = "license", required = false) String license,
                                                @RequestPart(name = "pyversion", required = false) String pyversion,
                                                @RequestPart(name = "summary", required = false) String summary,
                                                @RequestPart(name = "author_email", required = false) String authorEmail,
                                                @RequestPart(name = "content", required = true) MultipartFile file,
                                                HttpServletRequest request); @ApiOperation(value = "This Endpoint will be used for download/install pypi package") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_SEE_OTHER, message = "See Other Location"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/{packageName}", method = RequestMethod.GET) ResponseEntity<String> downloadPackage(@RepositoryMapping Repository repository,
                                                  @PathVariable(name = "packageName") String packageName,
                                                  HttpServletRequest request); @ApiOperation(value = "This Endpoint will be used to retreive pypi artifact/.whl file") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/packages/{artifactName}", method = RequestMethod.GET) void downloadPackage(@RepositoryMapping Repository repository,
                                @PathVariable(name = "artifactName") String artifactName,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                @RequestHeader HttpHeaders headers); @ApiOperation(value = "This Endpoint will be used to retreive all the versions of packages present in artifactory.") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Request Url Not Found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "An error occurred while executing download request."), @ApiResponse(code = HttpURLConnection.HTTP_UNAVAILABLE, message = "Service Unavailable.") }) @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "/{storageId}/{repositoryId}/simple/{packageName}", method = RequestMethod.GET, produces = MediaType.TEXT_HTML) ResponseEntity<String> browsePackage(@RepositoryMapping Repository repository,
                                                @PathVariable(name = "packageName") String packageName,
                                                HttpServletRequest request,
                                                HttpServletResponse response,
                                                @RequestHeader HttpHeaders headers);  }