install method

Future<TomSecretsIntegrationState> install(
  1. TomSecretsIntegration integration, {
  2. String? hosts,
})

Writes integration's block (an ssh block for hosts: the block's own patterns when it has some, else *), and for git the helper link. Throws StateError when the endpoint or tsm is not known.

Implementation

Future<TomSecretsIntegrationState> install(
  TomSecretsIntegration integration, {
  String? hosts,
}) async {
  final file = fileOf(integration);
  final text = await _read(file) ?? '';
  switch (integration) {
    case TomSecretsIntegration.ssh:
      if (agentEndpoint == null) {
        throw StateError('the service names no agent (is it running?)');
      }
      final kept = _hostsOf(tomSecretsBlockOf(text) ?? const []);
      await _write(
        file,
        tomSecretsWithBlock(
          text,
          sshBlock(hosts: hosts ?? kept ?? '*'),
          atTop: true,
        ),
        privateDirectory: true,
      );
    case TomSecretsIntegration.git:
      await _link();
      await _write(file, tomSecretsWithBlock(text, gitBlock));
  }
  return status(integration);
}