Skip to content

Commit

Permalink
Polish "Add Java InfoContributor"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Oct 1, 2021
1 parent 9564657 commit facb1fb
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
import org.springframework.boot.actuate.info.EnvironmentInfoContributor;
import org.springframework.boot.actuate.info.GitInfoContributor;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.actuate.info.java.JavaInfoContributor;
import org.springframework.boot.actuate.info.JavaInfoContributor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down Expand Up @@ -82,7 +82,7 @@ public InfoContributor buildInfoContributor(BuildProperties buildProperties) {
@Bean
@ConditionalOnEnabledInfoContributor("java")
@Order(DEFAULT_ORDER)
public InfoContributor javaInfoContributor() {
public JavaInfoContributor javaInfoContributor() {

This comment has been minimized.

Copy link
@wilkinsona

wilkinsona Oct 4, 2021

Given that it exposes potentially sensitive information and you don't have to provide anything else to switch it on (no build or git properties, for example), I think we should err on the side of caution and make this conditional on an enabled property being set to true.

This comment has been minimized.

Copy link
@wilkinsona

wilkinsona Oct 4, 2021

The counter argument is the env contribution. It's also potentially sensitive and enabled by default. Perhaps the info endpoint not being exposed by default and and being secured by default once it has been exposed is sufficient?

return new JavaInfoContributor();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,10 +27,10 @@
import org.springframework.boot.actuate.info.GitInfoContributor;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.actuate.info.java.JavaInfo;
import org.springframework.boot.actuate.info.java.JavaInfoContributor;
import org.springframework.boot.actuate.info.JavaInfoContributor;
import org.springframework.boot.info.BuildProperties;
import org.springframework.boot.info.GitProperties;
import org.springframework.boot.info.JavaInfo;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2021 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,10 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.info.java;
package org.springframework.boot.actuate.info;

import org.springframework.boot.actuate.info.Info.Builder;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.info.JavaInfo;

/**
* An {@link InfoContributor} that exposes {@link JavaInfo}.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2021 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,11 +14,11 @@
* limitations under the License.
*/

package org.springframework.boot.actuate.info.java;
package org.springframework.boot.actuate.info;

import org.junit.jupiter.api.Test;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.info.JavaInfo;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -34,17 +34,8 @@ void javaInfoShouldBeAdded() {
JavaInfoContributor javaInfoContributor = new JavaInfoContributor();
Info.Builder builder = new Info.Builder();
javaInfoContributor.contribute(builder);

assertThat(builder.build().getDetails().get("java")).isInstanceOf(JavaInfo.class);
JavaInfo javaInfo = (JavaInfo) builder.build().getDetails().get("java");

assertThat(javaInfo.getVendor()).isEqualTo(System.getProperty("java.vendor"));
assertThat(javaInfo.getVersion()).isEqualTo(System.getProperty("java.version"));
assertThat(javaInfo.getRuntime().getName()).isEqualTo(System.getProperty("java.runtime.name"));
assertThat(javaInfo.getRuntime().getVersion()).isEqualTo(System.getProperty("java.runtime.version"));
assertThat(javaInfo.getVm().getName()).isEqualTo(System.getProperty("java.vm.name"));
assertThat(javaInfo.getVm().getVendor()).isEqualTo(System.getProperty("java.vm.vendor"));
assertThat(javaInfo.getVm().getVersion()).isEqualTo(System.getProperty("java.vm.version"));
Info info = builder.build();
assertThat(info.getDetails().get("java")).isInstanceOf(JavaInfo.class);
}

}
Loading

0 comments on commit facb1fb

Please sign in to comment.