6. API 版本验证

平台必须在对Open Service Broker API的每次调用中提供一个HTTP标题,以指示平台支持的API规范的版本。 您可以配置Spring Cloud Open Service Broker来验证每个服务代理上调提供的版本。 默认情况下,此版本验证配置允许任何API版本。spring-doc.cadn.net.cn

为了自定义版本验证,请设置指定服务代理所需API版本的apiVersion属性,如下所示:spring-doc.cadn.net.cn

spring.cloud.openservicebroker.apiVersion=2.13

同样,您可以提供一个BrokerApiVersion型Spring Bean,如下所示:spring-doc.cadn.net.cn

package com.example.servicebroker;

import org.springframework.cloud.servicebroker.model.BrokerApiVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExampleApiVersionConfiguration {
	@Bean
	public BrokerApiVersion brokerApiVersion() {
		return new BrokerApiVersion("2.13");
	}
}

In the case of both a Spring Bean and a property being configured, the Spring Bean takes precedence over the property.spring-doc.cadn.net.cn

如果指定了API版本且平台在X-Broker-API-Version头中提供了不同的版本,框架会将412 Precondition Failed错误返回给平台。spring-doc.cadn.net.cn

如前所述,默认的版本验证配置为允许任何 API 版本。 但是,要完全禁用版本验证,您可以将 api-version-check-endabled 属性设置为 false,如下所示:spring-doc.cadn.net.cn

spring.cloud.openservicebroker.api-version-check-enabled = false