使用yml配置而不是standalone.xml

时间:2020-06-25 14:26:07

标签: java jboss keycloak

我有很多微服务,它们以类似的格式工作。我的要求是使我的 confiuration.yml 文件也可用于密钥斗篷,而不是与 standalone.xml 一起使用(因为我的客户要求)。由于配置是在SPI之前完成的,因此我在查看keycloak的源代码时没有看到可以覆盖的任何选项。

在最坏的情况下,我将要运行一些程序以将给定的configuration.yml转换为standalone.xml。我很高兴听到关于如何实现这一目标的任何想法。基本上,我想使用YML而不是XML,要么本机导入密钥斗篷中的内容,要么使用一些转换器。

由于我们所有微服务的工作方式都一样,也许您可​​以问为什么(甚至对于客户)也需要它?

override func viewDidLoad() {
        let adUnitID = "ca-app-pub-3940256099942544/3986624511"
        let numAdsToLoad = 5
        let options = GADMultipleAdsAdLoaderOptions()
        options.numberOfAds = numAdsToLoad
        
        let adOptions = GADNativeAdViewAdOptions()
        adOptions.preferredAdChoicesPosition = .topRightCorner
        
        adLoader = GADAdLoader(adUnitID: adUnitID, rootViewController: self, adTypes: [.unifiedNative], options: [options, adOptions])
        adLoader.delegate = self
        adLoader.load(GADRequest())
}

func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADUnifiedNativeAd) {
        nativeAds.append(nativeAd)
}
    
func adLoaderDidFinishLoading(_ adLoader: GADAdLoader) {
        collectionView.reloadData()
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "onlineAdCell", for: indexPath) as! OnlineAdCollectionViewCell

        let nativeAd = nativeAds[onlineAdIndex()]
        nativeAd.rootViewController = self
        (cell.adView.headlineView as! UILabel).text = nativeAd.headline
        (cell.adView.callToActionView as! UILabel).text = nativeAd.callToAction
                   (cell.adView.imageView as! UIImageView).image = nativeAd.images?.first?.image
                    cell.adView.imageView?.contentMode = .scaleAspectFill
        cell.adView.callToActionView?.isUserInteractionEnabled = false
        cell.adView.nativeAd = nativeAd
        return cell
}

我们不想强迫我们的客户学习任何其他逻辑来编辑我们的微服务。它们将始终以相同的方式更改上面的一些基本配置,我们可以将这些值转换为适当的standalone.xml方式。那么我可以实现此转换器本机扩展keycloak还是最好的选择?

1 个答案:

答案 0 :(得分:0)

这取决于要提取到yml的设置。 Standalone.xml允许您将配置值指定为属性,例如

<socket-binding name="http" port="${jboss.http.port:8080}"/>

因此您可以在启动期间提供属性文件或属性值,例如

./standalone.sh --properties=foo.properties -Dfoo=bar

但是,在您的情况下,您可以将所有这些属性存储在yml中,并使用一些启动包装程序作为keycloak来解析yml并将其所有设置公开为java属性,例如:

#!/bin/bash 
./standalone.sh $(magictool foo.yml)