Skip to content

Commit

Permalink
Fix 151 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kittylyst authored Feb 6, 2024
1 parent 76651a1 commit 76410d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/main/java/com/redhat/insights/agent/AgentMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,26 @@ private static boolean shouldLookForCerts(AgentConfiguration config) {
private void start() {
final InsightsReport report = AgentBasicReport.of(configuration);

Supplier<InsightsHttpClient> httpClientSupplier;
if (configuration.isDebug() || configuration.isFileOnly()) {
httpClientSupplier = () -> new InsightsFileWritingClient(logger, configuration);
} else {
final PEMSupport pem = new PEMSupport(logger, configuration);
httpClientSupplier =
() -> new InsightsAgentHttpClient(configuration, () -> pem.createTLSContext());
}
final Supplier<InsightsHttpClient> clientSupplier = getInsightsClientSupplier();
try {
final InsightsReportController controller =
InsightsReportController.of(
logger, configuration, report, httpClientSupplier, waitingJars);
InsightsReportController.of(logger, configuration, report, clientSupplier, waitingJars);
controller.generate();
} catch (InsightsException e) {
logger.info("Unable to start Red Hat Insights agent: " + e.getMessage());
}
}

private Supplier<InsightsHttpClient> getInsightsClientSupplier() {
final Supplier<InsightsHttpClient> out;
if (configuration.isDebug() || configuration.isFileOnly()) {
out = () -> new InsightsFileWritingClient(logger, configuration);
} else if (configuration.isOCP()) {
out = () -> new InsightsAgentHttpClient(configuration);
} else {
final PEMSupport pem = new PEMSupport(logger, configuration);
out = () -> new InsightsAgentHttpClient(configuration, pem::createTLSContext);
}
return out;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public InsightsAgentHttpClient(
this.useMTLS = !configuration.getMaybeAuthToken().isPresent();
}

public InsightsAgentHttpClient(InsightsConfiguration configuration) {
this.configuration = configuration;
this.sslContextSupplier =
() -> {
throw new InsightsException(
ERROR_SSL_CREATING_CONTEXT, "Could not create SSL context in Token Auth mode");
};
this.useMTLS = false;
}

@Override
public void decorate(InsightsReport report) {
if (useMTLS) {
Expand Down

0 comments on commit 76410d5

Please sign in to comment.