io.helidon.webserver.observe.config.ConfigObserverConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-webserver-observe-config Show documentation
Show all versions of helidon-webserver-observe-config Show documentation
Information from configuration (secured by default)
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
*
* 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.helidon.webserver.observe.config;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import io.helidon.builder.api.Prototype;
import io.helidon.common.Generated;
import io.helidon.common.config.Config;
import io.helidon.webserver.observe.ObserverConfigBase;
/**
* Interface generated from definition. Please add javadoc to the definition interface.
*
* @see #builder()
* @see #create()
*/
@Generated(value = "io.helidon.builder.codegen.BuilderCodegen", trigger = "io.helidon.webserver.observe.config.ConfigObserverConfigBlueprint")
public interface ConfigObserverConfig extends ConfigObserverConfigBlueprint, Prototype.Api, ObserverConfigBase {
/**
* Create a new fluent API builder to customize configuration.
*
* @return a new builder
*/
static ConfigObserverConfig.Builder builder() {
return new ConfigObserverConfig.Builder();
}
/**
* Create a new fluent API builder from an existing instance.
*
* @param instance an existing instance used as a base for the builder
* @return a builder based on an instance
*/
static ConfigObserverConfig.Builder builder(ConfigObserverConfig instance) {
return ConfigObserverConfig.builder().from(instance);
}
/**
* Create a new instance from configuration.
*
* @param config used to configure the new instance
* @return a new instance configured from configuration
*/
static ConfigObserverConfig create(Config config) {
return ConfigObserverConfig.builder().config(config).buildPrototype();
}
/**
* Create a new instance with default values.
*
* @return a new instance
*/
static ConfigObserverConfig create() {
return ConfigObserverConfig.builder().buildPrototype();
}
/**
* Fluent API builder base for {@link ConfigObserver}.
*
* @param type of the builder extending this abstract builder
* @param type of the prototype interface that would be built by {@link #buildPrototype()}
*/
abstract class BuilderBase, PROTOTYPE extends ConfigObserverConfig> extends ObserverConfigBase.BuilderBase implements Prototype.ConfiguredBuilder {
private final Set secrets = new LinkedHashSet<>(Set.of(".*password", ".*passphrase", ".*secret"));
private boolean permitAll;
private Config config;
private String endpoint = "config";
/**
* Protected to support extensibility.
*/
protected BuilderBase() {
name("config");
}
/**
* Update this builder from an existing prototype instance.
*
* @param prototype existing prototype to update this builder from
* @return updated builder instance
*/
public BUILDER from(ConfigObserverConfig prototype) {
super.from(prototype);
endpoint(prototype.endpoint());
permitAll(prototype.permitAll());
addSecrets(prototype.secrets());
return self();
}
/**
* Update this builder from an existing prototype builder instance.
*
* @param builder existing builder prototype to update this builder from
* @return updated builder instance
*/
public BUILDER from(ConfigObserverConfig.BuilderBase, ?> builder) {
super.from(builder);
endpoint(builder.endpoint());
permitAll(builder.permitAll());
addSecrets(builder.secrets);
return self();
}
/**
* Update builder from configuration (node of this type).
* If a value is present in configuration, it would override currently configured values.
*
* @param config configuration instance used to obtain values to update this builder
* @return updated builder instance
*/
@Override
public BUILDER config(Config config) {
Objects.requireNonNull(config);
this.config = config;
super.config(config);
config.get("endpoint").as(String.class).ifPresent(this::endpoint);
config.get("permit-all").as(Boolean.class).ifPresent(this::permitAll);
config.get("secrets").asList(String.class).map(java.util.Set::copyOf).ifPresent(this::secrets);
return self();
}
/**
*
*
* @param endpoint
* @return updated builder instance
* @see #endpoint()
*/
public BUILDER endpoint(String endpoint) {
Objects.requireNonNull(endpoint);
this.endpoint = endpoint;
return self();
}
/**
* Permit all access, even when not authorized.
*
* @param permitAll whether to permit access for anybody
* @return updated builder instance
* @see #permitAll()
*/
public BUILDER permitAll(boolean permitAll) {
this.permitAll = permitAll;
return self();
}
/**
* Secret patterns (regular expressions) to exclude from output.
* Any pattern that matches a key will cause the output to be obfuscated and not contain the value.
*
* Patterns always added:
*
* - {@code .*password}
* - {@code .*passphrase}
* - {@code .*secret}
*
*
* @param secrets set of regular expression patterns for keys, where values should be excluded from output
* @return updated builder instance
* @see #secrets()
*/
public BUILDER secrets(Set extends String> secrets) {
Objects.requireNonNull(secrets);
this.secrets.clear();
this.secrets.addAll(secrets);
return self();
}
/**
* Secret patterns (regular expressions) to exclude from output.
* Any pattern that matches a key will cause the output to be obfuscated and not contain the value.
*
* Patterns always added:
*
* - {@code .*password}
* - {@code .*passphrase}
* - {@code .*secret}
*
*
* @param secrets set of regular expression patterns for keys, where values should be excluded from output
* @return updated builder instance
* @see #secrets()
*/
public BUILDER addSecrets(Set extends String> secrets) {
Objects.requireNonNull(secrets);
this.secrets.addAll(secrets);
return self();
}
/**
* Secret patterns (regular expressions) to exclude from output.
* Any pattern that matches a key will cause the output to be obfuscated and not contain the value.
*
* Patterns always added:
*
* - {@code .*password}
* - {@code .*passphrase}
* - {@code .*secret}
*
*
* @param secret set of regular expression patterns for keys, where values should be excluded from output
* @return updated builder instance
* @see #secrets()
*/
public BUILDER addSecret(String secret) {
Objects.requireNonNull(secret);
this.secrets.add(secret);
return self();
}
/**
*
*
* @return the endpoint
*/
public String endpoint() {
return endpoint;
}
/**
* Permit all access, even when not authorized.
*
* @return the permit all
*/
public boolean permitAll() {
return permitAll;
}
/**
* Secret patterns (regular expressions) to exclude from output.
* Any pattern that matches a key will cause the output to be obfuscated and not contain the value.
*
* Patterns always added:
*
* - {@code .*password}
* - {@code .*passphrase}
* - {@code .*secret}
*
*
* @return the secrets
*/
public Set secrets() {
return secrets;
}
/**
* If this instance was configured, this would be the config instance used.
*
* @return config node used to configure this builder, or empty if not configured
*/
public Optional config() {
return Optional.ofNullable(config);
}
@Override
public String toString() {
return "ConfigObserverConfigBuilder{"
+ "endpoint=" + endpoint + ","
+ "permitAll=" + permitAll + ","
+ "secrets=" + secrets
+ "};"
+ super.toString();
}
/**
* Handles providers and decorators.
*/
protected void preBuildPrototype() {
super.preBuildPrototype();
}
/**
* Validates required properties.
*/
protected void validatePrototype() {
super.validatePrototype();
}
/**
* Generated implementation of the prototype, can be extended by descendant prototype implementations.
*/
protected static class ConfigObserverConfigImpl extends ObserverConfigBaseImpl implements ConfigObserverConfig, Supplier {
private final boolean permitAll;
private final Set secrets;
private final String endpoint;
/**
* Create an instance providing a builder.
*
* @param builder extending builder base of this prototype
*/
protected ConfigObserverConfigImpl(ConfigObserverConfig.BuilderBase, ?> builder) {
super(builder);
this.endpoint = builder.endpoint();
this.permitAll = builder.permitAll();
this.secrets = Collections.unmodifiableSet(new LinkedHashSet<>(builder.secrets()));
}
@Override
public ConfigObserver build() {
return ConfigObserver.create(this);
}
@Override
public ConfigObserver get() {
return build();
}
@Override
public String endpoint() {
return endpoint;
}
@Override
public boolean permitAll() {
return permitAll;
}
@Override
public Set secrets() {
return secrets;
}
@Override
public String toString() {
return "ConfigObserverConfig{"
+ "endpoint=" + endpoint + ","
+ "permitAll=" + permitAll + ","
+ "secrets=" + secrets
+ "};"
+ super.toString();
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof ConfigObserverConfig other)) {
return false;
}
return super.equals(other)
&& Objects.equals(endpoint, other.endpoint())
&& permitAll == other.permitAll()
&& Objects.equals(secrets, other.secrets());
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hash(endpoint, permitAll, secrets);
}
}
}
/**
* Fluent API builder for {@link ConfigObserver}.
*/
class Builder extends ConfigObserverConfig.BuilderBase implements io.helidon.common.Builder {
private Builder() {
}
@Override
public ConfigObserverConfig buildPrototype() {
preBuildPrototype();
validatePrototype();
return new ConfigObserverConfigImpl(this);
}
@Override
public ConfigObserver build() {
return ConfigObserver.create(this.buildPrototype());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy