-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for 7.4 API version (#701)
- Adds new constants for 7.4 API - Moves controller logic introduced by 7.3 API controllers to new common controllers - Adds new controllers for 7.4 API endpoint mappings - Adjusts converter API version mappings to include 7.4 API - Adds new unit and integration test cases covering the 7.4 API - Adds new end-to-end test cases covering the 7.4 API - Introduces random URI usage in integration tests to isolate test cases better - Removes 7.2 API variants of unnecessary end-to-end tests - Changes Lowkey Vault Client implementation to automatically use 7.4 API - Updates readme to mention the 7.4 API support #697 {minor} Signed-off-by: Esta Nagy <nagyesta@gmail.com>
- Loading branch information
Showing
86 changed files
with
5,958 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ain/java/com/github/nagyesta/lowkeyvault/controller/common/CommonKeyPolicyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.nagyesta.lowkeyvault.controller.common; | ||
|
||
import com.github.nagyesta.lowkeyvault.mapper.common.AliasAwareConverter; | ||
import com.github.nagyesta.lowkeyvault.mapper.common.registry.KeyConverterRegistry; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.key.KeyRotationPolicyModel; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.key.validator.Update; | ||
import com.github.nagyesta.lowkeyvault.service.key.KeyVaultFake; | ||
import com.github.nagyesta.lowkeyvault.service.key.ReadOnlyRotationPolicy; | ||
import com.github.nagyesta.lowkeyvault.service.key.RotationPolicy; | ||
import com.github.nagyesta.lowkeyvault.service.key.id.KeyEntityId; | ||
import com.github.nagyesta.lowkeyvault.service.vault.VaultService; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.net.URI; | ||
|
||
@Slf4j | ||
public abstract class CommonKeyPolicyController extends BaseKeyController { | ||
|
||
public CommonKeyPolicyController(@NonNull final KeyConverterRegistry registry, @NonNull final VaultService vaultService) { | ||
super(registry, vaultService); | ||
} | ||
|
||
public ResponseEntity<KeyRotationPolicyModel> getRotationPolicy( | ||
@Valid @Pattern(regexp = NAME_PATTERN) final String keyName, | ||
final URI baseUri) { | ||
log.info("Received request to {} get rotation policy: {} using API version: {}", | ||
baseUri.toString(), keyName, apiVersion()); | ||
return getRotationPolicyResponseEntity(getVaultByUri(baseUri), entityId(baseUri, keyName), baseUri); | ||
} | ||
|
||
public ResponseEntity<KeyRotationPolicyModel> updateRotationPolicy( | ||
@Valid @Pattern(regexp = NAME_PATTERN) final String keyName, | ||
final URI baseUri, | ||
@NonNull @Valid @Validated(Update.class) final KeyRotationPolicyModel request) { | ||
log.info("Received request to {} update rotation policy: {} using API version: {}", | ||
baseUri.toString(), keyName, apiVersion()); | ||
final KeyEntityId keyEntityId = entityId(baseUri, keyName); | ||
request.setKeyEntityId(keyEntityId); | ||
final RotationPolicy rotationPolicy = registry().rotationPolicyEntityConverter(apiVersion()).convert(request); | ||
final KeyVaultFake keyVaultFake = getVaultByUri(baseUri); | ||
keyVaultFake.setRotationPolicy(rotationPolicy); | ||
return getRotationPolicyResponseEntity(keyVaultFake, keyEntityId, baseUri); | ||
} | ||
|
||
private ResponseEntity<KeyRotationPolicyModel> getRotationPolicyResponseEntity( | ||
final KeyVaultFake keyVaultFake, final KeyEntityId keyEntityId, final URI baseUri) { | ||
final ReadOnlyRotationPolicy policy = keyVaultFake.rotationPolicy(keyEntityId); | ||
final AliasAwareConverter<ReadOnlyRotationPolicy, KeyRotationPolicyModel> converter = registry() | ||
.rotationPolicyModelConverter(apiVersion()); | ||
return ResponseEntity.ok(converter.convert(policy, baseUri)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...b/nagyesta/lowkeyvault/controller/common/CommonPolicyAwareKeyBackupRestoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.github.nagyesta.lowkeyvault.controller.common; | ||
|
||
import com.github.nagyesta.lowkeyvault.mapper.common.registry.KeyConverterRegistry; | ||
import com.github.nagyesta.lowkeyvault.model.common.backup.KeyBackupList; | ||
import com.github.nagyesta.lowkeyvault.model.common.backup.KeyBackupModel; | ||
import com.github.nagyesta.lowkeyvault.model.v7_2.key.KeyVaultKeyModel; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.key.KeyRotationPolicyModel; | ||
import com.github.nagyesta.lowkeyvault.service.key.KeyVaultFake; | ||
import com.github.nagyesta.lowkeyvault.service.key.ReadOnlyRotationPolicy; | ||
import com.github.nagyesta.lowkeyvault.service.key.id.KeyEntityId; | ||
import com.github.nagyesta.lowkeyvault.service.vault.VaultService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.lang.NonNull; | ||
|
||
import java.net.URI; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public abstract class CommonPolicyAwareKeyBackupRestoreController extends CommonKeyBackupRestoreController { | ||
|
||
public CommonPolicyAwareKeyBackupRestoreController( | ||
@NonNull final KeyConverterRegistry registry, @NonNull final VaultService vaultService) { | ||
super(registry, vaultService); | ||
} | ||
|
||
@Override | ||
protected KeyBackupModel backupEntity(final KeyEntityId entityId) { | ||
final KeyBackupModel keyBackupModel = super.backupEntity(entityId); | ||
final KeyBackupList value = keyBackupModel.getValue(); | ||
final ReadOnlyRotationPolicy rotationPolicy = getVaultByUri(entityId.vault()).rotationPolicy(entityId); | ||
value.setKeyRotationPolicy(registry().rotationPolicyModelConverter(apiVersion()).convert(rotationPolicy, entityId.vault())); | ||
return keyBackupModel; | ||
} | ||
|
||
@Override | ||
protected KeyVaultKeyModel restoreEntity(final KeyBackupModel backupModel) { | ||
final KeyVaultKeyModel keyVaultKeyModel = super.restoreEntity(backupModel); | ||
final URI baseUri = getSingleBaseUri(backupModel); | ||
final String entityName = getSingleEntityName(backupModel); | ||
final KeyEntityId keyEntityId = entityId(baseUri, entityName); | ||
final KeyVaultFake vaultByUri = getVaultByUri(baseUri); | ||
final KeyRotationPolicyModel keyRotationPolicy = backupModel.getValue().getKeyRotationPolicy(); | ||
Optional.ofNullable(keyRotationPolicy) | ||
.map(r -> { | ||
r.setKeyEntityId(keyEntityId); | ||
return r; | ||
}) | ||
.map(r -> registry().rotationPolicyEntityConverter(apiVersion()).convert(r)) | ||
.ifPresent(vaultByUri::setRotationPolicy); | ||
return keyVaultKeyModel; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...a/com/github/nagyesta/lowkeyvault/controller/v7_4/CertificateBackupRestoreController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.nagyesta.lowkeyvault.controller.v7_4; | ||
|
||
import com.github.nagyesta.lowkeyvault.controller.common.CommonCertificateBackupRestoreController; | ||
import com.github.nagyesta.lowkeyvault.mapper.common.registry.CertificateConverterRegistry; | ||
import com.github.nagyesta.lowkeyvault.model.common.ApiConstants; | ||
import com.github.nagyesta.lowkeyvault.model.common.backup.CertificateBackupModel; | ||
import com.github.nagyesta.lowkeyvault.model.v7_3.certificate.KeyVaultCertificateModel; | ||
import com.github.nagyesta.lowkeyvault.service.vault.VaultService; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.DependsOn; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URI; | ||
|
||
import static com.github.nagyesta.lowkeyvault.model.common.ApiConstants.API_VERSION_7_4; | ||
import static com.github.nagyesta.lowkeyvault.model.common.ApiConstants.V_7_4; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
@Slf4j | ||
@RestController | ||
@Validated | ||
@DependsOn({"certificateBackupConverter", "certificateModelConverter"}) | ||
@Component("CertificateBackupRestoreControllerV74") | ||
public class CertificateBackupRestoreController extends CommonCertificateBackupRestoreController { | ||
|
||
@Autowired | ||
public CertificateBackupRestoreController( | ||
@NonNull final CertificateConverterRegistry registry, @NonNull final VaultService vaultService) { | ||
super(registry, vaultService); | ||
} | ||
|
||
@Override | ||
@PostMapping(value = {"/certificates/{certificateName}/backup", "/certificates/{certificateName}/backup/"}, | ||
params = API_VERSION_7_4, | ||
produces = APPLICATION_JSON_VALUE) | ||
public ResponseEntity<CertificateBackupModel> backup(@PathVariable @Valid @Pattern(regexp = NAME_PATTERN) final String certificateName, | ||
@RequestAttribute(name = ApiConstants.REQUEST_BASE_URI) final URI baseUri) { | ||
return super.backup(certificateName, baseUri); | ||
} | ||
|
||
@Override | ||
@PostMapping(value = {"/certificates/restore", "/certificates/restore/"}, | ||
params = API_VERSION_7_4, | ||
consumes = APPLICATION_JSON_VALUE, | ||
produces = APPLICATION_JSON_VALUE) | ||
public ResponseEntity<KeyVaultCertificateModel> restore(@RequestAttribute(name = ApiConstants.REQUEST_BASE_URI) final URI baseUri, | ||
@Valid @RequestBody final CertificateBackupModel certificateBackupModel) { | ||
return super.restore(baseUri, certificateBackupModel); | ||
} | ||
|
||
@Override | ||
protected String apiVersion() { | ||
return V_7_4; | ||
} | ||
} |
Oops, something went wrong.