io.helidon.config.Config.asBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(14.0k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中io.helidon.config.Config.asBoolean()方法的一些代码示例,展示了Config.asBoolean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.asBoolean()方法的具体详情如下:
包路径:io.helidon.config.Config
类名称:Config
方法名:asBoolean

Config.asBoolean介绍

[英]Boolean typed value.
[中]布尔类型值。

代码示例

代码示例来源:origin: oracle/helidon

@Override
public void init(Config config) {
  root = config;
  /*
   * If failOnMissingReferenceSetting has not already been explicitly set
   * by the constructor, try to get the setting from the configuration. In
   * either case save the result in a simple boolean for efficiency in
   * #apply.
   */
  if (!failOnMissingReferenceSetting.isPresent()) {
    failOnMissingReferenceSetting = Optional.of(
        config
          .get(ConfigFilters.ValueResolvingBuilder.FAIL_ON_MISSING_REFERENCE_KEY_NAME)
          .asBoolean()
          .orElse(DEFAULT_FAIL_ON_MISSING_REFERENCE_BEHAVIOR));
  }
  failOnMissingReference = failOnMissingReferenceSetting.get();
}

代码示例来源:origin: oracle/helidon

/**
   * Update builder from configuration and set the config to {@link #configuration(io.helidon.config.Config)}.
   *
   * @param config configuration placed on the key of this provider
   * @return updated builder instance
   */
  public Builder config(Config config) {
    configuration(config);
    config.get("fail-on-unvalidated").asBoolean().ifPresent(this::failOnUnvalidated);
    config.get("fail-if-none-validated").asBoolean().ifPresent(this::failIfNoneValidated);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

@Override
protected MyConfigSourceBuilder2 init(Config metaConfig) {
  metaConfig.get("myProp3").asBoolean().ifPresent(this::myProp3);
  return super.init(metaConfig);
}

代码示例来源:origin: oracle/helidon

@Override
protected MyConfigSourceBuilder1 init(Config metaConfig) {
  metaConfig.get("myProp3").asBoolean().ifPresent(this::myProp3);
  return super.init(metaConfig);
}

代码示例来源:origin: oracle/helidon

private static void register(BaseRegistry registry,
               Config config,
               Metadata meta,
               Metric metric) {
  if (registry.config.get(CONFIG_METRIC_ENABLED_BASE + meta.getName() + ".enabled").asBoolean().orElse(true)) {
    registry.register(meta, metric);
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Update this builder from configuration.
 *
 * @param config config instance located on the key {@link PolicyValidator#configKey()}
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("inherit").asBoolean().ifPresent(this::inherit);
  config.get("statement").asString().ifPresent(this::statement);
  return this;
}

代码示例来源:origin: oracle/helidon

/**
 * Initializes config filter instance from configuration properties.
 * <p>
 * Optional {@code properties}:
 * <ul>
 * <li>{@code failOnMissingReference} - type {@link Boolean}, see {@link #failOnMissingReference}</li>
 * </ul>
 *
 * @param metaConfig meta-configuration used to initialize returned config filter instance from
 * @return new instance of config filter builder described by {@code metaConfig}
 * @throws MissingValueException  in case the configuration tree does not contain all expected sub-nodes
 *                                required by the mapper implementation to provide instance of Java type.
 * @throws ConfigMappingException in case the mapper fails to map the (existing) configuration tree represented by the
 *                                supplied configuration node to an instance of a given Java type.
 * @see ConfigFilters#valueResolving()
 */
public static ValueResolvingBuilder create(Config metaConfig) throws ConfigMappingException, MissingValueException {
  ValueResolvingBuilder builder = new ValueResolvingBuilder();
  builder.failOnMissingReference(metaConfig.get(FAIL_ON_MISSING_REFERENCE_KEY_NAME).asBoolean().orElse(false));
  return builder;
}

代码示例来源:origin: oracle/helidon

/**
   * Load configuration data from configuration.
   *
   * @param config configuration located the key of this attribute config
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("user").asList(String.class).ifPresent(this::addRoles);
    config.get("service").asList(String.class).ifPresent(this::addServiceRoles);
    config.get("permit-all").asBoolean().ifPresent(this::permitAll);
    config.get("deny-all").asBoolean().ifPresent(this::denyAll);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

private EncryptionFilter(Builder builder, Config config) {
  if (builder.fromConfig) {
    this.requireEncryption = OptionalHelper.from(EncryptionUtil.getEnv(ConfigProperties.REQUIRE_ENCRYPTION_ENV_VARIABLE)
                               .map(Boolean::parseBoolean))
        .or(() -> config.get(ConfigProperties.REQUIRE_ENCRYPTION_CONFIG_KEY).asBoolean().asOptional())
        .asOptional()
        .orElse(true);
    this.masterPassword = EncryptionUtil.resolveMasterPassword(requireEncryption, config).orElse(null);
    this.privateKey = EncryptionUtil.resolvePrivateKey(config.get("security.config.rsa"))
        .orElse(null);
  } else {
    this.requireEncryption = builder.requireEncryption;
    this.privateKey = builder.privateKeyConfig.privateKey()
        .orElseThrow(() -> new ConfigEncryptionException("Private key configuration is invalid"));
    this.masterPassword = builder.masterPassword;
  }
  if (null != privateKey && !(privateKey instanceof RSAPrivateKey)) {
    throw new ConfigEncryptionException("Private key must be an RSA private key, but is: "
                          + privateKey.getClass().getName());
  }
  ConfigFilter noOp = (key, stringValue) -> stringValue;
  aesFilter = (null == masterPassword ? noOp : (key, stringValue) -> decryptAes(masterPassword, stringValue));
  rsaFilter = (null == privateKey ? noOp : (key, stringValue) -> decryptRsa(privateKey, stringValue));
  clearFilter = this::clearText;
  aliasFilter = (key, stringValue) -> aliased(stringValue, config);
}

代码示例来源:origin: oracle/helidon

static Optional<Resource> fromConfigUrl(Config config, String keyPrefix) {
  return config.get(keyPrefix + "-url")
      .as(URI.class)
      .map(uri -> config.get("proxy-host").asString()
          .map(proxyHost -> {
            if (config.get(keyPrefix + "-use-proxy").asBoolean().orElse(true)) {
              Proxy proxy = new Proxy(Proxy.Type.HTTP,
                          new InetSocketAddress(proxyHost,
                                     config.get("proxy-port").asInt().orElse(
                                         DEFAULT_PROXY_PORT)));
              return Resource.create(uri, proxy);
            } else {
              return Resource.create(uri);
            }
          })
          .orElseGet(() -> Resource.create(uri)));
}

代码示例来源:origin: oracle/helidon

/**
   * Load all properties for this thread pool executor from configuration.
   * Expected keys:
   * <ul>
   * <li>core-pool-size</li>
   * <li>is-daemon</li>
   * <li>thread-name-prefix</li>
   * <li>should-prestart</li>
   * </ul>
   *
   * @param config config located on the key of executor-service
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("core-pool-size").asInt().ifPresent(this::corePoolSize);
    config.get("is-daemon").asBoolean().ifPresent(this::daemon);
    config.get("thread-name-prefix").asString().ifPresent(this::threadNamePrefix);
    config.get("should-prestart").asBoolean().ifPresent(this::prestart);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

@Override
public void filter(ContainerRequestContext requestContext) {
  ServerRequest serverRequest = this.request.get();
  Tracer tracer = serverRequest.webServer().configuration().tracer();
  SpanContext parentSpan = serverRequest.spanContext();
  boolean clientEnabled = config.get("tracing.client.enabled").asBoolean().orElse(true);
  TracingContext tracingContext = TracingContext.create(tracer, serverRequest.headers().toMap(), clientEnabled);
  tracingContext.parentSpan(parentSpan);
  TracingContext.set(tracingContext);
}

代码示例来源:origin: oracle/helidon

/**
 * Create a builder from configuration.
 *
 * @param config Config located at http-signatures key
 * @return builder instance configured from config
 */
public Builder config(Config config) {
  config.get("headers").asList(HttpSignHeader.class).ifPresent(list -> list.forEach(this::addAcceptHeader));
  config.get("optional").asBoolean().ifPresent(this::optional);
  config.get("realm").asString().ifPresent(this::realm);
  config.get("sign-headers").as(SignedHeadersConfig::create).ifPresent(this::inboundRequiredHeaders);
  outboundConfig = OutboundConfig.create(config);
  config.get("inbound.keys")
      .asList(InboundClientDefinition::create)
      .ifPresent(list -> list.forEach(inbound -> inboundKeys.put(inbound.keyId(), inbound)));
  return this;
}

代码示例来源:origin: oracle/helidon

/**
 * Load this builder from a configuration.
 *
 * @param config configuration to load from
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("optional").asBoolean().ifPresent(this::optional);
  config.get("authenticate").asBoolean().ifPresent(this::authenticate);
  config.get("propagate").asBoolean().ifPresent(this::propagate);
  config.get("allow-impersonation").asBoolean().ifPresent(this::allowImpersonation);
  config.get("principal-type").asString().as(SubjectType::valueOf).ifPresent(this::subjectType);
  config.get("atn-token.handler").as(TokenHandler::create).ifPresent(this::atnTokenHandler);
  config.get("atn-token").ifExists(this::verifyKeys);
  config.get("atn-token.jwt-audience").asString().ifPresent(this::expectedAudience);
  config.get("atn-token.default-key-id").asString().ifPresent(this::defaultKeyId);
  config.get("atn-token.verify-key").asString().ifPresent(this::publicKeyPath);
  config.get("sign-token").ifExists(outbound -> outboundConfig(OutboundConfig.create(outbound)));
  config.get("sign-token").ifExists(this::outbound);
  org.eclipse.microprofile.config.Config mpConfig = ConfigProviderResolver.instance().getConfig();
  mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY, String.class).ifPresent(this::publicKey);
  mpConfig.getOptionalValue(CONFIG_PUBLIC_KEY_PATH, String.class).ifPresent(this::publicKeyPath);
  mpConfig.getOptionalValue(CONFIG_EXPECTED_ISSUER, String.class).ifPresent(this::expectedIssuer);
  return this;
}

代码示例来源:origin: oracle/helidon

/**
 * Initialize builder from specified configuration properties.
 * <p>
 * Supported configuration {@code properties}:
 * <ul>
 * <li>{@code optional} - type {@code boolean}, see {@link #optional()}</li>
 * <li>{@code polling-strategy} - see {@link PollingStrategy} for details about configuration format,
 * see {@link #pollingStrategy(Supplier)} or {@link #pollingStrategy(Function)}</li>
 * </ul>
 *
 * @param metaConfig configuration properties used to initialize a builder instance.
 * @return modified builder instance
 */
protected B init(Config metaConfig) {
  //optional / mandatory
  metaConfig.get(OPTIONAL_KEY)
      .asBoolean()
      .filter(value -> value) //filter `true` only
      .ifPresent(value -> optional());
  //polling-strategy
  metaConfig.get(POLLING_STRATEGY_KEY)
      .ifExists(cfg -> pollingStrategy(PollingStrategyConfigMapper.instance().apply(cfg, targetType)));
  //retry-policy
  metaConfig.get(RETRY_POLICY_KEY)
      .as(RetryPolicy::create)
      .ifPresent(this::retryPolicy);
  return thisBuilder;
}

代码示例来源:origin: oracle/helidon

config.get("cert-alias").asString().ifPresent(this::certAlias);
config.get("cert-chain").asString().ifPresent(this::certChainAlias);
config.get("trust-store").asBoolean().ifPresent(this::trustStore);

代码示例来源:origin: oracle/helidon

/**
   * Load all properties for this thread pool executor from configuration.
   * Expected keys:
   * <ul>
   * <li>core-pool-size</li>
   * <li>max-pool-size</li>
   * <li>keep-alive-minutes</li>
   * <li>queue-capacity</li>
   * <li>is-daemon</li>
   * <li>thread-name-prefix</li>
   * <li>should-prestart</li>
   * </ul>
   *
   * @param config config located on the key of executor-service
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("core-pool-size").asInt().ifPresent(this::corePoolSize);
    config.get("max-pool-size").asInt().ifPresent(this::maxPoolSize);
    config.get("keep-alive-minutes").asInt().ifPresent(this::keepAliveMinutes);
    config.get("queue-capacity").asInt().ifPresent(this::queueCapacity);
    config.get("is-daemon").asBoolean().ifPresent(this::daemon);
    config.get("thread-name-prefix").asString().ifPresent(this::threadNamePrefix);
    config.get("should-prestart").asBoolean().ifPresent(this::prestart);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Update fields from configuration.
 *
 * @param config Configuration
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("name").asString().ifPresent(this::name);
  config.get("default").asBoolean().ifPresent(this::isDefault);
  config.get("authentication").asList(FlaggedProvider::create)
      .ifPresent(this.authenticators::addAll);
  config.get("authorization").asList(FlaggedProvider::create)
      .ifPresent(this.authorizers::addAll);
  config.get("outbound").asNodeList()
      .ifPresent(configs -> configs.forEach(outConfig -> addOutboundProvider(outConfig.get("name")
                                              .asString()
                                              .get())));
  return this;
}

代码示例来源:origin: oracle/helidon

/**
   * Update this builder from configuration.
   *
   * @param config Configuration at provider (security.provider.x) key
   * @return updated builder instance
   */
  public Builder config(Config config) {
    config.get("optional").asBoolean().ifPresent(this::optional);
    config.get("client-id").asString().ifPresent(this::clientId);
    config.get("proxy-host").asString().ifPresent(this::proxyHost);
    config.get("proxy-port").asInt().ifPresent(this::proxyPort);
    config.get("realm").asString().ifPresent(this::realm);
    config.get("token").as(TokenHandler::create).ifPresent(this::tokenProvider);
    return this;
  }
}

代码示例来源:origin: oracle/helidon

/**
 * Load this builder from a configuration.
 *
 * @param config configuration to load from
 * @return updated builder instance
 */
public Builder config(Config config) {
  config.get("optional").as(Boolean.class).ifPresent(this::optional);
  config.get("authenticate").as(Boolean.class).ifPresent(this::authenticate);
  config.get("propagate").as(Boolean.class).ifPresent(this::propagate);
  config.get("allow-impersonation").asBoolean().ifPresent(this::allowImpersonation);
  config.get("principal-type").as(SubjectType.class).ifPresent(this::subjectType);
  config.get("atn-token.handler").as(TokenHandler.class).ifPresent(this::atnTokenHandler);
  config.get("atn-token").ifExists(this::verifyKeys);
  config.get("atn-token.jwt-audience").asString().ifPresent(this::expectedAudience);
  config.get("sign-token").ifExists(outbound -> outboundConfig(OutboundConfig.create(outbound)));
  config.get("sign-token").ifExists(this::outbound);
  return this;
}

相关文章