All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.swisscom.cloud.sb.broker.cfextensions.endpoint.EndpointLookup.groovy Maven / Gradle / Ivy

There is a newer version: 6.21.6
Show newest version
package com.swisscom.cloud.sb.broker.cfextensions.endpoint

import com.swisscom.cloud.sb.broker.model.ServiceInstance
import com.swisscom.cloud.sb.broker.util.servicedetail.ServiceDetailType
import com.swisscom.cloud.sb.broker.util.servicedetail.ServiceDetailsHelper
import com.swisscom.cloud.sb.model.endpoint.Endpoint
import groovy.transform.CompileStatic
import org.springframework.stereotype.Component

@Component
@CompileStatic
class EndpointLookup {
    public static final Collection DEFAULT_PROTOCOLS = Collections.unmodifiableCollection(["tcp"])

    Collection findEndpoints(ServiceInstance serviceInstance, EndpointConfig config) {
        def result = new LinkedList()
        def portsForServiceInstance = ServiceDetailsHelper.from(serviceInstance).findAllWithServiceDetailType(ServiceDetailType.PORT)
        if (config.protocols.size() == 0){
            config.protocols.addAll(DEFAULT_PROTOCOLS)
        }

        config.protocols.each { String protocol ->
            config.ipRanges.each { String ipRange ->
                portsForServiceInstance.each { String port ->
                        result.add(new Endpoint(protocol: protocol, ports: port, destination: ipRange))
                }
            }
        }
        return result
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy