From f0a7a4662ff1030bfb6e212143162bc61b613f9b Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Mon, 4 May 2020 11:53:40 -0700 Subject: [PATCH] Refactor data class field names to match the desired serialized JSON keys - the jackson lib in Spring Boot 2.2.1 serializes booleans like: isCertificateAuthority => certificate_authority - but this behavior will be changed in Spring Boot 2.2.4's jackson lib: https://github.com/FasterXML/jackson-module-kotlin/issues/80 - this commit makes the code work for both current & future versions of jackson lib --- .../DefaultCertificatesHandler.kt | 4 ++-- .../credentials/DefaultCredentialsHandler.kt | 4 ++-- .../credentials/RemoteCredentialsHandler.kt | 6 +++--- .../management/ManagementController.kt | 4 ++-- .../credential/CertificateCredentialValue.kt | 20 +++++++++---------- .../domain/CertificateCredentialVersion.kt | 6 +++--- .../services/CertificateDataService.kt | 4 ++-- .../services/DefaultCertificateService.kt | 4 ++-- .../credhub/views/CertificateView.kt | 16 +++++++-------- .../DefaultCertificateServiceTest.java | 14 ++++++------- .../RemoteCertificateAuthorityServiceTest.kt | 12 +++++------ .../org/cloudfoundry/credhub/Management.kt | 6 +++--- 12 files changed, 50 insertions(+), 50 deletions(-) diff --git a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/certificates/DefaultCertificatesHandler.kt b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/certificates/DefaultCertificatesHandler.kt index d6551a228..1e3c56c7d 100644 --- a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/certificates/DefaultCertificatesHandler.kt +++ b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/certificates/DefaultCertificatesHandler.kt @@ -62,7 +62,7 @@ class DefaultCertificatesHandler( val credentialValue = credentialGenerator .generate(generateRequest) as CertificateCredentialValue - credentialValue.isTransitional = request.isTransitional + credentialValue.transitional = request.isTransitional val credentialVersion = certificateService .save( @@ -145,7 +145,7 @@ class DefaultCertificatesHandler( checkPermissionsByUuid(certificateId, WRITE) val certificateCredentialValue = requestBody.value - certificateCredentialValue?.isTransitional = requestBody.isTransitional + certificateCredentialValue?.transitional = requestBody.isTransitional val credentialVersion = certificateService.set( UUID.fromString(certificateId), certificateCredentialValue diff --git a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/DefaultCredentialsHandler.kt b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/DefaultCredentialsHandler.kt index 1de18d7da..7328322d4 100644 --- a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/DefaultCredentialsHandler.kt +++ b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/DefaultCredentialsHandler.kt @@ -100,10 +100,10 @@ class DefaultCredentialsHandler( val certificateReader = CertificateReader(certificateValue?.certificate) if (certificateReader.isCa) { - setRequest.certificateValue?.isCertificateAuthority = true + setRequest.certificateValue?.certificateAuthority = true if (caName == null && certificateReader.isSelfSigned) { setRequest.certificateValue?.caName = setRequest.name - setRequest.certificateValue?.isSelfSigned = true + setRequest.certificateValue?.selfSigned = true } } diff --git a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/RemoteCredentialsHandler.kt b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/RemoteCredentialsHandler.kt index 82fecc141..e46712c3a 100644 --- a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/RemoteCredentialsHandler.kt +++ b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/credentials/RemoteCredentialsHandler.kt @@ -320,9 +320,9 @@ class RemoteCredentialsHandler( "ca_name" to certificateCredentialValue.caName, "certificate" to certificateCredentialValue.certificate, "private_key" to certificateCredentialValue.privateKey, - "transitional" to certificateCredentialValue.isTransitional, - "certificate_authority" to certificateCredentialValue.isCertificateAuthority, - "self_signed" to certificateCredentialValue.isSelfSigned, + "transitional" to certificateCredentialValue.transitional, + "certificate_authority" to certificateCredentialValue.certificateAuthority, + "self_signed" to certificateCredentialValue.selfSigned, "generated" to certificateCredentialValue.generated )) diff --git a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/management/ManagementController.kt b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/management/ManagementController.kt index 68bd827fe..cf85b5287 100644 --- a/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/management/ManagementController.kt +++ b/backends/credhub/src/main/kotlin/org/cloudfoundry/credhub/management/ManagementController.kt @@ -38,9 +38,9 @@ class ManagementController(private val managementService: ManagementService) { @ResponseStatus(HttpStatus.OK) fun updateManagementRegistry(@RequestBody management: Management): Management { - managementService.toggleReadOnlyMode(management.isReadOnlyMode) + managementService.toggleReadOnlyMode(management.readOnlyMode) - LOGGER.info("Setting read only mode to " + management.isReadOnlyMode) + LOGGER.info("Setting read only mode to " + management.readOnlyMode) return management } diff --git a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/credential/CertificateCredentialValue.kt b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/credential/CertificateCredentialValue.kt index e3b928b6e..92c83b5d4 100644 --- a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/credential/CertificateCredentialValue.kt +++ b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/credential/CertificateCredentialValue.kt @@ -43,9 +43,9 @@ class CertificateCredentialValue : CredentialValue { @JsonIgnore var trustedCa: String? = null - var isTransitional: Boolean = false - var isCertificateAuthority: Boolean = false - var isSelfSigned: Boolean = false + var transitional: Boolean = false + var certificateAuthority: Boolean = false + var selfSigned: Boolean = false @JsonInclude(Include.NON_NULL) var generated: Boolean? = null @@ -91,9 +91,9 @@ class CertificateCredentialValue : CredentialValue { this.trustedCa = trustedCa this.certificate = certificate this.privateKey = privateKey - this.isTransitional = transitional - this.isCertificateAuthority = certificateAuthority - this.isSelfSigned = selfSigned + this.transitional = transitional + this.certificateAuthority = certificateAuthority + this.selfSigned = selfSigned this.generated = generated this.caName = caName } @@ -106,9 +106,9 @@ class CertificateCredentialValue : CredentialValue { return false } val that = o as CertificateCredentialValue? - return isTransitional == that!!.isTransitional && - isCertificateAuthority == that.isCertificateAuthority && - isSelfSigned == that.isSelfSigned && + return transitional == that!!.transitional && + certificateAuthority == that.certificateAuthority && + selfSigned == that.selfSigned && ca == that.ca && certificate == that.certificate && privateKey == that.privateKey && @@ -116,6 +116,6 @@ class CertificateCredentialValue : CredentialValue { } override fun hashCode(): Int { - return Objects.hash(ca, certificate, privateKey, this.caName, isTransitional, isCertificateAuthority, isSelfSigned) + return Objects.hash(ca, certificate, privateKey, this.caName, transitional, certificateAuthority, selfSigned) } } diff --git a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/domain/CertificateCredentialVersion.kt b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/domain/CertificateCredentialVersion.kt index 8ddd459e5..0ff45f769 100644 --- a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/domain/CertificateCredentialVersion.kt +++ b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/domain/CertificateCredentialVersion.kt @@ -86,11 +86,11 @@ class CertificateCredentialVersion(delegate: CertificateCredentialVersionData) : this.privateKey = certificate.privateKey this.caName = certificate.caName this.certificate = certificate.certificate - this.setTransitional(certificate.isTransitional) + this.setTransitional(certificate.transitional) this.expiryDate = certificate.expiryDate - this.isCertificateAuthority = certificate.isCertificateAuthority + this.isCertificateAuthority = certificate.certificateAuthority this.trustedCa = certificate.trustedCa - this.isSelfSigned = certificate.isSelfSigned + this.isSelfSigned = certificate.selfSigned this.generated = certificate.generated } diff --git a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/CertificateDataService.kt b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/CertificateDataService.kt index 2e124b3d8..bd08ff8a8 100644 --- a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/CertificateDataService.kt +++ b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/CertificateDataService.kt @@ -75,7 +75,7 @@ constructor( val isGenerated = rowSet.getObject("CERTIFICATE_GENERATED") as? Boolean val certificateVersionMetadata = CertificateVersionMetadata( - toUUID(rowSet.getObject("VERSION_UUID")), + toUUID(rowSet.getObject("VERSION_UUID")!!), expiryDate, rowSet.getBoolean("TRANSITIONAL"), isCertificateAuthority, @@ -83,7 +83,7 @@ constructor( isGenerated ) - val credentialUUID: UUID = toUUID(rowSet.getObject("CREDENTIAL_UUID")) + val credentialUUID: UUID = toUUID(rowSet.getObject("CREDENTIAL_UUID")!!) if (certificateMetadataMap.containsKey(credentialUUID)) { certificateMetadataMap.getValue(credentialUUID).versions?.add(certificateVersionMetadata) diff --git a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/DefaultCertificateService.kt b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/DefaultCertificateService.kt index 5c61a6910..f2457e445 100644 --- a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/DefaultCertificateService.kt +++ b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/services/DefaultCertificateService.kt @@ -37,7 +37,7 @@ class DefaultCertificateService( generateRequest: BaseCredentialGenerateRequest ): CredentialVersion { generateRequest.type = "certificate" - if (credentialValue.isTransitional) { + if (credentialValue.transitional) { validateNoTransitionalVersionsAlreadyExist(generateRequest.name) } val version = credentialService @@ -174,7 +174,7 @@ class DefaultCertificateService( operator fun set(certificateUuid: UUID, value: CertificateCredentialValue?): CertificateCredentialVersion { val credential = findCertificateCredential(certificateUuid) - if (value?.isTransitional!!) { + if (value?.transitional!!) { validateNoTransitionalVersionsAlreadyExist(credential.name) } diff --git a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/views/CertificateView.kt b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/views/CertificateView.kt index ffc2c14d4..824b9659e 100644 --- a/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/views/CertificateView.kt +++ b/components/credentials/src/main/kotlin/org/cloudfoundry/credhub/views/CertificateView.kt @@ -13,9 +13,9 @@ class CertificateView : CredentialView { private var version: CertificateCredentialVersion? = null var expiryDate: Instant? = null private set - var isCertificateAuthority = false + var certificateAuthority = false private set - var isSelfSigned = false + var selfSigned = false private set @JsonInclude(JsonInclude.Include.NON_NULL) var generated: Boolean? = null @@ -32,8 +32,8 @@ class CertificateView : CredentialView { ) { this.version = version expiryDate = version.expiryDate - isCertificateAuthority = version.isCertificateAuthority - isSelfSigned = version.isSelfSigned + certificateAuthority = version.isCertificateAuthority + selfSigned = version.isSelfSigned generated = version.generated concatenateCas = false } @@ -48,8 +48,8 @@ class CertificateView : CredentialView { ) { this.version = version expiryDate = version.expiryDate - isCertificateAuthority = version.isCertificateAuthority - isSelfSigned = version.isSelfSigned + certificateAuthority = version.isCertificateAuthority + selfSigned = version.isSelfSigned generated = version.generated this.concatenateCas = concatenateCas } @@ -74,13 +74,13 @@ class CertificateView : CredentialView { return false } val that = o as CertificateView - return isCertificateAuthority == that.isCertificateAuthority && isSelfSigned == that.isSelfSigned && + return certificateAuthority == that.certificateAuthority && selfSigned == that.selfSigned && generated == that.generated && version == that.version && expiryDate == that.expiryDate } override fun hashCode(): Int { - return Objects.hash(super.hashCode(), version, expiryDate, isCertificateAuthority, isSelfSigned, generated) + return Objects.hash(super.hashCode(), version, expiryDate, certificateAuthority, selfSigned, generated) } } diff --git a/components/credentials/src/test/java/org/cloudfoundry/credhub/services/DefaultCertificateServiceTest.java b/components/credentials/src/test/java/org/cloudfoundry/credhub/services/DefaultCertificateServiceTest.java index 552e0bc69..4585f98a7 100644 --- a/components/credentials/src/test/java/org/cloudfoundry/credhub/services/DefaultCertificateServiceTest.java +++ b/components/credentials/src/test/java/org/cloudfoundry/credhub/services/DefaultCertificateServiceTest.java @@ -160,7 +160,7 @@ public void beforeEach() { @Test public void save_whenTransitionalIsFalse_delegatesToCredentialService() { - when(value.isTransitional()).thenReturn(false); + when(value.getTransitional()).thenReturn(false); final BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class); @@ -184,7 +184,7 @@ public void save_whenTransitionalIsFalse_delegatesToCredentialService() { @Test public void save_whenTransitionalIsTrue_andThereAreNoOtherTransitionalVersions_delegatesToCredentialService() { - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class); when(generateRequest.getName()).thenReturn("some-ca"); @@ -210,7 +210,7 @@ public void save_whenTransitionalIsTrue_andThereAreNoOtherTransitionalVersions_d @Test public void save_whenTransitionalIsTrue_andConcatenateCasIsTrue_generatesNewChildVersion() { - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class); when(generateRequest.getName()).thenReturn("some-ca"); @@ -243,7 +243,7 @@ public void save_whenTransitionalIsTrue_andConcatenateCasIsTrue_generatesNewChil @Test public void set_whenTransitionalIsTrue_andConcatenateCasIsTrue_generatesNewChildVersion() { - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final CertificateCredentialVersion previousVersion = mock(CertificateCredentialVersion.class); when(previousVersion.isVersionTransitional()).thenReturn(false); @@ -276,7 +276,7 @@ public void set_whenTransitionalIsTrue_andConcatenateCasIsTrue_generatesNewChild @Test public void set_whenTransitionalIsTrue_andConcatenateCasIsFalse_doesNotGeneratesNewChildVersion() { - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final CertificateCredentialVersion previousVersion = mock(CertificateCredentialVersion.class); when(previousVersion.isVersionTransitional()).thenReturn(false); @@ -310,7 +310,7 @@ public void set_whenTransitionalIsTrue_andConcatenateCasIsFalse_doesNotGenerates @Test public void save_whenTransitionalIsTrue_andConcatenateCasIsFalse_doesNotGeneratesNewChildVersion() { - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class); when(generateRequest.getName()).thenReturn("some-ca"); @@ -344,7 +344,7 @@ public void save_whenTransitionalIsTrue_andConcatenateCasIsFalse_doesNotGenerate @Test public void save_whenTransitionalIsTrue_AndThereIsAnotherTransitionalVersion_throwsAnException() { final CertificateCredentialValue value = mock(CertificateCredentialValue.class); - when(value.isTransitional()).thenReturn(true); + when(value.getTransitional()).thenReturn(true); final BaseCredentialGenerateRequest generateRequest = mock(BaseCredentialGenerateRequest.class); when(generateRequest.getName()).thenReturn("/some-name"); diff --git a/components/credentials/src/test/kotlin/org/cloudfoundry/credhub/services/RemoteCertificateAuthorityServiceTest.kt b/components/credentials/src/test/kotlin/org/cloudfoundry/credhub/services/RemoteCertificateAuthorityServiceTest.kt index 46f8768b6..e5225b2de 100644 --- a/components/credentials/src/test/kotlin/org/cloudfoundry/credhub/services/RemoteCertificateAuthorityServiceTest.kt +++ b/components/credentials/src/test/kotlin/org/cloudfoundry/credhub/services/RemoteCertificateAuthorityServiceTest.kt @@ -79,10 +79,10 @@ class RemoteCertificateAuthorityServiceTest { assertEquals(result.certificate, TestConstants.OTHER_TEST_CERTIFICATE) assertEquals(result.privateKey, TestConstants.OTHER_TEST_PRIVATE_KEY) assertEquals(result.caName, "/some-ca") - assertEquals(result.isCertificateAuthority, true) - assertEquals(result.isSelfSigned, true) + assertEquals(result.certificateAuthority, true) + assertEquals(result.selfSigned, true) assertEquals(result.generated, true) - assertEquals(result.isTransitional, false) + assertEquals(result.transitional, false) } @Test @@ -101,9 +101,9 @@ class RemoteCertificateAuthorityServiceTest { "ca_name" to data.caName, "certificate" to data.certificate, "private_key" to data.privateKey, - "transitional" to data.isTransitional, - "certificate_authority" to data.isCertificateAuthority, - "self_signed" to data.isSelfSigned, + "transitional" to data.transitional, + "certificate_authority" to data.certificateAuthority, + "self_signed" to data.selfSigned, "generated" to data.generated )) diff --git a/components/management/src/main/kotlin/org/cloudfoundry/credhub/Management.kt b/components/management/src/main/kotlin/org/cloudfoundry/credhub/Management.kt index f8bca23f9..520fb9d4f 100644 --- a/components/management/src/main/kotlin/org/cloudfoundry/credhub/Management.kt +++ b/components/management/src/main/kotlin/org/cloudfoundry/credhub/Management.kt @@ -1,17 +1,17 @@ package org.cloudfoundry.credhub class Management { - var isReadOnlyMode: Boolean = false + var readOnlyMode: Boolean = false constructor() : super() { // no arg constructor required by Jackson } constructor(readOnlyMode: Boolean?) : super() { - this.isReadOnlyMode = readOnlyMode!! + this.readOnlyMode = readOnlyMode!! } override fun toString(): String { - return "isReadOnly: $isReadOnlyMode" + return "isReadOnly: $readOnlyMode" } }