io.stargate.sgv2.api.common.config.MultiTenancyConfig Maven / Gradle / Ivy
/*
* Copyright The Stargate Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.stargate.sgv2.api.common.config;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.stargate.sgv2.api.common.tenant.TenantResolver;
import io.stargate.sgv2.api.common.tenant.impl.FixedTenantResolver;
import io.stargate.sgv2.api.common.tenant.impl.SubdomainTenantResolver;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Pattern;
import java.util.Optional;
import java.util.OptionalInt;
/** Configuration mapping for the tenant resolver. */
@ConfigMapping(prefix = "stargate.multi-tenancy")
public interface MultiTenancyConfig {
/** @return If multi-tenancy is enabled. */
@WithDefault("false")
boolean enabled();
/** @return Tenant resolver in case the multi-tenancy is active. */
@Valid
TenantResolverConfig tenantResolver();
/** Configuration mapping for the tenant resolver. */
interface TenantResolverConfig {
/**
* Tenant resolver type, possible options:
*
*
* subdomain
- reads tenant id from request host domain (see {@link
* SubdomainTenantResolver}
* fixed
- fixed tenant id supplied by the configuration (see {@link
* FixedTenantResolver}}
* custom
- allows configuring custom tenant resolver
*
*
* If unset, noop resolver will be used.
*
* @return The type of the {@link TenantResolver} used.
*/
Optional<@Pattern(regexp = "subdomain|fixed|custom") String> type();
/** @return Specific settings for the fixed
tenant resolver type. */
@Valid
MultiTenancyConfig.TenantResolverConfig.FixedTenantResolverConfig fixed();
/** @return Specific settings for the subdomain
tenant resolver type. */
@Valid
MultiTenancyConfig.TenantResolverConfig.SubdomainTenantResolverConfig subdomain();
interface FixedTenantResolverConfig {
/** @return Tenant ID value. */
Optional tenantId();
}
interface SubdomainTenantResolverConfig {
/** @return Maximum characters to pull from the subdomain. */
OptionalInt maxChars();
/** @return The regex to validate the resolved tenant against. */
Optional regex();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy