|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 VK DIGITAL TECHNOLOGIES LIMITED LIABILITY COMPANY |
| 3 | + * All Rights Reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +package testcontainers.single; |
| 7 | + |
| 8 | +// --8<-- [start:create-single-node] |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | +import java.nio.file.Files; |
| 12 | +import java.nio.file.Path; |
| 13 | +import java.util.Collections; |
| 14 | + |
| 15 | +import org.testcontainers.containers.tarantool.config.ConfigurationUtils; |
| 16 | + |
| 17 | +import io.tarantool.autogen.Tarantool3Configuration; |
| 18 | +import io.tarantool.autogen.credentials.Credentials; |
| 19 | +import io.tarantool.autogen.credentials.users.Users; |
| 20 | +import io.tarantool.autogen.credentials.users.usersProperty.UsersProperty; |
| 21 | +import io.tarantool.autogen.groups.Groups; |
| 22 | +import io.tarantool.autogen.groups.groupsProperty.GroupsProperty; |
| 23 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.Replicasets; |
| 24 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.replicasetsProperty.ReplicasetsProperty; |
| 25 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.replicasetsProperty.instances.Instances; |
| 26 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.replicasetsProperty.instances.instancesProperty.InstancesProperty; |
| 27 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.replicasetsProperty.instances.instancesProperty.iproto.Iproto; |
| 28 | +import io.tarantool.autogen.groups.groupsProperty.replicasets.replicasetsProperty.instances.instancesProperty.iproto.listen.Listen; |
| 29 | + |
| 30 | +public class CreateSingleNode { |
| 31 | + |
| 32 | + public static final String NODE = "test-node"; |
| 33 | + |
| 34 | + public static final CharSequence PWD = "secret"; |
| 35 | + |
| 36 | + public static final String LOGIN = "test-user"; |
| 37 | + |
| 38 | + /* |
| 39 | + Создает конфигурацию вида: |
| 40 | + --- |
| 41 | + credentials: |
| 42 | + users: |
| 43 | + test-user: |
| 44 | + password: "secret" |
| 45 | + roles: |
| 46 | + - "super" |
| 47 | + groups: |
| 48 | + test-group: |
| 49 | + replicasets: |
| 50 | + test-rs: |
| 51 | + instances: |
| 52 | + test-node: |
| 53 | + iproto: |
| 54 | + listen: |
| 55 | + - uri: "0.0.0.0:3301" |
| 56 | + */ |
| 57 | + public static Path createSingleNodeConfig(Path tempDir) throws IOException { |
| 58 | + final Path pathToConfigFile = Files.createFile(tempDir.resolve("config.yaml")); |
| 59 | + |
| 60 | + final Credentials credentials = |
| 61 | + Credentials.builder() |
| 62 | + .withUsers( |
| 63 | + Users.builder() |
| 64 | + .withAdditionalProperty( |
| 65 | + LOGIN, |
| 66 | + UsersProperty.builder() |
| 67 | + .withRoles(Collections.singletonList("super")) |
| 68 | + .withPassword(PWD.toString()) |
| 69 | + .build()) |
| 70 | + .build()) |
| 71 | + .build(); |
| 72 | + |
| 73 | + final Iproto iproto = |
| 74 | + Iproto.builder() |
| 75 | + .withListen(Collections.singletonList(Listen.builder().withUri("0.0.0.0:3301").build())) |
| 76 | + .build(); |
| 77 | + |
| 78 | + final InstancesProperty instance = InstancesProperty.builder().withIproto(iproto).build(); |
| 79 | + |
| 80 | + final ReplicasetsProperty replicaset = |
| 81 | + ReplicasetsProperty.builder() |
| 82 | + .withInstances(Instances.builder().withAdditionalProperty(NODE, instance).build()) |
| 83 | + .build(); |
| 84 | + |
| 85 | + final GroupsProperty group = |
| 86 | + GroupsProperty.builder() |
| 87 | + .withReplicasets( |
| 88 | + Replicasets.builder().withAdditionalProperty("test-rs", replicaset).build()) |
| 89 | + .build(); |
| 90 | + |
| 91 | + final Tarantool3Configuration configuration = |
| 92 | + Tarantool3Configuration.builder() |
| 93 | + .withGroups(Groups.builder().withAdditionalProperty("test-group", group).build()) |
| 94 | + .withCredentials(credentials) |
| 95 | + .build(); |
| 96 | + |
| 97 | + ConfigurationUtils.writeToFile(configuration, pathToConfigFile); |
| 98 | + return pathToConfigFile; |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +// --8<-- [end:create-single-node] |
0 commit comments