Line data Source code
1 : import 'package:testainers/src/testainers_base.dart';
2 : import 'package:testainers/src/testainers_utils.dart';
3 :
4 : class TestainersSshd extends Testainers {
5 : final String? _username;
6 : final String? _password;
7 : int? _port;
8 :
9 1 : TestainersSshd({
10 : String? username,
11 : String? password,
12 : int? port,
13 : super.config,
14 : super.name,
15 : super.image = 'testainers/sshd-container',
16 : super.tag = 'latest',
17 : super.ports = const <int, int>{},
18 : super.env = const <String, String>{},
19 : super.detached = true,
20 : super.remove = true,
21 : super.links,
22 : super.networks,
23 : super.healthCmd = r'sshpass -p "$SSHD_PASSWORD" ssh '
24 : '-o StrictHostKeyChecking=no '
25 : '-o UserKnownHostsFile=/dev/null '
26 : '-o PubkeyAuthentication=no '
27 : r'"$SSHD_USER"@127.0.0.1 uptime',
28 : super.healthInterval = 5,
29 : super.healthRetries = 2,
30 : super.healthTimeout = 3,
31 : super.healthStartPeriod = 1,
32 : super.noHealthcheck,
33 : super.stopTime = 1,
34 : }) : _username = username,
35 : _password = password,
36 : _port = port;
37 :
38 4 : String get username => _username ?? config.defaultUsername;
39 :
40 4 : String get password => _password ?? config.defaultPassword;
41 :
42 2 : int get port => _port ?? -1;
43 :
44 1 : @override
45 : Future<Map<int, int>> portsFilter(Map<int, int> ports) async {
46 2 : _port ??= await TestainersUtils.generatePort();
47 3 : return <int, int>{...ports, _port!: 22};
48 : }
49 :
50 1 : @override
51 : Future<Map<String, String>> envFilter(Map<String, String> env) async =>
52 1 : <String, String>{
53 : ...env,
54 2 : 'SSHD_USER': username,
55 2 : 'SSHD_PASSWORD': password,
56 : };
57 : }
|