Skip to content

Commit 828b1b1

Browse files
feat: Add environment variable for extensions file storage (apache#3819)
1 parent 67c4da6 commit 828b1b1

File tree

6 files changed

+41
-6
lines changed

6 files changed

+41
-6
lines changed

streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public enum Envs {
2323
SP_PORT("SP_PORT"),
2424

2525
SP_CORE_ASSET_BASE_DIR("SP_CORE_ASSET_BASE_DIR"),
26+
SP_EXT_ASSET_BASE_DIR("SP_EXT_ASSET_BASE_DIR"),
2627

2728
SP_CORE_SCHEME("SP_CORE_SCHEME", "http", "http"),
2829
SP_CORE_HOST("SP_CORE_HOST", "backend", "localhost"),

streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ public StringEnvironmentVariable getCoreAssetBaseDir() {
233233
return new StringEnvironmentVariable(Envs.SP_CORE_ASSET_BASE_DIR);
234234
}
235235

236+
@Override
237+
public StringEnvironmentVariable getExtAssetBaseDir() {
238+
return new StringEnvironmentVariable(Envs.SP_EXT_ASSET_BASE_DIR);
239+
}
240+
236241
@Override
237242
public StringEnvironmentVariable getFlinkJarFileLoc() {
238243
return new StringEnvironmentVariable(Envs.SP_FLINK_JAR_FILE_LOC);

streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public interface Environment {
9898

9999
StringEnvironmentVariable getCoreAssetBaseDir();
100100

101+
StringEnvironmentVariable getExtAssetBaseDir();
102+
101103
// Flink Wrapper
102104
StringEnvironmentVariable getFlinkJarFileLoc();
103105

streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/utils/FileProtocolUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.streampipes.connect.iiot.utils;
2020

2121
import org.apache.streampipes.client.StreamPipesClient;
22+
import org.apache.streampipes.commons.environment.Environments;
2223
import org.apache.streampipes.commons.exceptions.connect.ParseException;
2324
import org.apache.streampipes.commons.file.FileHasher;
2425
import org.apache.streampipes.extensions.management.client.StreamPipesClientResolver;
@@ -86,7 +87,12 @@ private static void storeFileLocally(String selectedFilename) throws IOException
8687
}
8788

8889
private static String makeServiceStorageDir() {
89-
return System.getProperty("user.home")
90+
var storageDir = Environments
91+
.getEnvironment()
92+
.getExtAssetBaseDir()
93+
.getValueOrReturn(System.getProperty("user.home"));
94+
95+
return storageDir
9096
+ File.separator
9197
+ ".streampipes"
9298
+ File.separator

streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/config/security/CompositeCertificateValidator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public CompositeCertificateValidator(TrustListManager trustListManager,
7171
public void validateCertificateChain(List<X509Certificate> certificateChain) throws UaException {
7272
PKIXCertPathBuilderResult certPathResult;
7373

74+
X509Certificate peer = getEndEntity(certificateChain);
7475
try {
7576
certPathResult = CertificateValidationUtil.buildTrustedCertPath(
7677
certificateChain,
@@ -79,7 +80,7 @@ public void validateCertificateChain(List<X509Certificate> certificateChain) thr
7980
);
8081
} catch (UaException e) {
8182
if (isCertificateRejected(e.getStatusCode().getValue())) {
82-
sendToCore(certificateChain.get(0));
83+
sendToCore(peer);
8384
}
8485
throw e;
8586
}
@@ -97,6 +98,13 @@ public void validateCertificateChain(List<X509Certificate> certificateChain) thr
9798
);
9899
}
99100

101+
private X509Certificate getEndEntity(List<X509Certificate> chain) {
102+
return chain.stream()
103+
.filter(c -> c.getBasicConstraints() < 0)
104+
.findFirst()
105+
.orElse(chain.get(0));
106+
}
107+
100108
@Override
101109
public void validateCertificateChain(
102110
List<X509Certificate> certificateChain,

streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/utils/OpcUaUtils.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.eclipse.milo.opcua.stack.core.AttributeId;
3535
import org.eclipse.milo.opcua.stack.core.UaException;
3636
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
3739

3840
import java.net.URISyntaxException;
3941
import java.util.List;
@@ -45,6 +47,8 @@
4547
*/
4648
public class OpcUaUtils {
4749

50+
private static final Logger LOG = LoggerFactory.getLogger(OpcUaUtils.class);
51+
4852
private static final String OPC_TCP_PREFIX = "opc.tcp://";
4953

5054
/***
@@ -141,19 +145,28 @@ private static boolean isCertificateException(ExecutionException e) {
141145
Throwable cause = e.getCause();
142146

143147
if (cause instanceof UaException uaException) {
144-
return CompositeCertificateValidator.REJECTED_STATUS_CODES
145-
.contains(uaException.getStatusCode().getValue());
148+
return checkAndLogCertificateException(uaException);
146149
}
147150

148151
Throwable nestedCause = cause != null ? cause.getCause() : null;
149152
if (nestedCause instanceof UaException uaException) {
150-
return CompositeCertificateValidator.REJECTED_STATUS_CODES
151-
.contains(uaException.getStatusCode().getValue());
153+
return checkAndLogCertificateException(uaException);
152154
}
153155

154156
return false;
155157
}
156158

159+
private static boolean checkAndLogCertificateException(UaException e) {
160+
var containsRejectedStatusCode = CompositeCertificateValidator.REJECTED_STATUS_CODES
161+
.contains(e.getStatusCode().getValue());
162+
163+
if (containsRejectedStatusCode) {
164+
var statusCode = CompositeCertificateValidator.REJECTED_STATUS_CODES.stream().filter(code -> code.equals(e.getStatusCode().getValue())).findFirst();
165+
statusCode.ifPresent(sc -> LOG.warn("Status Code: {}", sc));
166+
}
167+
return containsRejectedStatusCode;
168+
}
169+
157170
private static String makeExceptionMessage(ExecutionException e) {
158171
StringBuilder message = new StringBuilder(
159172
"The provided certificate could not be trusted. Administrators can accept this certificate in the settings. "

0 commit comments

Comments
 (0)