Skip to content

Commit

Permalink
Merge pull request strongbox#1675 from anki2189/issue-1664
Browse files Browse the repository at this point in the history
Out of Service Repository Handling
  • Loading branch information
steve-todorov committed Feb 11, 2020
2 parents 6fdc2b4 + 2c54b38 commit 6a8cad0
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,11 @@ public ResponseEntity addOrUpdateRepository(@ApiParam(value = "The storageId", r
}

@ApiOperation(value = "Returns the configuration of a repository.")
@ApiResponses(value = { @ApiResponse(code = 200,
message = "The repository was updated successfully.",
response = RepositoryDto.class),
@ApiResponse(code = 404,
message = "The repository ${storageId}:${repositoryId} was not found!") })
@ApiResponses(value = { @ApiResponse(code = 200, message = "The repository was updated successfully.", response = RepositoryDto.class),
@ApiResponse(code = 404, message = "The repository ${storageId}:${repositoryId} was not found!") })
@PreAuthorize("hasAuthority('CONFIGURATION_VIEW_REPOSITORY')")
@GetMapping(value = "/{storageId}/{repositoryId}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity getRepositoryResponseEntity(@RepositoryMapping Repository repository)
public ResponseEntity getRepositoryResponseEntity(@RepositoryMapping(allowOutOfServiceRepository = true) Repository repository)
{
return ResponseEntity.ok(repository);
}
Expand All @@ -305,7 +302,7 @@ public ResponseEntity getRepositoryResponseEntity(@RepositoryMapping Repository
@PreAuthorize("hasAuthority('CONFIGURATION_DELETE_REPOSITORY')")
@DeleteMapping(value = "/{storageId}/{repositoryId}", produces = { MediaType.TEXT_PLAIN_VALUE,
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity removeRepository(@RepositoryMapping Repository repository,
public ResponseEntity removeRepository(@RepositoryMapping(allowOutOfServiceRepository = true) Repository repository,
@ApiParam(value = "Whether to force delete the repository from the file system")
@RequestParam(name = "force", defaultValue = "false") final boolean force,
@RequestHeader(HttpHeaders.ACCEPT) String accept)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
String storageVariableName() default "storageId";

String repositoryVariableName() default "repositoryId";

boolean allowOutOfServiceRepository() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ public Object resolveArgument(final MethodParameter parameter,
throw new RepositoryNotFoundException(message);
}

final boolean inService = repository.isInService();
if (!inService)
// This annotation is used in a lot of controllers - some of which are related to the configuration management.
// It is necessary to allow requests to pass when the repository status is `out of service` (i.e. `/api/configuration/**`),
// but still return `ServiceUnavailableException` when people are accessing `/storages/**`.
if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository())
{
final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId);
throw new ServiceUnavailableException(message);
Expand Down Expand Up @@ -147,4 +149,4 @@ private Repository getRepository(final String storageId,
return storage.getRepository(repositoryId);
}

}
}
Loading

0 comments on commit 6a8cad0

Please sign in to comment.