import-database-users-and-databases #82

Merged
hsh-michaelhoennig merged 5 commits from import-database-users-and-databases into master 2024-08-02 10:40:16 +02:00
4 changed files with 103 additions and 64 deletions
Showing only changes of commit 194405c577 - Show all commits

View File

@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static java.util.Optional.ofNullable; import static java.util.Optional.ofNullable;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_DATABASE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_INSTANCE;
class HsPostgreSqlDbInstanceHostingAssetValidator extends HostingAssetEntityValidator { class HsPostgreSqlDbInstanceHostingAssetValidator extends HostingAssetEntityValidator {
@ -13,7 +13,7 @@ class HsPostgreSqlDbInstanceHostingAssetValidator extends HostingAssetEntityVali
public HsPostgreSqlDbInstanceHostingAssetValidator() { public HsPostgreSqlDbInstanceHostingAssetValidator() {
super( super(
PGSQL_DATABASE, PGSQL_INSTANCE,
AlarmContact.isOptional(), AlarmContact.isOptional(),
// TODO.spec: PostgreSQL extensions in database and here? also decide which. Free selection or booleans/checkboxes? // TODO.spec: PostgreSQL extensions in database and here? also decide which. Free selection or booleans/checkboxes?

View File

@ -24,10 +24,12 @@ import org.springframework.test.annotation.Commit;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import java.io.Reader; import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; import java.util.function.Function;
@ -107,8 +109,9 @@ public class ImportHostingAssets extends ImportOfficeData {
static final Integer PACKET_ID_OFFSET = 3000000; static final Integer PACKET_ID_OFFSET = 3000000;
static final Integer UNIXUSER_ID_OFFSET = 4000000; static final Integer UNIXUSER_ID_OFFSET = 4000000;
static final Integer EMAILALIAS_ID_OFFSET = 5000000; static final Integer EMAILALIAS_ID_OFFSET = 5000000;
static final Integer DBUSER_ID_OFFSET = 6000000; static final Integer DBINSTANCE_ID_OFFSET = 6000000;
static final Integer DB_ID_OFFSET = 7000000; static final Integer DBUSER_ID_OFFSET = 7000000;
static final Integer DB_ID_OFFSET = 8000000;
record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetRawEntity> serverRef) {} record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetRawEntity> serverRef) {}
@ -116,6 +119,7 @@ public class ImportHostingAssets extends ImportOfficeData {
static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>(); static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>();
static Map<Integer, Hive> hives = new WriteOnceMap<>(); static Map<Integer, Hive> hives = new WriteOnceMap<>();
static Map<Integer, HsHostingAssetRawEntity> hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type? static Map<Integer, HsHostingAssetRawEntity> hostingAssets = new WriteOnceMap<>(); // TODO.impl: separate maps for each type?
static Map<String, HsHostingAssetRawEntity> dbUsersByEngineAndName = new WriteOnceMap<>();
@Test @Test
@Order(11010) @Order(11010)
@ -348,18 +352,26 @@ public class ImportHostingAssets extends ImportOfficeData {
@Test @Test
@Order(15000) @Order(15000)
void createDatabaseInstances() { void createDatabaseInstances() {
// FIXME createDatabaseInstances(hostingAssets.values().stream().filter(ha -> ha.getType()==MANAGED_SERVER).toList());
} }
@Test @Test
@Order(15009) @Order(15009)
void verifyDatabaseINSTANCES() { void verifyDatabaseInstances() {
assumeThatWeAreImportingControlledTestData(); assumeThatWeAreImportingControlledTestData();
// FIXME
// assertThat(firstOfEachType(5, PGSQL_INSTANCE, MARIADB_INSTANCE)).isEqualToIgnoringWhitespace(""" assertThat(firstOfEachType(5, PGSQL_INSTANCE, MARIADB_INSTANCE)).isEqualToIgnoringWhitespace("""
// { {
// } 6000000=HsHostingAssetRawEntity(PGSQL_INSTANCE, vm1061|PgSql.default, vm1061-PostgreSQL default instance, MANAGED_SERVER:vm1061),
// """); 6000001=HsHostingAssetRawEntity(MARIADB_INSTANCE, vm1061|MariaDB.default, vm1061-MariaDB default instance, MANAGED_SERVER:vm1061),
6000002=HsHostingAssetRawEntity(PGSQL_INSTANCE, vm1050|PgSql.default, vm1050-PostgreSQL default instance, MANAGED_SERVER:vm1050),
6000003=HsHostingAssetRawEntity(MARIADB_INSTANCE, vm1050|MariaDB.default, vm1050-MariaDB default instance, MANAGED_SERVER:vm1050),
6000004=HsHostingAssetRawEntity(PGSQL_INSTANCE, vm1068|PgSql.default, vm1068-PostgreSQL default instance, MANAGED_SERVER:vm1068),
6000005=HsHostingAssetRawEntity(MARIADB_INSTANCE, vm1068|MariaDB.default, vm1068-MariaDB default instance, MANAGED_SERVER:vm1068),
6000006=HsHostingAssetRawEntity(PGSQL_INSTANCE, vm1093|PgSql.default, vm1093-PostgreSQL default instance, MANAGED_SERVER:vm1093),
6000007=HsHostingAssetRawEntity(MARIADB_INSTANCE, vm1093|MariaDB.default, vm1093-MariaDB default instance, MANAGED_SERVER:vm1093)
}
""");
} }
@Test @Test
@ -380,16 +392,16 @@ public class ImportHostingAssets extends ImportOfficeData {
assertThat(firstOfEachType(5, PGSQL_USER, MARIADB_USER)).isEqualToIgnoringWhitespace(""" assertThat(firstOfEachType(5, PGSQL_USER, MARIADB_USER)).isEqualToIgnoringWhitespace("""
{ {
6001858=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00, hsh00, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:PGI|hsh00, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$JDiZmaxU+O+ByArLY/CkYZ8HbOk0r/I8LyABnno5gQs=:NI3T500/63dzI1B07Jh3UtQGlukS6JxuS0XoxM/QgAc="}), 7001857=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00, hsh00, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:vm1050|PgSql.default, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$JDiZmaxU+O+ByArLY/CkYZ8HbOk0r/I8LyABnno5gQs=:NI3T500/63dzI1B07Jh3UtQGlukS6JxuS0XoxM/QgAc="}),
6001860=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_hsadmin, hsh00_hsadmin, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:PGI|hsh00_hsadmin, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg="}), 7001858=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00, hsh00, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:vm1050|MariaDB.default, { "password": "*59067A36BA197AD0A47D74909296C5B002A0FB9F"}),
6001861=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_hsadmin_ro, hsh00_hsadmin_ro, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:PGI|hsh00_hsadmin_ro, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8="}), 7001859=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_vorstand, hsh00_vorstand, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:vm1050|PgSql.default, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg="}),
6004908=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_mantis, hsh00_mantis, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:MAI|hsh00_mantis, { "password": "*EA4C0889A22AAE66BBEBC88161E8CF862D73B44F"}), 7001860=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_hsadmin, hsh00_hsadmin, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:vm1050|PgSql.default, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg="}),
6004909=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_mantis_ro, hsh00_mantis_ro, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:MAI|hsh00_mantis_ro, { "password": "*B3BB6D0DA2EC01958616E9B3BCD2926FE8C38383"}), 7001861=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_hsadmin_ro, hsh00_hsadmin_ro, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:vm1050|PgSql.default, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8="}),
6004931=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_phpPgSqlAdmin, hsh00_phpPgSqlAdmin, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:MAI|hsh00_phpPgSqlAdmin, { "password": "*59067A36BA197AD0A47D74909296C5B002A0FB9F"}), 7004908=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_mantis, hsh00_mantis, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:vm1050|MariaDB.default, { "password": "*EA4C0889A22AAE66BBEBC88161E8CF862D73B44F"}),
6004932=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_phpMyAdmin, hsh00_phpMyAdmin, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:MAI|hsh00_phpMyAdmin, { "password": "*3188720B1889EF5447C722629765F296F40257C2"}), 7004909=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_mantis_ro, hsh00_mantis_ro, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:vm1050|MariaDB.default, { "password": "*B3BB6D0DA2EC01958616E9B3BCD2926FE8C38383"}),
6007520=HsHostingAssetRawEntity(MARIADB_USER, MAU|lug00_wla, lug00_wla, MANAGED_WEBSPACE:lug00, MARIADB_INSTANCE:MAI|lug00_wla, { "password": "*11667C0EAC42BF8B0295ABEDC7D2868A835E4DB5"}), 7004931=HsHostingAssetRawEntity(PGSQL_USER, PGU|hsh00_phpPgSqlAdmin, hsh00_phpPgSqlAdmin, MANAGED_WEBSPACE:hsh00, PGSQL_INSTANCE:vm1050|PgSql.default, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8="}),
6007522=HsHostingAssetRawEntity(PGSQL_USER, PGU|lug00_ola, lug00_ola, MANAGED_WEBSPACE:lug00, PGSQL_INSTANCE:PGI|lug00_ola, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$tir+cV3ZzOZeEWurwAJk+8qkvsTAWaBfwx846oYMOr4=:p4yk/4hHkfSMAFxSuTuh3RIrbSpHNBh7h6raVa3nt1c="}), 7004932=HsHostingAssetRawEntity(MARIADB_USER, MAU|hsh00_phpMyAdmin, hsh00_phpMyAdmin, MANAGED_WEBSPACE:hsh00, MARIADB_INSTANCE:vm1050|MariaDB.default, { "password": "*3188720B1889EF5447C722629765F296F40257C2"}),
6007605=HsHostingAssetRawEntity(PGSQL_USER, PGU|mim00_office, mim00_office, MANAGED_WEBSPACE:mim00, PGSQL_INSTANCE:PGI|mim00_office, { "password": "SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$43jziwd1o+nkfjE0zFbks24Zy5GK+km87B7vzEQt4So=:xRQntZxBxdo1JJbhkegnUFKHT0T8MDW75hkQs2S3z6k="}) 7007520=HsHostingAssetRawEntity(MARIADB_USER, MAU|lug00_wla, lug00_wla, MANAGED_WEBSPACE:lug00, MARIADB_INSTANCE:vm1068|MariaDB.default, { "password": "*11667C0EAC42BF8B0295ABEDC7D2868A835E4DB5"})
} }
"""); """);
} }
@ -412,16 +424,16 @@ public class ImportHostingAssets extends ImportOfficeData {
assertThat(firstOfEachType(5, PGSQL_DATABASE, MARIADB_DATABASE)).isEqualToIgnoringWhitespace(""" assertThat(firstOfEachType(5, PGSQL_DATABASE, MARIADB_DATABASE)).isEqualToIgnoringWhitespace("""
{ {
7000077=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_vorstand, hsh00_vorstand, { "encoding": "LATIN1"}), 8000077=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_vorstand, hsh00_vorstand, PGSQL_USER:PGU|hsh00_vorstand, { "encoding": "LATIN1"}),
7000786=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_addr, hsh00_addr, { "encoding": "latin1"}), 8000786=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_addr, hsh00_addr, MARIADB_USER:MAU|hsh00, { "encoding": "latin1"}),
7000805=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_db2, hsh00_db2, { "encoding": "latin1"}), 8000805=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_db2, hsh00_db2, MARIADB_USER:MAU|hsh00, { "encoding": "latin1"}),
7001858=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00, hsh00, { "encoding": "LATIN1"}), 8001858=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00, hsh00, PGSQL_USER:PGU|hsh00, { "encoding": "LATIN1"}),
7001860=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_hsadmin, hsh00_hsadmin, { "encoding": "UTF8"}), 8001860=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_hsadmin, hsh00_hsadmin, PGSQL_USER:PGU|hsh00_hsadmin, { "encoding": "UTF8"}),
7004908=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_mantis, hsh00_mantis, { "encoding": "utf8"}), 8004908=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_mantis, hsh00_mantis, MARIADB_USER:MAU|hsh00_mantis, { "encoding": "utf8"}),
7004931=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_phpPgSqlAdmin, hsh00_phpPgSqlAdmin, { "encoding": "UTF8"}), 8004931=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_phpPgSqlAdmin, hsh00_phpPgSqlAdmin, PGSQL_USER:PGU|hsh00_phpPgSqlAdmin, { "encoding": "UTF8"}),
7004932=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_phpPgSqlAdmin_new, hsh00_phpPgSqlAdmin_new, { "encoding": "UTF8"}), 8004932=HsHostingAssetRawEntity(PGSQL_DATABASE, PGD|hsh00_phpPgSqlAdmin_new, hsh00_phpPgSqlAdmin_new, PGSQL_USER:PGU|hsh00_phpPgSqlAdmin, { "encoding": "UTF8"}),
7004941=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_phpMyAdmin, hsh00_phpMyAdmin, { "encoding": "utf8"}), 8004941=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_phpMyAdmin, hsh00_phpMyAdmin, MARIADB_USER:MAU|hsh00_phpMyAdmin, { "encoding": "utf8"}),
7004942=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_phpMyAdmin_old, hsh00_phpMyAdmin_old, { "encoding": "utf8"}) 8004942=HsHostingAssetRawEntity(MARIADB_DATABASE, MAD|hsh00_phpMyAdmin_old, hsh00_phpMyAdmin_old, MARIADB_USER:MAU|hsh00_phpMyAdmin, { "encoding": "utf8"})
} }
"""); """);
} }
@ -932,6 +944,33 @@ public class ImportHostingAssets extends ImportOfficeData {
}); });
} }
private void createDatabaseInstances(final List<HsHostingAssetRawEntity> parentAssets) {
final var idRef = new AtomicInteger(0);
parentAssets.forEach(pa -> {
if (pa.getSubHostingAssets() == null) {
pa.setSubHostingAssets(new ArrayList<>());
}
final var pgSqlInstanceAsset = HsHostingAssetRawEntity.builder()
.type(PGSQL_INSTANCE)
.parentAsset(pa)
.identifier(pa.getIdentifier() + "|PgSql.default")
.caption(pa.getIdentifier() + "-PostgreSQL default instance")
.build();
pa.getSubHostingAssets().add(pgSqlInstanceAsset);
hostingAssets.put(DBINSTANCE_ID_OFFSET + idRef.getAndIncrement(), pgSqlInstanceAsset);
final var mariaDbInstanceAsset = HsHostingAssetRawEntity.builder()
.type(MARIADB_INSTANCE)
.parentAsset(pa)
.identifier(pa.getIdentifier() + "|MariaDB.default")
.caption(pa.getIdentifier() + "-MariaDB default instance")
.build();
pa.getSubHostingAssets().add(mariaDbInstanceAsset);
hostingAssets.put(DBINSTANCE_ID_OFFSET + idRef.getAndIncrement(), mariaDbInstanceAsset);
});
}
private void importDatabaseUsers(final String[] header, final List<String[]> records) { private void importDatabaseUsers(final String[] header, final List<String[]> records) {
final var columns = new Columns(header); final var columns = new Columns(header);
records.stream() records.stream()
@ -944,20 +983,17 @@ public class ImportHostingAssets extends ImportOfficeData {
final HsHostingAssetType dbUserAssetType = "mysql".equals(engine) ? MARIADB_USER final HsHostingAssetType dbUserAssetType = "mysql".equals(engine) ? MARIADB_USER
: "pgsql".equals(engine) ? PGSQL_USER : "pgsql".equals(engine) ? PGSQL_USER
: failWith("unknown DB engine " + engine); : failWith("unknown DB engine " + engine);
// FIXME: Create one instance for each managed server, not for each db-user! final var hash = dbUserAssetType == MARIADB_USER ? Algorithm.MYSQL_NATIVE : Algorithm.SCRAM_SHA256;
final var name = rec.getString("name");
final var password_hash = rec.getString("password_hash", HashGenerator.using(hash).withRandomSalt().hash("fake pw " + name));
final HsHostingAssetType dbInstanceAssetType = "mysql".equals(engine) ? MARIADB_INSTANCE final HsHostingAssetType dbInstanceAssetType = "mysql".equals(engine) ? MARIADB_INSTANCE
: "pgsql".equals(engine) ? PGSQL_INSTANCE : "pgsql".equals(engine) ? PGSQL_INSTANCE
: failWith("unknown DB engine " + engine); : failWith("unknown DB engine " + engine);
final var hash = dbUserAssetType == MARIADB_USER ? Algorithm.MYSQL_NATIVE : Algorithm.SCRAM_SHA256; final var relatedWebspaceHA = hostingAssets.get(PACKET_ID_OFFSET + packet_id).getParentAsset();
final var name = rec.getString("name"); final var dbInstanceAsset = relatedWebspaceHA.getSubHostingAssets().stream()
final var password_hash = rec.getString("password_hash", HashGenerator.using(hash).withSalt("fixed salt").hash("fake pw " + name)); .filter(ha -> ha.getType() == dbInstanceAssetType)
.findAny().orElseThrow(); // there is exactly one: the default instance for the given type
final var dbInstanceAsset = HsHostingAssetRawEntity.builder()
.type(dbInstanceAssetType)
.parentAsset(hostingAssets.get(PACKET_ID_OFFSET + packet_id).getParentAsset())
.identifier(dbUserAssetType.name().substring(0, 2) + "I|" + name)
.caption(name)
.build();
final var dbUserAsset = HsHostingAssetRawEntity.builder() final var dbUserAsset = HsHostingAssetRawEntity.builder()
.type(dbUserAssetType) .type(dbUserAssetType)
@ -969,6 +1005,7 @@ public class ImportHostingAssets extends ImportOfficeData {
entry("password", password_hash) entry("password", password_hash)
))) )))
.build(); .build();
dbUsersByEngineAndName.put(engine + ":" + name, dbUserAsset);
hostingAssets.put(DBUSER_ID_OFFSET + dbuser_id, dbUserAsset); hostingAssets.put(DBUSER_ID_OFFSET + dbuser_id, dbUserAsset);
}); });
} }
@ -980,24 +1017,25 @@ public class ImportHostingAssets extends ImportOfficeData {
.map(row -> new Record(columns, row)) .map(row -> new Record(columns, row))
.forEach(rec -> { .forEach(rec -> {
final var database_id = rec.getInteger("database_id"); final var database_id = rec.getInteger("database_id");
final var packet_id = rec.getInteger("packet_id");
final var owning_dbuser_id = 0; // FIXME
final var engine = rec.getString("engine"); final var engine = rec.getString("engine");
final var owner = rec.getString("owner");
final var owningDbUserHA = dbUsersByEngineAndName.get(engine + ":" + owner);
assertThat(owningDbUserHA).as("owning user for " + (engine + ":" + owner) + " not found").isNotNull();
final HsHostingAssetType type = "mysql".equals(engine) ? MARIADB_DATABASE final HsHostingAssetType type = "mysql".equals(engine) ? MARIADB_DATABASE
: "pgsql".equals(engine) ? PGSQL_DATABASE : "pgsql".equals(engine) ? PGSQL_DATABASE
: failWith("unknown DB engine " + engine); : failWith("unknown DB engine " + engine);
final var name = rec.getString("name"); final var name = rec.getString("name");
final var encoding = rec.getString("encoding"); final var encoding = rec.getString("encoding").replaceAll("[-_]+", "");
final var dbUserAsset = HsHostingAssetRawEntity.builder() final var dbAsset = HsHostingAssetRawEntity.builder()
.type(type) .type(type)
.parentAsset(hostingAssets.get(DBUSER_ID_OFFSET + owning_dbuser_id)) .parentAsset(owningDbUserHA)
.identifier(type.name().substring(0, 2) + "D|" + name) .identifier(type.name().substring(0, 2) + "D|" + name)
.caption(name) .caption(name)
.config(ofEntries( .config(ofEntries(
entry("encoding", encoding) entry("encoding", type == MARIADB_DATABASE ? encoding.toLowerCase() : encoding.toUpperCase())
)) ))
.build(); .build();
hostingAssets.put(DB_ID_OFFSET + database_id, dbUserAsset); hostingAssets.put(DB_ID_OFFSET + database_id, dbAsset);
}); });
} }

View File

@ -2,15 +2,14 @@ database_id;engine;packet_id;name;owner;encoding
77;pgsql;630;hsh00_vorstand;hsh00_vorstand;LATIN1 77;pgsql;630;hsh00_vorstand;hsh00_vorstand;LATIN1
786;mysql;630;hsh00_addr;hsh00;latin1 786;mysql;630;hsh00_addr;hsh00;latin1
805;mysql;630;hsh00_db2;hsh00;latin1 805;mysql;630;hsh00_db2;hsh00;LATIN-1
291568;pgsql;1112;mih00_invoicing;mih00_invoicing;UTF8
1858;pgsql;630;hsh00;hsh00;LATIN1 1858;pgsql;630;hsh00;hsh00;LATIN1
1860;pgsql;630;hsh00_hsadmin;hsh00_hsadmin;UTF8 1860;pgsql;630;hsh00_hsadmin;hsh00_hsadmin;UTF8
4931;pgsql;630;hsh00_phpPgSqlAdmin;hsh00_phpPgSqlAdmin;UTF8 4931;pgsql;630;hsh00_phpPgSqlAdmin;hsh00_phpPgSqlAdmin;UTF8
4932;pgsql;630;hsh00_phpPgSqlAdmin_new;hsh00_phpPgSqlAdmin;UTF8 4932;pgsql;630;hsh00_phpPgSqlAdmin_new;hsh00_phpPgSqlAdmin;utf8
4908;mysql;630;hsh00_mantis;hsh00_mantis;utf8 4908;mysql;630;hsh00_mantis;hsh00_mantis;UTF-8
4941;mysql;630;hsh00_phpMyAdmin;hsh00_phpMyAdmin;utf8 4941;mysql;630;hsh00_phpMyAdmin;hsh00_phpMyAdmin;utf8
4942;mysql;630;hsh00_phpMyAdmin_old;hsh00_phpMyAdmin;utf8 4942;mysql;630;hsh00_phpMyAdmin_old;hsh00_phpMyAdmin;utf8

1 database_id engine packet_id name owner encoding
2 77 pgsql 630 hsh00_vorstand hsh00_vorstand LATIN1
3 786 mysql 630 hsh00_addr hsh00 latin1
4 805 mysql 630 hsh00_db2 hsh00 LATIN-1
5 1858 pgsql 630 hsh00 hsh00 LATIN1
6 1860 pgsql 630 hsh00_hsadmin hsh00_hsadmin UTF8
7 4931 pgsql 630 hsh00_phpPgSqlAdmin hsh00_phpPgSqlAdmin UTF8
8 4932 pgsql 630 hsh00_phpPgSqlAdmin_new hsh00_phpPgSqlAdmin utf8
9 4908 mysql 630 hsh00_mantis hsh00_mantis UTF-8
10 4941 mysql 630 hsh00_phpMyAdmin hsh00_phpMyAdmin utf8
11 4942 mysql 630 hsh00_phpMyAdmin_old hsh00_phpMyAdmin utf8
12 7520 mysql 1094 lug00_wla lug00_wla utf8
13 7521 mysql 1094 lug00_wla_test lug00_wla utf8
14 7522 pgsql 1094 lug00_ola lug00_ola UTF8
15 7523 pgsql 1094 lug00_ola_Test lug00_ola UTF8
16 7604 mysql 1112 mim00_test mim00_test latin1
17 7605 pgsql 1112 mim00_office mim00_office UTF8

View File

@ -1,15 +1,17 @@
dbuser_id;engine;packet_id;name;password_hash dbuser_id;engine;packet_id;name;password_hash
1858;pgsql;630;hsh00 1857;pgsql;630;hsh00;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$JDiZmaxU+O+ByArLY/CkYZ8HbOk0r/I8LyABnno5gQs=:NI3T500/63dzI1B07Jh3UtQGlukS6JxuS0XoxM/QgAc=
1860;pgsql;630;hsh00_hsadmin 1858;mysql;630;hsh00;*59067A36BA197AD0A47D74909296C5B002A0FB9F
1861;pgsql;630;hsh00_hsadmin_ro 1859;pgsql;630;hsh00_vorstand;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg=
4931;mysql;630;hsh00_phpPgSqlAdmin 1860;pgsql;630;hsh00_hsadmin;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg=
4908;mysql;630;hsh00_mantis 1861;pgsql;630;hsh00_hsadmin_ro;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8=
4909;mysql;630;hsh00_mantis_ro 4931;pgsql;630;hsh00_phpPgSqlAdmin;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8=
4932;mysql;630;hsh00_phpMyAdmin 4908;mysql;630;hsh00_mantis;*EA4C0889A22AAE66BBEBC88161E8CF862D73B44F
4909;mysql;630;hsh00_mantis_ro;*B3BB6D0DA2EC01958616E9B3BCD2926FE8C38383
4932;mysql;630;hsh00_phpMyAdmin;*3188720B1889EF5447C722629765F296F40257C2
7520;mysql;1094;lug00_wla 7520;mysql;1094;lug00_wla;*11667C0EAC42BF8B0295ABEDC7D2868A835E4DB5
7522;pgsql;1094;lug00_ola 7522;pgsql;1094;lug00_ola;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$tir+cV3ZzOZeEWurwAJk+8qkvsTAWaBfwx846oYMOr4=:p4yk/4hHkfSMAFxSuTuh3RIrbSpHNBh7h6raVa3nt1c=
7604;mysql;1112;mim00_test 7604;mysql;1112;mim00_test;*156CFD94A0594A5C3F4C6742376DDF4B8C5F6D90
7605;pgsql;1112;mim00_office 7605;pgsql;1112;mim00_office;SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$43jziwd1o+nkfjE0zFbks24Zy5GK+km87B7vzEQt4So=:xRQntZxBxdo1JJbhkegnUFKHT0T8MDW75hkQs2S3z6k=

1 dbuser_id engine packet_id name password_hash
2 1857 pgsql 630 hsh00 SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$JDiZmaxU+O+ByArLY/CkYZ8HbOk0r/I8LyABnno5gQs=:NI3T500/63dzI1B07Jh3UtQGlukS6JxuS0XoxM/QgAc=
3 1858 mysql 630 hsh00 *59067A36BA197AD0A47D74909296C5B002A0FB9F
4 1859 pgsql 630 hsh00_vorstand SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg=
5 1860 pgsql 630 hsh00_hsadmin SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$54Wh+OGx/GaIvAia+I3k78jHGhqmYwe4+iLssmH5zhk=:D4Gq1z2Li2BVSaZrz1azDrs6pwsIzhq4+suK1Hh6ZIg=
6 1861 pgsql 630 hsh00_hsadmin_ro SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8=
7 4931 pgsql 630 hsh00_phpPgSqlAdmin SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$UhJnJJhmKANbcaG+izWK3rz5bmhhluSuiCJFlUmDVI8=:6AC4mbLfJGiGlEOWhpz9BivvMODhLLHOnRnnktJPgn8=
8 4908 mysql 630 hsh00_mantis *EA4C0889A22AAE66BBEBC88161E8CF862D73B44F
9 4909 mysql 630 hsh00_mantis_ro *B3BB6D0DA2EC01958616E9B3BCD2926FE8C38383
10 4932 mysql 630 hsh00_phpMyAdmin *3188720B1889EF5447C722629765F296F40257C2
11 7520 mysql 1094 lug00_wla *11667C0EAC42BF8B0295ABEDC7D2868A835E4DB5
12 7522 pgsql 1094 lug00_ola SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$tir+cV3ZzOZeEWurwAJk+8qkvsTAWaBfwx846oYMOr4=:p4yk/4hHkfSMAFxSuTuh3RIrbSpHNBh7h6raVa3nt1c=
13 7604 mysql 1112 mim00_test *156CFD94A0594A5C3F4C6742376DDF4B8C5F6D90
14 7605 pgsql 1112 mim00_office SCRAM-SHA-256$4096:Zml4ZWQgc2FsdA==$43jziwd1o+nkfjE0zFbks24Zy5GK+km87B7vzEQt4So=:xRQntZxBxdo1JJbhkegnUFKHT0T8MDW75hkQs2S3z6k=