validateRemoteGitProgramArgs function

void validateRemoteGitProgramArgs(
  1. RemoteGitProgramArgs args, {
  2. bool inheritSettings = false,
})

Validates remote program arguments using upstream Pulumi Automation rules.

Implementation

void validateRemoteGitProgramArgs(
  RemoteGitProgramArgs args, {
  bool inheritSettings = false,
}) {
  if (!isFullyQualifiedStackName(args.stackName)) {
    throw ArgumentError(
      'stack name "${args.stackName}" must be fully qualified.',
    );
  }

  if ((args.url == null || args.url!.isEmpty) && !inheritSettings) {
    throw ArgumentError('url is required if inheritSettings is not set.');
  }

  if (args.branch != null &&
      args.branch!.isNotEmpty &&
      args.commitHash != null &&
      args.commitHash!.isNotEmpty) {
    throw ArgumentError('branch and commitHash cannot both be specified.');
  }

  final branchMissing = args.branch == null || args.branch!.isEmpty;
  final commitMissing = args.commitHash == null || args.commitHash!.isEmpty;
  if (branchMissing && commitMissing && !inheritSettings) {
    throw ArgumentError(
      'either branch or commitHash is required if inheritSettings is not set.',
    );
  }

  if (args.auth?.sshPrivateKey != null &&
      args.auth!.sshPrivateKey!.isNotEmpty &&
      args.auth?.sshPrivateKeyPath != null &&
      args.auth!.sshPrivateKeyPath!.isNotEmpty) {
    throw ArgumentError(
      'sshPrivateKey and sshPrivateKeyPath cannot both be specified.',
    );
  }
}