-
Notifications
You must be signed in to change notification settings - Fork 105
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
Showing
4 changed files
with
169 additions
and
21 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
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,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.walmartlabs.concord.it</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>2.1.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>testing-concord-server</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.walmartlabs.concord.server</groupId> | ||
<artifactId>concord-server</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.walmartlabs.concord.server.plugins.ansible</groupId> | ||
<artifactId>concord-ansible-plugin</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.walmartlabs.concord.server.plugins</groupId> | ||
<artifactId>concord-oneops-plugin</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.walmartlabs.concord.server.plugins.noderoster</groupId> | ||
<artifactId>concord-noderoster-plugin</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.walmartlabs.concord.server.plugins</groupId> | ||
<artifactId>pfed-sso</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>postgresql</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.typesafe</groupId> | ||
<artifactId>config</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
97 changes: 97 additions & 0 deletions
97
...g-server/src/main/java/com/walmartlabs/concord/it/testingserver/TestingConcordServer.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,97 @@ | ||
package com.walmartlabs.concord.it.testingserver; | ||
|
||
/*- | ||
* ***** | ||
* Concord | ||
* ----- | ||
* Copyright (C) 2017 - 2023 Walmart Inc. | ||
* ----- | ||
* 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. | ||
* ===== | ||
*/ | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import com.typesafe.config.ConfigParseOptions; | ||
import com.typesafe.config.ConfigResolveOptions; | ||
import com.walmartlabs.concord.server.ConcordServer; | ||
import com.walmartlabs.concord.server.ConcordServerModule; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Base64; | ||
import java.util.Map; | ||
|
||
public class TestingConcordServer implements AutoCloseable { | ||
|
||
private PostgreSQLContainer<?> db; | ||
private ConcordServer server; | ||
|
||
public TestingConcordServer start() throws Exception { | ||
db = new PostgreSQLContainer<>("postgres:15-alpine"); | ||
db.start(); | ||
|
||
server = ConcordServer.withModules(new ConcordServerModule(prepareConfig(db))) | ||
.start(); | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
this.stop(); | ||
} | ||
|
||
public void stop() throws Exception { | ||
if (server != null) { | ||
server.stop(); | ||
server = null; | ||
} | ||
|
||
if (db != null) { | ||
db.stop(); | ||
db = null; | ||
} | ||
} | ||
|
||
private static Config prepareConfig(PostgreSQLContainer<?> db) { | ||
Config testConfig = ConfigFactory.parseMap(Map.of( | ||
"db.url", db.getJdbcUrl(), | ||
"db.appUsername", db.getUsername(), | ||
"db.appPassword", db.getPassword(), | ||
"db.inventoryUsername", db.getUsername(), | ||
"db.inventoryPassword", db.getPassword(), | ||
"db.changeLogParameters.defaultAdminToken", "foobar", | ||
"secretStore.serverPassword", randomString(), | ||
"secretStore.secretStoreSalt", randomString(), | ||
"secretStore.projectSecretSalt", randomString() | ||
)); | ||
|
||
Config defaultConfig = ConfigFactory.load("concord-server.conf", ConfigParseOptions.defaults(), ConfigResolveOptions.defaults().setAllowUnresolved(true)) | ||
.getConfig("concord-server"); | ||
|
||
return testConfig.withFallback(defaultConfig).resolve(); | ||
} | ||
|
||
private static String randomString() { | ||
byte[] ab = new byte[64]; | ||
new SecureRandom().nextBytes(ab); | ||
return Base64.getEncoder().encodeToString(ab); | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
TestingConcordServer server = new TestingConcordServer().start(); | ||
Thread.sleep(100000); | ||
server.stop(); | ||
} | ||
} |
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