buildRemoteWorkspaceArgs function

List<String> buildRemoteWorkspaceArgs(
  1. RemoteGitProgramArgs programArgs, {
  2. RemoteWorkspaceOptions options = const RemoteWorkspaceOptions(),
})

Builds pulumi CLI arguments required for remote operations.

Implementation

List<String> buildRemoteWorkspaceArgs(
  RemoteGitProgramArgs programArgs, {
  RemoteWorkspaceOptions options = const RemoteWorkspaceOptions(),
}) {
  validateRemoteGitProgramArgs(
    programArgs,
    inheritSettings: options.inheritSettings,
  );

  final args = <String>['--remote'];
  if (programArgs.url != null && programArgs.url!.isNotEmpty) {
    args.add(programArgs.url!);
  }

  if (programArgs.projectPath != null && programArgs.projectPath!.isNotEmpty) {
    args.addAll(<String>['--remote-git-repo-dir', programArgs.projectPath!]);
  }
  if (programArgs.branch != null && programArgs.branch!.isNotEmpty) {
    args.addAll(<String>['--remote-git-branch', programArgs.branch!]);
  }
  if (programArgs.commitHash != null && programArgs.commitHash!.isNotEmpty) {
    args.addAll(<String>['--remote-git-commit', programArgs.commitHash!]);
  }

  final auth = programArgs.auth;
  if (auth != null) {
    if (auth.personalAccessToken != null &&
        auth.personalAccessToken!.isNotEmpty) {
      args.addAll(<String>[
        '--remote-git-auth-access-token',
        auth.personalAccessToken!,
      ]);
    }
    if (auth.sshPrivateKey != null && auth.sshPrivateKey!.isNotEmpty) {
      args.addAll(<String>[
        '--remote-git-auth-ssh-private-key',
        auth.sshPrivateKey!,
      ]);
    }
    if (auth.sshPrivateKeyPath != null && auth.sshPrivateKeyPath!.isNotEmpty) {
      args.addAll(<String>[
        '--remote-git-auth-ssh-private-key-path',
        auth.sshPrivateKeyPath!,
      ]);
    }
    if (auth.password != null && auth.password!.isNotEmpty) {
      args.addAll(<String>['--remote-git-auth-password', auth.password!]);
    }
    if (auth.username != null && auth.username!.isNotEmpty) {
      args.addAll(<String>['--remote-git-auth-username', auth.username!]);
    }
  }

  for (final entry in options.envVars.entries) {
    final key = entry.key;
    final value = entry.value;
    if (value is String) {
      args.addAll(<String>['--remote-env', '$key=$value']);
      continue;
    }
    if (value is RemoteSecret) {
      args.addAll(<String>['--remote-env-secret', '$key=${value.secret}']);
      continue;
    }
    throw ArgumentError("unexpected env value '$value' for key '$key'");
  }

  for (final command in options.preRunCommands) {
    args.addAll(<String>['--remote-pre-run-command', command]);
  }

  if (options.skipInstallDependencies) {
    args.add('--remote-skip-install-dependencies');
  }

  if (options.executorImage != null) {
    args.add('--remote-executor-image=${options.executorImage!.image}');
    final credentials = options.executorImage!.credentials;
    if (credentials != null) {
      args.add('--remote-executor-image-username=${credentials.username}');
      args.add('--remote-executor-image-password=${credentials.password}');
    }
  }

  if (options.inheritSettings) {
    args.add('--remote-inherit-settings');
  }

  return args;
}