Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed a hardcoded schema string in favor of the configuration value #588

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading