Search in sources :

Example 1 with Slf4jIntLogger

use of com.blackducksoftware.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.

the class GlobalHubConfigActions method channelTestConfig.

@Override
public String channelTestConfig(final GlobalHubConfigRestModel restModel) throws IntegrationException {
    final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    String apiToken;
    if (restModel.isHubApiKeyIsSet()) {
        final GlobalHubConfigEntity foundEntity = getRepository().findOne(Long.parseLong(restModel.getId()));
        apiToken = foundEntity.getHubApiKey();
    } else {
        apiToken = restModel.getHubApiKey();
    }
    final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
    hubServerConfigBuilder.setHubUrl(globalProperties.getHubUrl());
    hubServerConfigBuilder.setTimeout(restModel.getHubTimeout());
    hubServerConfigBuilder.setProxyHost(globalProperties.getHubProxyHost());
    hubServerConfigBuilder.setProxyPort(globalProperties.getHubProxyPort());
    hubServerConfigBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
    hubServerConfigBuilder.setApiToken(apiToken);
    hubServerConfigBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
    if (globalProperties.getHubTrustCertificate() != null) {
        hubServerConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    }
    hubServerConfigBuilder.setLogger(intLogger);
    validateHubConfiguration(hubServerConfigBuilder);
    final RestConnection restConnection = createRestConnection(hubServerConfigBuilder);
    restConnection.connect();
    return "Successfully connected to the Hub.";
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 2 with Slf4jIntLogger

use of com.blackducksoftware.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.

the class LoginActionsTestIT method authenticateUserTestIT.

@Test
public void authenticateUserTestIT() throws IntegrationException {
    final LoginActions loginActions = new LoginActions(new TestGlobalProperties());
    final boolean userAuthenticated = loginActions.authenticateUser(mockLoginRestModel.createRestModel(), new Slf4jIntLogger(logger));
    Assert.assertTrue(userAuthenticated);
}
Also used : Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 3 with Slf4jIntLogger

use of com.blackducksoftware.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.

the class LoginActionsTestIT method testValidateHubConfigurationException.

@Test
public void testValidateHubConfigurationException() {
    mockLoginRestModel.setHubUsername(null);
    final LoginActions loginActions = new LoginActions(new TestGlobalProperties());
    try {
        final boolean authenticated = loginActions.authenticateUser(mockLoginRestModel.createRestModel(), new Slf4jIntLogger(logger));
        assertFalse(authenticated);
    } catch (final IntegrationException e) {
        fail();
    }
}
Also used : Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 4 with Slf4jIntLogger

use of com.blackducksoftware.integration.log.Slf4jIntLogger in project hub-detect by blackducksoftware.

the class Application method init.

@PostConstruct
public void init() {
    final long start = System.currentTimeMillis();
    try {
        detectInfo.init();
        detectOptionManager.init();
        final List<DetectOption> options = detectOptionManager.getDetectOptions();
        boolean isPrintHelp = false;
        boolean isPrintHelpDoc = false;
        boolean isInteractive = false;
        for (final String arg : applicationArguments.getSourceArgs()) {
            if (arg.equals("-h") || arg.equals("--help")) {
                isPrintHelp = true;
            } else if (arg.equals("-hdoc") || arg.equals("--helpdocument")) {
                isPrintHelpDoc = true;
            } else if (arg.equals("-i") || arg.equals("--interactive")) {
                isInteractive = true;
            }
        }
        if (isPrintHelp) {
            helpPrinter.printHelpMessage(System.out, options);
            return;
        }
        if (isPrintHelpDoc) {
            helpHtmlWriter.writeHelpMessage(String.format("hub-detect-%s-help.html", detectInfo.getDetectVersion()));
            return;
        }
        if (isInteractive) {
            final InteractiveReader interactiveReader = createInteractiveReader();
            final PrintStream interactivePrintStream = new PrintStream(System.out);
            interactiveManager.interact(interactiveReader, interactivePrintStream);
        }
        detectConfiguration.init();
        logger.info("Configuration processed completely.");
        if (!detectConfiguration.getSuppressConfigurationOutput()) {
            final DetectInfoPrinter infoPrinter = new DetectInfoPrinter();
            final DetectConfigurationPrinter detectConfigurationPrinter = new DetectConfigurationPrinter();
            infoPrinter.printInfo(System.out, detectInfo);
            detectConfigurationPrinter.print(System.out, detectInfo, detectConfiguration, options);
        }
        if (detectConfiguration.getTestConnection()) {
            hubServiceWrapper.assertHubConnection(new SilentLogger());
            return;
        }
        if (!detectConfiguration.getHubOfflineMode()) {
            hubServiceWrapper.init();
        }
        final DetectProject detectProject = detectProjectManager.createDetectProject();
        final List<File> createdBdioFiles = detectProjectManager.createBdioFiles(detectProject);
        if (!detectConfiguration.getHubOfflineMode()) {
            final ProjectVersionView projectVersionView = hubManager.updateHubProjectVersion(detectProject, createdBdioFiles);
            hubManager.performPostHubActions(detectProject, projectVersionView);
        } else if (!detectConfiguration.getHubSignatureScannerDisabled()) {
            hubSignatureScanner.scanPathsOffline(detectProject);
        }
        for (final ExitCodeReporter exitCodeReporter : exitCodeReporters) {
            exitCodeType = ExitCodeType.getWinningExitCodeType(exitCodeType, exitCodeReporter.getExitCodeType());
        }
    } catch (final Exception e) {
        populateExitCodeFromExceptionDetails(e);
    } finally {
        try {
            detectPhoneHomeManager.endPhoneHome();
        } catch (final Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
        if (!detectConfiguration.getSuppressResultsOutput()) {
            detectSummary.logResults(new Slf4jIntLogger(logger), exitCodeType);
        }
        detectFileManager.cleanupDirectories();
    }
    final long end = System.currentTimeMillis();
    logger.info(String.format("Hub-Detect run duration: %s", DurationFormatUtils.formatPeriod(start, end, "HH'h' mm'm' ss's' SSS'ms'")));
    if (detectConfiguration.getForceSuccess() && exitCodeType.getExitCode() != 0) {
        logger.warn("Forcing success: Exiting with 0. Desired exit code was ${exitCodeType.getExitCode()}.");
        System.exit(0);
    } else {
        System.exit(exitCodeType.getExitCode());
    }
}
Also used : PrintStream(java.io.PrintStream) InteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.InteractiveReader) ScannerInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ScannerInteractiveReader) ConsoleInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ConsoleInteractiveReader) DetectInfoPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectInfoPrinter) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) DetectOption(com.blackducksoftware.integration.hub.detect.help.DetectOption) DetectProject(com.blackducksoftware.integration.hub.detect.model.DetectProject) ExitCodeReporter(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter) DetectConfigurationPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectConfigurationPrinter) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) SilentLogger(com.blackducksoftware.integration.log.SilentLogger) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 5 with Slf4jIntLogger

