Split spec_service_binding.go by app type: Spring Boot app, other app#105
Conversation
There was a problem hiding this comment.
Copilot reviewed 6 out of 14 changed files in this pull request and generated 1 comment.
Files not reviewed (8)
- cli/azd/resources/scaffold/templates/resources.bicept: Language not supported
- cli/azd/internal/scaffold/spec_service_binding_test.go: Evaluated as low risk
- cli/azd/internal/repository/app_init.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/spec.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env.go: Evaluated as low risk
Comments suppressed due to low confidence (4)
cli/azd/internal/binding/binding_test.go:151
- The test case 'invalid input' in 'TestToTargetAndInfoType' should have an actual invalid input to test the function's behavior with invalid data.
input: "${binding:azure.db.mysql::username}"
cli/azd/internal/binding/binding_common.go:22
- The error message should use 'common source' instead of 'spring boot app' to match the context.
return nil, fmt.Errorf("unsupported target type when binding for spring boot app, target.Type = %s", target.Type)
cli/azd/pkg/project/scaffold_gen.go:207
- Ensure that the changes involving the merging of environment variables using
MergeMapWithDuplicationCheckare covered by tests. This includes scenarios with and without duplication.
serviceSpec.Envs, err = binding.MergeMapWithDuplicationCheck(serviceSpec.Envs, projectConfig.Services[resource.Name].Env)
cli/azd/pkg/project/scaffold_gen.go:255
- Ensure that the changes involving the handling of different source types (e.g., Spring Boot apps) are covered by tests. This includes verifying that the correct environment variables are returned for each source type.
sourceType := toSourceType(userService.Language)
…pec_service_binding
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot reviewed 6 out of 14 changed files in this pull request and generated no comments.
Files not reviewed (8)
- cli/azd/resources/scaffold/templates/resources.bicept: Language not supported
- cli/azd/internal/scaffold/spec_service_binding_test.go: Evaluated as low risk
- cli/azd/internal/repository/app_init.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/spec.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env.go: Evaluated as low risk
Comments suppressed due to low confidence (2)
cli/azd/internal/binding/binding_spring_boot.go:1
- The new functions for generating Spring Boot environment variables should be covered by tests to ensure they work as expected.
package binding
cli/azd/internal/binding/binding_common.go:22
- The error message incorrectly mentions "spring boot app." It should be updated to "common source."
return nil, fmt.Errorf("unsupported target type when binding for spring boot app, target.Type = %s", target.Type)
| func GetBindingEnvs(source Source, target Target) (map[string]string, | ||
| error) { | ||
| switch source.Type { | ||
| case Java, SpringBoot: // todo: support other Java types |
There was a problem hiding this comment.
This todo will not be done in current PR.
There was a problem hiding this comment.
Copilot reviewed 6 out of 14 changed files in this pull request and generated 1 comment.
Files not reviewed (8)
- cli/azd/resources/scaffold/templates/resources.bicept: Language not supported
- cli/azd/internal/scaffold/spec_service_binding_test.go: Evaluated as low risk
- cli/azd/internal/repository/app_init.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/spec.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env.go: Evaluated as low risk
Comments suppressed due to low confidence (4)
cli/azd/internal/binding/binding_spring_boot.go:93
- The InfoType used for 'spring.data.mongodb.uri' should be 'InfoTypeConnectionString' instead of 'InfoTypeJdbcUrl'.
"spring.data.mongodb.uri": ToBindingEnv(target, InfoTypeJdbcUrl),
cli/azd/internal/binding/binding_common.go:22
- The error message should be 'unsupported target type when binding for common source, target.Type = %s'.
return nil, fmt.Errorf("unsupported target type when binding for spring boot app, target.Type = %s", target.Type)
cli/azd/pkg/project/scaffold_gen.go:339
- [nitpick] The variable name 'sourceType' is not very descriptive. It should be renamed to 'bindingSourceType'.
sourceType := toSourceType(userService.Language)
cli/azd/pkg/project/scaffold_gen.go:349
- The changes to the 'printEnvListAboutUses' function introduce new behavior that is not covered by tests. Add tests to ensure this function works correctly with the new 'binding' package.
func printEnvListAboutUses(infraSpec *scaffold.InfraSpec, projectConfig *ProjectConfig, console input.Console, ctx context.Context) error {
…Delete related todo.
| ServiceTypeHostContainerApp: { | ||
| ServiceBindingInfoTypeHost: "https://{{BackendName}}.${containerAppsEnvironment.outputs.defaultDomain}", | ||
| binding.AzureContainerApp: { | ||
| binding.InfoTypeHost: "'https://{{BackendName}}.${containerAppsEnvironment.outputs.defaultDomain}'", |
There was a problem hiding this comment.
FYI: Added ' because it's a string value.
…tityClientId" to make it easier to understand.
| run: | | ||
| cd ./cli/azd | ||
| go test $(go list ./... | grep -v github.com/azure/azure-dev/cli/azd/test/functional) -cover -v | ||
| go test $(go list ./... | grep -v github.com/azure/azure-dev/cli/azd/test/functional | grep -v github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning/terraform) -cover -v |
There was a problem hiding this comment.
Ignore the test failure in current PR because it's not caused by current PR. The failure already exists in previous PR: #104
Maybe this failure can be fixed by merge upstream main, but I'm not sure. Anyway, skip related test in current PR.
|
|
||
| func toSourceType(language appdetect.Language) binding.SourceType { | ||
| switch language { | ||
| case appdetect.Java: |
There was a problem hiding this comment.
Currently, application will not be detected as SpringBoot, but when an application be detected as SpringBoot, it will take effect. Keep SpringBoot type is just for future usage.
Delete SpringBoot type will make it confusing: An application has type Java, but is called binding_spring_boot.go.
| func BindToPostgres(sourceType binding.SourceType, serviceSpec *ServiceSpec, postgres *DatabasePostgres) error { | ||
| serviceSpec.DbPostgres = postgres | ||
| envs, err := GetServiceBindingEnvsForPostgres(*postgres) | ||
| envs, err := binding.GetBindingEnvs(binding.Source{Type: sourceType}, |
There was a problem hiding this comment.
So the workflow of these envs is like:
- App detection to define the app types, aka language
- Then in scaffold, we get the env list, based on the app type + the resource type
- In the bicep files, we inject the envs
So the only thing to pass down is the app type?
There was a problem hiding this comment.
App detection to define the app types, aka language
Currently, app type is decided by language, in the future, it can be decided by other information like framework dependency.
Then in scaffold, we get the env list, based on the app type + the resource type
Not only app type, there is some other informations like jsJms isKafka, SpringBootVersion
In the bicep files, we inject the envs
Yes.
So the only thing to pass down is the app type?
Not only the app type, all these information are necessary:
- Source
- AppType
- metadata like: isJms, isKafka, SpringBootVersion
- Target
- Target Type
- AuthType
| } | ||
|
|
||
| func BindToCosmosDb(serviceSpec *ServiceSpec, cosmos *DatabaseCosmosAccount) error { | ||
| func BindToCosmosDb(sourceType binding.SourceType, serviceSpec *ServiceSpec, cosmos *DatabaseCosmosAccount) error { |
There was a problem hiding this comment.
Seems like these methods are very alike, can we reduce them?
| case ResourceTypeMessagingKafka: | ||
| variables, err = binding.GetBindingEnvs(binding.Source{ | ||
| Type: sourceType, | ||
| IsSpringBootKafka: true, |
There was a problem hiding this comment.
No need to refactor in this PR, but isSpringBootKafka is also some footprint we want to reduce.
There was a problem hiding this comment.
All binding related logic has been moved into binding package, so there should be some code to represent the information about is spring boot kafka.
How about keeping current change in current PR, if we want to reduce it, we can do it in another PR.
There was a problem hiding this comment.
Updated. Moved IsSpringBootKafka from Source to Source.Metadata.
|
|
||
| func GetBindingEnvsForSpringBootToPostgresql(authType internal.AuthType) (map[string]string, error) { | ||
| target := Target{Type: AzureDatabaseForPostgresql} | ||
| switch authType { |
There was a problem hiding this comment.
Here we get binding envs based on the app type first, then in each func, we return them based on the auth type.
I have a question that, the different dependencies used also have impact on the binding envs, should return different Env Vars. For example, for the app type: SpringBoot and the authType: ConnectionString of Kafka,
- if the dependency is
spring-cloud-starter-stream-kafka(spring-cloud stream style), it should configure the properties likespring.cloud.stream.kafka.binder.brokers. - if the dependency is
spring-kafka(pure spring), it should configure the property likespring.kafka.bootstrap-servers.
So how to deal with this case?
…er' , which is different from specified PrincipalType 'ServicePrincipal'.
| } | ||
| { | ||
| principalId: principalId | ||
| principalType: 'ServicePrincipal' |
There was a problem hiding this comment.
FYI: This is a bug before current PR.
Error message:
UnmatchedPrincipalType: The PrincipalId 'xxx' has type 'User' , which is different from specified PrincipalType 'ServicePrincipal'.There was a problem hiding this comment.
Copilot reviewed 6 out of 16 changed files in this pull request and generated no comments.
Files not reviewed (10)
- cli/azd/resources/scaffold/templates/resources.bicept: Language not supported
- cli/azd/internal/scaffold/spec_service_binding_test.go: Evaluated as low risk
- cli/azd/internal/scaffold/bicep_env_test.go: Evaluated as low risk
- cli/azd/internal/binding/binding_common.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm.go: Evaluated as low risk
- cli/azd/internal/repository/infra_confirm_test.go: Evaluated as low risk
- cli/azd/pkg/project/scaffold_gen.go: Evaluated as low risk
- cli/azd/internal/scaffold/scaffold.go: Evaluated as low risk
- cli/azd/internal/repository/app_init.go: Evaluated as low risk
- cli/azd/internal/scaffold/spec.go: Evaluated as low risk
Comments suppressed due to low confidence (2)
cli/azd/internal/binding/binding_spring_boot.go:94
- The method name should be
GetBindingEnvsForSpringBootToMongoDBfor consistency.
func GetBindingEnvsForSpringBootToMongoDb(authType internal.AuthType) (map[string]string, error) {
cli/azd/internal/scaffold/bicep_env.go:31
- The ReplaceBindingEnv function should use the correct indices for the substring replacement. The current implementation may not handle cases where the prefix and suffix are not found correctly.
bicepEnvValue = binding.ReplaceBindingEnv(value, bicepEnvValue)
|
Hi, @saragluna , @haoozhang . |



Split spec_service_binding.go by app type: Spring Boot app, other app.