Skip to content

Commit

Permalink
Removed a hardcoded schema string in favor of the configuration value (
Browse files Browse the repository at this point in the history
  • Loading branch information
kickroot authored Mar 12, 2024
1 parent d37e050 commit 9527562
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion magpie-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class PolicyAnalyzerServiceImpl implements PolicyAnalyzerService {
private static final ObjectMapper MAPPER = new ObjectMapper();
private AssetsRepo assetsRepo;

private PersistConfig config;

@Override
public void init(MagpieConfig config) {
final var rawPersistConfig = config.getPlugins().get(PersistPlugin.ID);
Expand All @@ -42,6 +44,7 @@ public void init(MagpieConfig config) {

try {
final PersistConfig persistConfig = MAPPER.treeToValue(MAPPER.valueToTree(rawPersistConfig.getConfig()), PersistConfig.class);
this.config = persistConfig;
assetsRepo = new HibernateAssetsRepoImpl(persistConfig);
} catch (JsonProcessingException e) {
throw new ConfigException("Cannot instantiate PersistConfig while initializing PolicyAnalyzerService", e);
Expand Down Expand Up @@ -81,7 +84,8 @@ private void processPolicy(Policy policy,

private boolean cloudProviderAssetsAvailable(Policy policy) {
var provider = Strings.isNullOrEmpty(policy.getCloudProvider()) ? "" : policy.getCloudProvider().toLowerCase(Locale.ROOT);
List<Map<String, Object>> data = assetsRepo.queryNative("select count(*) from magpie.%provider%".replace("%provider%", provider));
var schema = Strings.isNullOrEmpty(config.getSchema()) ? "magpie" : config.getSchema();
List<Map<String, Object>> data = assetsRepo.queryNative("select count(*) from %schema%.%provider%".replace("%schema%", schema).replace("%provider%", provider));
final var count = data.get(0).get("count");
BigInteger compareTo;
if(count instanceof BigInteger) {
Expand Down

0 comments on commit 9527562

Please sign in to comment.