Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 002715a

Browse files
markpollackilayaperumalg
authored andcommitted
Use tile service binding credentials as default property values
Adds CfEnv as a dependency and uses CfEnv to get credentials from a `p-dataflow` service binding to set the SCDF URI property and Oauth2 client credentials properties. Use CfEnv version specification from parent pom
1 parent 34e480c commit 002715a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

spring-cloud-dataflow-composed-task-runner/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
<groupId>org.springframework.cloud</groupId>
3636
<artifactId>spring-cloud-dataflow-rest-client</artifactId>
3737
</dependency>
38+
<dependency>
39+
<groupId>io.pivotal.cfenv</groupId>
40+
<artifactId>java-cfenv</artifactId>
41+
</dependency>
3842
<dependency>
3943
<groupId>org.mockito</groupId>
4044
<artifactId>mockito-core</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2017-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.composedtaskrunner.support;
18+
19+
import java.util.HashMap;
20+
21+
import io.pivotal.cfenv.core.CfCredentials;
22+
import io.pivotal.cfenv.core.CfEnv;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
27+
import org.springframework.context.ApplicationListener;
28+
import org.springframework.core.env.MapPropertySource;
29+
import org.springframework.core.env.StandardEnvironment;
30+
31+
/**
32+
* If the composed task runner is running on Cloud Foundry and is bound to a service instance from SCDF for VMware
33+
* Tanzu, use the values from the service binding credentials to configure the composed task runner.
34+
*
35+
* @author Mike Heath
36+
*/
37+
public class CfServiceBindingPropertySourceInitializer
38+
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
39+
40+
private static final Logger log = LoggerFactory.getLogger(CfServiceBindingPropertySourceInitializer.class);
41+
42+
public static final String PROPERTY_SOURCE_NAME = "p-dataflow";
43+
44+
@Override
45+
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
46+
final CfEnv cfEnv = new CfEnv();
47+
try {
48+
final CfCredentials credentials = cfEnv.findCredentialsByLabel("p-dataflow");
49+
final HashMap<String, Object> propertiesMap = new HashMap<>();
50+
propertiesMap.put("dataflowServerUri", credentials.getString("dataflow-url"));
51+
propertiesMap.put("oauth2ClientCredentialsClientId", credentials.getString("client-id"));
52+
propertiesMap.put("oauth2ClientCredentialsClientSecret", credentials.getString("client-secret"));
53+
propertiesMap.put("oauth2ClientCredentialsTokenUri", credentials.getString("access-token-url"));
54+
55+
final MapPropertySource propertySource = new MapPropertySource(PROPERTY_SOURCE_NAME, propertiesMap);
56+
event.getEnvironment().getPropertySources()
57+
.addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, propertySource);
58+
} catch (IllegalArgumentException e) {
59+
log.debug("No 'p-dataflow' service binding found in VCAP_SERVICES");
60+
}
61+
}
62+
63+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.context.ApplicationListener=\
2+
org.springframework.cloud.dataflow.composedtaskrunner.support.CfServiceBindingPropertySourceInitializer

0 commit comments

Comments
 (0)