Skip to content

Commit

Permalink
adjustments to review of pull request:
Browse files Browse the repository at this point in the history
- renamed XmlRootElement name of ApiKeyDTO
- renamed postApiKey() to createApiKey()
- added exceptions to throw clause
- rewrote conditional operator to if-else-statement
  • Loading branch information
akomii committed Jul 11, 2024
1 parent 8ca076c commit 80f6e6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @author [email protected]
*/
@XmlRootElement(name = "apiKeyCred")
@XmlRootElement(name = "ApiKeyCred")
public class ApiKeyDTO {

private String apiKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private String convertPropertiesToString(Properties props) {
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response postApiKey(ApiKeyDTO apiKeyDTO) {
public Response createApiKey(ApiKeyDTO apiKeyDTO) {
String apiKey = apiKeyDTO.getApiKey();
String clientDn = apiKeyDTO.getClientDn();
if (apiKey == null || clientDn == null) {
Expand Down Expand Up @@ -147,4 +147,4 @@ private Response setApiKeyStatus(String apiKey, ApiKeyStatus status) {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ private Path getPropertiesPath() {
* @throws IllegalArgumentException If the API key already exists.
* @throws IllegalStateException If the PropertyFileAPIKeys instance is not initialized.
*/
public void addNewApiKeyAndUpdatePropertiesFile(String apiKey, String clientDn) throws IOException {
public void addNewApiKeyAndUpdatePropertiesFile(String apiKey, String clientDn)
throws IOException, IllegalArgumentException, IllegalStateException {
checkKeysInitialized();
Properties properties = keys.getProperties();
if (properties.containsKey(apiKey)) {
Expand All @@ -90,7 +91,8 @@ public void addNewApiKeyAndUpdatePropertiesFile(String apiKey, String clientDn)
* @throws SecurityException If an attempt is made to modify an admin API key.
* @throws IllegalStateException If the PropertyFileAPIKeys instance is not initialized.
*/
public void setStateOfApiKeyAndUpdatePropertiesFile(String apiKey, ApiKeyStatus status) throws IOException {
public void setStateOfApiKeyAndUpdatePropertiesFile(String apiKey, ApiKeyStatus status)
throws IOException, NoSuchElementException, SecurityException, IllegalStateException {
checkKeysInitialized();
Properties properties = keys.getProperties();
if (!properties.containsKey(apiKey)) {
Expand Down Expand Up @@ -130,7 +132,11 @@ private String setStatusInClientDn(String clientDn, ApiKeyStatus status) {
case ACTIVE:
return clientDn.replace("," + ApiKeyStatus.INACTIVE.name(), "");
case INACTIVE:
return clientDn.endsWith(ApiKeyStatus.INACTIVE.name()) ? clientDn : clientDn + "," + ApiKeyStatus.INACTIVE.name();
if (clientDn.endsWith(ApiKeyStatus.INACTIVE.name())) {
return clientDn;
} else {
return clientDn + "," + ApiKeyStatus.INACTIVE.name();
}
default:
throw new IllegalArgumentException("Unknown status: " + status.name());
}
Expand Down

0 comments on commit 80f6e6c

Please sign in to comment.