Skip to content

Commit

Permalink
Use spring.factories to provide bean: KeyVaultHealthIndicator. (Azure…
Browse files Browse the repository at this point in the history
…#14337)

* Use spring.factories to provide bean: KeyVaultHealthIndicator.

* Fix error reported by maven-checkstyle-plugin.

Co-authored-by: Rujun Chen <[email protected]>
  • Loading branch information
Rujun Chen and rujche authored Aug 24, 2020
1 parent 6027874 commit 822baf6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<version>2.3.3.RELEASE</version> <!-- {x-version-update;org.springframework.boot:spring-boot-actuator-autoconfigure;external_dependency} -->
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.3.RELEASE</version> <!-- {x-version-update;org.springframework.boot:spring-boot-starter-web;external_dependency} -->
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.azure.keyvault;
package com.microsoft.azure.keyvault.sample;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -11,15 +11,15 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SampleApplication implements CommandLineRunner {
public class KeyVaultSampleApplication implements CommandLineRunner {

private static final Logger LOGGER = LoggerFactory.getLogger(SampleApplication.class);
private static final Logger LOGGER = LoggerFactory.getLogger(KeyVaultSampleApplication.class);

@Value("${keyVaultSecretName}")
private String keyVaultSecretName;

public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
SpringApplication.run(KeyVaultSampleApplication.class, args);
}

public void run(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.azure.test.cosmosdb;

import com.microsoft.azure.test.utils.AppRunner;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.azure.keyvault.spring;

import com.azure.security.keyvault.secrets.SecretClient;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.ConfigurableEnvironment;

@Configuration
@ConditionalOnClass({ SecretClient.class, HealthIndicator.class })
@PropertySource("classpath:/azure-spring-actuator.properties")
public class KeyVaultHealthConfiguration {

@Bean
@ConditionalOnEnabledHealthIndicator("azure-key-vault")
KeyVaultHealthIndicator keyVaultHealthIndicator(ConfigurableEnvironment environment) {
return new KeyVaultHealthIndicator(environment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

package com.microsoft.azure.keyvault.spring;

import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Component;

@ConditionalOnEnabledHealthIndicator("azure-key-vault")
@Component
public class KeyVaultHealthIndicator implements HealthIndicator {

private final ConfigurableEnvironment environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ com.microsoft.azure.spring.autoconfigure.aad.AADOAuth2AutoConfiguration,\
com.microsoft.azure.spring.autoconfigure.b2c.AADB2CAutoConfiguration,\
com.microsoft.azure.spring.autoconfigure.metrics.AzureMonitorMetricsExportAutoConfiguration,\
com.microsoft.azure.spring.autoconfigure.jms.ServiceBusJMSAutoConfiguration,\
com.microsoft.azure.spring.autoconfigure.cosmosdb.CosmosHealthConfiguration
com.microsoft.azure.spring.autoconfigure.cosmosdb.CosmosHealthConfiguration,\
com.microsoft.azure.keyvault.spring.KeyVaultHealthConfiguration

0 comments on commit 822baf6

Please sign in to comment.