use of com.blackducksoftware.integration.log.Slf4jIntLogger in project hub-detect by blackducksoftware.

the class DetectConfiguration method createUnauthenticatedRestConnection.

public UnauthenticatedRestConnection createUnauthenticatedRestConnection(final String url) throws DetectUserFriendlyException {
    final UnauthenticatedRestConnectionBuilder restConnectionBuilder = new UnauthenticatedRestConnectionBuilder();
    restConnectionBuilder.setBaseUrl(url);
    restConnectionBuilder.setTimeout(getHubTimeout());
    restConnectionBuilder.applyProxyInfo(getHubProxyInfo());
    restConnectionBuilder.setLogger(new Slf4jIntLogger(logger));
    restConnectionBuilder.setAlwaysTrustServerCertificate(getHubTrustCertificate());
    return restConnectionBuilder.build();
}
Also used : Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) UnauthenticatedRestConnectionBuilder(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)

Aggregations

Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)12 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)5 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)5 Test (org.junit.Test)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)3 IntLogger (com.blackducksoftware.integration.log.IntLogger)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 MockLoginRestModel (com.blackducksoftware.integration.hub.alert.mock.model.MockLoginRestModel)2 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)2 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)2 CIEnvironmentVariables (com.blackducksoftware.integration.util.CIEnvironmentVariables)2 File (java.io.File)2 EncryptionException (com.blackducksoftware.integration.exception.EncryptionException)1 Credentials (com.blackducksoftware.integration.hub.Credentials)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)1 LoginRestModel (com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel)1 CurrentVersionView (com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView)1 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)1