Skip to content

Commit

Permalink
Reduce the amount of converter injections in controllers (#514)
Browse files Browse the repository at this point in the history
- Reimplements the way converters are injected into beans using converter registries
- Simplifies controller implementations by using new base controller classes
- Merges backup models into a single version per entity type (cert/key/secret)
- Updates affected test cases

Resolves #506
{minor}

Signed-off-by: Esta Nagy <[email protected]>
  • Loading branch information
nagyesta authored Mar 21, 2023
1 parent 72731ed commit 2a81c54
Show file tree
Hide file tree
Showing 144 changed files with 2,933 additions and 1,726 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ configure(subprojects.findAll({
'com.github.nagyesta.lowkeyvault.service.exception.NotFoundException',
'com.github.nagyesta.lowkeyvault.service.exception.CryptoException',
'com.github.nagyesta.lowkeyvault.exception.VaultNotFoundException',
//until Cert features are implemented
'com.github.nagyesta.lowkeyvault.model.v7_3.certificate.DeletedKeyVaultCertificateItemModel'
//until Certificate backup features are implemented
'com.github.nagyesta.lowkeyvault.model.common.backup.CertificateBackupModel',
'com.github.nagyesta.lowkeyvault.model.common.backup.CertificateBackupList'
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.nagyesta.lowkeyvault.context;

import com.github.nagyesta.lowkeyvault.model.common.ApiConstants;

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

public interface ApiVersionAware {

/**
* Supported API version collection containing only 7.2.
*/
SortedSet<String> V7_2 = new TreeSet<>(Set.of(ApiConstants.V_7_2));
/**
* Supported API version collection containing only 7.3.
*/
SortedSet<String> V7_3 = new TreeSet<>(Set.of(ApiConstants.V_7_3));
/**
* Supported API version collection containing both 7.2 and 7.3.
*/
SortedSet<String> V7_2_AND_V7_3 = new TreeSet<>(Set.of(ApiConstants.V_7_2, ApiConstants.V_7_3));

SortedSet<String> supportedVersions();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.nagyesta.lowkeyvault.context;

import com.github.nagyesta.lowkeyvault.mapper.common.registry.CertificateConverterRegistry;
import com.github.nagyesta.lowkeyvault.mapper.v7_3.certificate.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class CertificateConverterConfiguration {

@Bean
public CertificateConverterRegistry certificateConverterRegistry() {
return new CertificateConverterRegistry();
}

@Bean
public CertificateEntityToV73PropertiesModelConverter certificatePropertiesConverter() {
return new CertificateEntityToV73PropertiesModelConverter(certificateConverterRegistry());
}

@Bean
@DependsOn("certificatePropertiesConverter")
public CertificateEntityToV73ModelConverter certificateModelConverter() {
return new CertificateEntityToV73ModelConverter(certificateConverterRegistry());
}

@Bean
@DependsOn("certificatePropertiesConverter")
public CertificateEntityToV73CertificateItemModelConverter certificateItemConverter() {
return new CertificateEntityToV73CertificateItemModelConverter(certificateConverterRegistry());
}

@Bean
@DependsOn("certificatePropertiesConverter")
public CertificateEntityToV73CertificateVersionItemModelConverter certificateVersionedItemConverter() {
return new CertificateEntityToV73CertificateVersionItemModelConverter(certificateConverterRegistry());
}

@Bean
public CertificateEntityToV73PolicyModelConverter certificatePolicyConverter() {
return new CertificateEntityToV73PolicyModelConverter(certificateConverterRegistry());
}

@Bean
public CertificateEntityToV73IssuancePolicyModelConverter certificateIssuancePolicyConverter() {
return new CertificateEntityToV73IssuancePolicyModelConverter(certificateConverterRegistry());
}

@Bean
public CertificateEntityToV73PendingCertificateOperationModelConverter certificatePendingOperationConverter() {
return new CertificateEntityToV73PendingCertificateOperationModelConverter(certificateConverterRegistry());
}

@Bean
public CertificateLifetimeActionsPolicyToV73ModelConverter certificateLifetimeActionConverter() {
return new CertificateLifetimeActionsPolicyToV73ModelConverter(certificateConverterRegistry());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.nagyesta.lowkeyvault.context;

import com.github.nagyesta.lowkeyvault.mapper.common.registry.KeyConverterRegistry;
import com.github.nagyesta.lowkeyvault.mapper.v7_2.key.*;
import com.github.nagyesta.lowkeyvault.mapper.v7_3.key.KeyRotationPolicyToV73ModelConverter;
import com.github.nagyesta.lowkeyvault.mapper.v7_3.key.KeyRotationPolicyV73ModelToEntityConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class KeyConverterConfiguration {

@Bean
public KeyConverterRegistry keyConverterRegistry() {
return new KeyConverterRegistry();
}

@Bean
public KeyEntityToV72PropertiesModelConverter keyPropertiesConverter() {
return new KeyEntityToV72PropertiesModelConverter(keyConverterRegistry());
}

@Bean
@DependsOn("keyPropertiesConverter")
public KeyEntityToV72ModelConverter keyModelConverter() {
return new KeyEntityToV72ModelConverter(keyConverterRegistry());
}

@Bean
@DependsOn("keyPropertiesConverter")
public KeyEntityToV72KeyItemModelConverter keyItemConverter() {
return new KeyEntityToV72KeyItemModelConverter(keyConverterRegistry());
}

@Bean
@DependsOn("keyPropertiesConverter")
public KeyEntityToV72KeyVersionItemModelConverter keyVersionedItemConverter() {
return new KeyEntityToV72KeyVersionItemModelConverter(keyConverterRegistry());
}

@Bean
@DependsOn("keyPropertiesConverter")
public KeyEntityToV72BackupConverter keyBackupConverter() {
return new KeyEntityToV72BackupConverter(keyConverterRegistry());
}

@Bean
public KeyRotationPolicyToV73ModelConverter keyRotationPolicyModelConverter() {
return new KeyRotationPolicyToV73ModelConverter(keyConverterRegistry());
}

@Bean
public KeyRotationPolicyV73ModelToEntityConverter keyRotationPolicyEntityConverter() {
return new KeyRotationPolicyV73ModelToEntityConverter(keyConverterRegistry());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.nagyesta.lowkeyvault.context;

import com.github.nagyesta.lowkeyvault.mapper.common.registry.SecretConverterRegistry;
import com.github.nagyesta.lowkeyvault.mapper.v7_2.secret.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class SecretConverterConfiguration {

@Bean
public SecretConverterRegistry secretConverterRegistry() {
return new SecretConverterRegistry();
}

@Bean
public SecretEntityToV72PropertiesModelConverter secretPropertiesConverter() {
return new SecretEntityToV72PropertiesModelConverter(secretConverterRegistry());
}

@Bean
@DependsOn("secretPropertiesConverter")
public SecretEntityToV72ModelConverter secretModelConverter() {
return new SecretEntityToV72ModelConverter(secretConverterRegistry());
}

@Bean
@DependsOn("secretPropertiesConverter")
public SecretEntityToV72SecretItemModelConverter secretItemConverter() {
return new SecretEntityToV72SecretItemModelConverter(secretConverterRegistry());
}

@Bean
@DependsOn("secretPropertiesConverter")
public SecretEntityToV72SecretVersionItemModelConverter secretVersionedItemConverter() {
return new SecretEntityToV72SecretVersionItemModelConverter(secretConverterRegistry());
}

@Bean
@DependsOn("secretPropertiesConverter")
public SecretEntityToV72BackupConverter secretBackupConverter() {
return new SecretEntityToV72BackupConverter(secretConverterRegistry());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.github.nagyesta.lowkeyvault.controller.v7_3.KeyBackupRestoreController;
import com.github.nagyesta.lowkeyvault.controller.v7_3.SecretBackupRestoreController;
import com.github.nagyesta.lowkeyvault.model.common.ErrorModel;
import com.github.nagyesta.lowkeyvault.model.common.backup.KeyBackupList;
import com.github.nagyesta.lowkeyvault.model.common.backup.KeyBackupModel;
import com.github.nagyesta.lowkeyvault.model.common.backup.SecretBackupList;
import com.github.nagyesta.lowkeyvault.model.common.backup.SecretBackupModel;
import com.github.nagyesta.lowkeyvault.model.management.VaultBackupListModel;
import com.github.nagyesta.lowkeyvault.model.management.VaultBackupModel;
import com.github.nagyesta.lowkeyvault.model.management.VaultModel;
import com.github.nagyesta.lowkeyvault.model.v7_2.secret.SecretBackupList;
import com.github.nagyesta.lowkeyvault.model.v7_2.secret.SecretBackupModel;
import com.github.nagyesta.lowkeyvault.model.v7_3.key.KeyBackupList;
import com.github.nagyesta.lowkeyvault.model.v7_3.key.KeyBackupModel;
import com.github.nagyesta.lowkeyvault.service.exception.NotFoundException;
import com.github.nagyesta.lowkeyvault.service.key.ReadOnlyKeyVaultKeyEntity;
import com.github.nagyesta.lowkeyvault.service.key.id.VersionedKeyEntityId;
Expand Down
Loading

0 comments on commit 2a81c54

Please sign in to comment.