Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Configuration properties compatible with Spring Boot Relaxed Binding #406

Closed
lukasznyrc opened this issue Jan 29, 2019 · 5 comments
Closed
Labels
component: core An issue related to core functionality - credentials, region resolution type: bug A general bug
Milestone

Comments

@lukasznyrc
Copy link
Contributor

Spring Boot uses some relaxed rules for binding Environment properties to @ConfigurationProperties beans, so there does not need to be an exact match between the Environment property name and the bean property name.
Common examples where this is useful include dash-separated environment properties (for example, context-path binds to contextPath).

This is not a valid case when it comes to Spring Cloud AWS configuration, for example it's not possible to use kebab case, which is recommended for use in .properties and .yml files. Following configuration doesn't work.

cloud:
  aws:
    credentials:
      use-default-aws-credentials-chain: true
      instance-profile: false
      profile-name: my-profile

A working configuration has to be in camel case, which is inconsistent with Spring Boot recommendations:

cloud:
  aws:
    credentials:
      useDefaultAwsCredentialsChain: true
      instanceProfile: false
      profileName: my-profile

Spring Boot: 2.1.2.RELEASE
Spring Cloud AWS: 2.1.0.RELEASE (Greenwich.RELEASE)

@internetstaff
Copy link

I just hit this myself on V2.1.1.RELEASE.

PR seems like it would break non-kebab binding, but that does highlight the source of the problem:

In ContextCredentialsAutoConfiguration, AwsCredentialsProperties has a @ConfigurationProperties annotation for "cloud.aws.credentials".

IntelliJ picks this up and suggests cloud.aws.credentials.use-default-aws-credentials-chain for a property in a yaml config.

It looks like registerBeanDefinitions() then does direct lookups of several properties by property names, avoiding binding and meaning only the camel case version of "cloud.aws.credentials.useDefaultAwsCredentialsChain" and other properties works.

Perhaps AwsCredentialsProperties needs to be extracted then autowired into ContextCredentialsAutoConfiguration for use instead of directly querying properties?

@lukasznyrc
Copy link
Contributor Author

lukasznyrc commented Jun 18, 2019

PR seems like it would break non-kebab binding

No. It works fine for both naming conventions.

Perhaps AwsCredentialsProperties needs to be extracted then autowired into ContextCredentialsAutoConfiguration for use instead of directly querying properties?

What do you mean exactly?

@internetstaff
Copy link

I am surprised that camel case would still work when explicitly querying snake case, since the current problem seems to be that snake case doesn't work because it's explicitly querying for camel case. :)

I was thinking that if AwsCredentialsProperties was extracted, it could be configured with e.g. ConfigurationProperties and use the existing relaxed binding support without explicitly querying properties and thus be more flexible?

@darrelldraney
Copy link

darrelldraney commented Jul 24, 2019

With spring boot 2 all reading of environment variables should be done in lower kebab case. https://github.com/spring-projects/spring-boot/wiki/relaxed-binding-2.0#reading-properties-from-the-environment

@frommeyerc
Copy link

We just also run into this issue. Is there anything we could do to have this in the released version soon?

tac-yacht added a commit to tac-yacht/spring-cloud-aws that referenced this issue Mar 28, 2020
@maciejwalkowiak maciejwalkowiak added component: core An issue related to core functionality - credentials, region resolution type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 30, 2020
@maciejwalkowiak maciejwalkowiak added this to the 2.2.3 milestone May 30, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue May 31, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue May 31, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
maciejwalkowiak pushed a commit to maciejwalkowiak/spring-cloud-aws that referenced this issue Oct 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
component: core An issue related to core functionality - credentials, region resolution type: bug A general bug
6 participants