-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e283b2f
commit 3ed8a01
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ore-metadata-service/src/main/java/com/lgi/appstore/metadata/info/AppInfoContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 Liberty Global B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.lgi.appstore.metadata.info; | ||
|
||
import org.springframework.boot.actuate.info.Info; | ||
import org.springframework.boot.actuate.info.InfoContributor; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.TimeZone; | ||
|
||
@Component | ||
public class AppInfoContributor implements InfoContributor { | ||
|
||
private static final String MISSING_DETAIL_VALUE = "not specified"; | ||
private static final Map<String, Object> DETAILS = new HashMap<>(); | ||
|
||
private final Environment environment; | ||
|
||
public AppInfoContributor(Environment environment) { | ||
this.environment = environment; | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
addAppPropertyDetailFromEnvironment(AppProperty.APP_BRANCH); | ||
addAppPropertyDetailFromEnvironment(AppProperty.APP_BUILD_TIME); | ||
addAppPropertyDetailFromEnvironment(AppProperty.APP_NAME); | ||
addAppPropertyDetailFromEnvironment(AppProperty.APP_REVISION); | ||
addAppPropertyDetail(AppProperty.APP_START_TIME, getCurrentTime()); | ||
addAppPropertyDetailFromEnvironment(AppProperty.APP_VERSION); | ||
addAppPropertyDetailFromEnvironment(AppProperty.HOST_NAME); | ||
addAppPropertyDetailFromEnvironment(AppProperty.STACK_NAME); | ||
} | ||
|
||
@Override | ||
public void contribute(Info.Builder builder) { | ||
builder.withDetails(DETAILS); | ||
} | ||
|
||
private void addAppPropertyDetailFromEnvironment(AppProperty appProperty) { | ||
addAppPropertyDetail(appProperty, getAppPropertyValueFromEnvironment(appProperty)); | ||
} | ||
|
||
private void addAppPropertyDetail(AppProperty appProperty, Object value) { | ||
DETAILS.put(appProperty.toString(), value); | ||
} | ||
|
||
private Object getAppPropertyValueFromEnvironment(AppProperty appProperty) { | ||
return Optional.ofNullable(environment.getProperty(appProperty.toString())) | ||
.orElse(MISSING_DETAIL_VALUE); | ||
} | ||
|
||
public static String getCurrentTime() { | ||
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
df.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
return df.format(new Date()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
appstore-metadata-service/src/main/java/com/lgi/appstore/metadata/info/AppProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 Liberty Global B.V. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.lgi.appstore.metadata.info; | ||
|
||
public enum AppProperty { | ||
APP_BRANCH, | ||
APP_BUILD_TIME, | ||
APP_NAME, | ||
APP_REVISION, | ||
APP_START_TIME, | ||
APP_VERSION, | ||
HOST_NAME, | ||
STACK_NAME | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters