Skip to content
Snippets Groups Projects

feat: Create CveServiceProducer with proxy startup service

1 unresolved thread
Files
5
/*********************************************************************
* Copyright (c) 2022 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.cve.config;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.cve.api.GithubCveAPI;
import org.eclipsefoundation.cve.api.GitlabCveAPI;
import org.eclipsefoundation.cve.service.CveService;
import org.eclipsefoundation.cve.service.impl.DefaultCveService;
import org.eclipsefoundation.cve.service.impl.StubbedCveService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.quarkus.arc.DefaultBean;
import io.quarkus.arc.properties.IfBuildProperty;
/**
* Allows Quarkus to inject the appropriate bean at runtime. Uses the stubbed
* service if running in dev profile.
*/
@Dependent
public class CveServiceProvider {
@ConfigProperty(name = "eclipse.github.cve-project.token")
String ghToken;
@Inject
@RestClient
GitlabCveAPI gitlabApi;
@Inject
@RestClient
GithubCveAPI githubApi;
@Produces
@ApplicationScoped
@DefaultBean
public CveService defaultCveService(ManagedExecutor executor, ObjectMapper om,
GitlabCveLoaderConfig glCveLoaderConfig) {
return new DefaultCveService(gitlabApi, githubApi, executor, glCveLoaderConfig, ghToken, om);
}
@Produces
@ApplicationScoped
@IfBuildProperty(name = "eclipse.cve.stubbed", stringValue = "true", enableIfMissing = true)
public CveService stubbedCveService() {
return new StubbedCveService();
}
}
Loading