-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: service binding support for service registry with application s…
…ervices
- Loading branch information
Showing
5 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...n/java/io/quarkus/apicurio/registry/binding/ServiceRegistryBindingExtensionProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.quarkus.apicurio.registry.avro.binding; | ||
|
||
import io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter; | ||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.Capability; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; | ||
|
||
class ServiceRegistryBindingExtensionProcessor { | ||
|
||
@BuildStep | ||
void registerServiceBinding(Capabilities capabilities, | ||
BuildProducer<ServiceProviderBuildItem> serviceProvider) { | ||
if (capabilities.isPresent(Capability.KUBERNETES_SERVICE_BINDING)) { | ||
serviceProvider.produce( | ||
new ServiceProviderBuildItem("io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter", | ||
ServiceRegistryBindingConverter.class.getName())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...e/src/main/java/io/quarkus/apicurio/registry/binding/ServiceRegistryBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package io.quarkus.apicurio.registry.binding; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class ServiceRegistryBindingConverter implements ServiceBindingConverter { | ||
|
||
private static Logger LOG = Logger.getLogger(ServiceRegistryBindingConverter.class.getName()); | ||
|
||
private static final String INCOMING_PREFIX = "mp.messaging.incoming."; | ||
private static final String OUTGOING_PREFIX = "mp.messaging.outgoing."; | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
var matchingByType = ServiceBinding.singleMatchingByType("serviceregistry", serviceBindings); | ||
Config config = ConfigProvider.getConfig(); | ||
if (matchingByType.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
|
||
var binding = matchingByType.get(); | ||
|
||
List<String> channels = extractChannels(config); | ||
|
||
Map<String, String> properties = new HashMap<>(); | ||
|
||
String registryUrl = binding.getProperties().get("registryUrl"); | ||
if (registryUrl == null) { | ||
registryUrl = binding.getProperties().get("registryurl"); | ||
} | ||
if (registryUrl != null) { | ||
properties.put("mp.messaging.connector.smallrye-kafka.apicurio.registry.url", registryUrl); | ||
} | ||
|
||
for (String channel : channels) { | ||
|
||
String prefix = channel; | ||
|
||
String oAuthHost = binding.getProperties().get("oauthServerUrl"); | ||
if (oAuthHost == null) { | ||
oAuthHost = binding.getProperties().get("oauthserverurl"); | ||
} | ||
if (oAuthHost != null) { | ||
properties.put(prefix + "apicurio.auth.service.url", oAuthHost); | ||
} | ||
|
||
String clientId = binding.getProperties().get("clientId"); | ||
if (clientId == null) { | ||
clientId = binding.getProperties().get("clientid"); | ||
} | ||
if (clientId != null) { | ||
properties.put(prefix + "apicurio.auth.client.id", clientId); | ||
} | ||
|
||
String clientSecret = binding.getProperties().get("clientSecret"); | ||
if (clientSecret == null) { | ||
clientSecret = binding.getProperties().get("clientsecret"); | ||
} | ||
if (clientSecret != null) { | ||
properties.put(prefix + "apicurio.auth.client.secret", clientSecret); | ||
} | ||
|
||
String realm = binding.getProperties().get("oauthRealm"); | ||
if (realm == null) { | ||
realm = binding.getProperties().get("oauthRealm"); | ||
} | ||
if (clientSecret != null) { | ||
properties.put(prefix + "apicurio.auth.realm", realm); | ||
} | ||
|
||
if (registryUrl != null) { | ||
properties.put(prefix + "apicurio.registry.url", registryUrl); | ||
} | ||
} | ||
|
||
return Optional.of(new ServiceBindingConfigSource("serviceregistry-k8s-service-binding-source", properties)); | ||
} | ||
|
||
private List<String> extractChannels(Config configIn) { | ||
|
||
var list = new ArrayList<String>(); | ||
|
||
for (String propertyName : configIn.getPropertyNames()) { | ||
if (propertyName.startsWith(INCOMING_PREFIX)) { | ||
var channelName = propertyName.replace(INCOMING_PREFIX, "").split("\\.")[0]; | ||
list.add(INCOMING_PREFIX + channelName + "."); | ||
} else if (propertyName.startsWith(OUTGOING_PREFIX)) { | ||
var channelName = propertyName.replace(OUTGOING_PREFIX, "").split("\\.")[0]; | ||
list.add(OUTGOING_PREFIX + channelName + "."); | ||
} | ||
} | ||
return list; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.apicurio.registry.binding.ServiceRegistryBindingConverter |