-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes the cluster ID (previously system UUID) available to other instances and services. Instead of `Config.getInstance().getSystemUuid()`, `ClusterInfo.getClusterId()` must be used from now on. As the cluster ID is only generated once and then never updated, it will only be loaded upon first invocation of `ClusterInfo.getClusterId()`. Updating of the cluster ID via API or UI is prevented by marking it as read-only. Relates to DependencyTrack/hyades#925 Signed-off-by: nscuro <[email protected]>
- Loading branch information
Showing
8 changed files
with
237 additions
and
75 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.common; | ||
|
||
import alpine.Config; | ||
import alpine.model.ConfigProperty; | ||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import org.dependencytrack.model.ConfigPropertyConstants; | ||
import org.dependencytrack.persistence.QueryManager; | ||
|
||
import javax.jdo.Query; | ||
import java.util.UUID; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public final class ClusterInfo { | ||
|
||
private static final Supplier<String> CLUSTER_ID_SUPPLIER = Suppliers.memoize(ClusterInfo::loadClusterId); | ||
|
||
public static String getClusterId() { | ||
return CLUSTER_ID_SUPPLIER.get(); | ||
} | ||
|
||
private static String loadClusterId() { | ||
if (Config.isUnitTestsEnabled()) { | ||
return UUID.randomUUID().toString(); | ||
} | ||
|
||
try (final var qm = new QueryManager()) { | ||
final Query<ConfigProperty> query = qm.getPersistenceManager().newQuery(ConfigProperty.class); | ||
query.setFilter("groupName == :groupName && propertyName == :propertyName"); | ||
query.setParameters( | ||
ConfigPropertyConstants.INTERNAL_CLUSTER_ID.getGroupName(), | ||
ConfigPropertyConstants.INTERNAL_CLUSTER_ID.getPropertyName() | ||
); | ||
query.setResult("propertyValue"); | ||
|
||
try { | ||
final String clusterId = query.executeResultUnique(String.class); | ||
return requireNonNull(clusterId, "Cluster ID must not be null"); | ||
} finally { | ||
query.closeAll(); | ||
} | ||
} | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/dependencytrack/model/ConfigPropertyAccessMode.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,27 @@ | ||
/* | ||
* This file is part of Dependency-Track. | ||
* | ||
* 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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright (c) OWASP Foundation. All Rights Reserved. | ||
*/ | ||
package org.dependencytrack.model; | ||
|
||
public enum ConfigPropertyAccessMode { | ||
|
||
READ_ONLY, | ||
|
||
READ_WRITE | ||
|
||
} |
170 changes: 96 additions & 74 deletions
170
src/main/java/org/dependencytrack/model/ConfigPropertyConstants.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.EnvironmentVariables; | ||
|
@@ -34,6 +35,11 @@ public class ManagedHttpClientFactoryTest { | |
@Rule | ||
public EnvironmentVariables environmentVariables = new EnvironmentVariables(); | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
Config.enableUnitTests(); | ||
} | ||
|
||
@Before | ||
public void before() { | ||
environmentVariables.set("http_proxy", "http://acme%5Cusername:[email protected]:1080"); | ||
|
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