in src/dsc/Commands/Connect/TargetConnectCommandBase.cs [81:142]
protected void ParseTargetOptions()
{
// If multiple container identifiers are present, throw error
if ((targetDeploymentOption.HasValue() && (targetPodOption.HasValue() || targetServiceOption.HasValue()))
|| (targetPodOption.HasValue() && targetServiceOption.HasValue()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_SpecifyOneContainerIdentifier, $"{targetDeploymentOption.Template}, {targetPodOption.Template}, {targetServiceOption.Template}");
}
// At least one pod identifier needs to be present.
if (!targetPodOption.HasValue() && !targetDeploymentOption.HasValue() && !targetServiceOption.HasValue())
{
throw new InvalidUsageException(_operationContext, Resources.Error_SpecifyOneContainerIdentifier, $"{targetDeploymentOption.Template}, {targetPodOption.Template}, {targetServiceOption.Template}");
}
if (targetContainerOption.HasValue())
{
if (!KubernetesUtilities.IsValidK8sObjectName(targetContainerOption.Value()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_InvalidConfigurationValue, targetContainerOption.Template);
}
_operationContext.LoggingProperties.Add(CliConstants.Properties.TargetContainerName, new PII(targetContainerOption.Value()));
_targetContainer = targetContainerOption.Value();
}
if (targetPodOption.HasValue())
{
if (!KubernetesUtilities.IsValidK8sObjectName(targetPodOption.Value()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_InvalidConfigurationValue, targetPodOption.Template);
}
_operationContext.LoggingProperties.Add(CliConstants.Properties.TargetPodName, new PII(targetPodOption.Value()));
_targetPod = targetPodOption.Value();
}
if (targetDeploymentOption.HasValue())
{
if (!KubernetesUtilities.IsValidK8sObjectName(targetDeploymentOption.Value()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_InvalidConfigurationValue, targetDeploymentOption.Template);
}
_operationContext.LoggingProperties.Add(CliConstants.Properties.TargetDeploymentName, new PII(targetDeploymentOption.Value()));
_targetDeployment = targetDeploymentOption.Value();
}
if (targetServiceOption.HasValue())
{
if (!KubernetesUtilities.IsValidK8sObjectName(targetServiceOption.Value()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_InvalidConfigurationValue, targetServiceOption.Template);
}
_operationContext.LoggingProperties.Add(CliConstants.Properties.TargetServiceName, new PII(targetServiceOption.Value()));
_targetService = targetServiceOption.Value();
}
if (targetNamespaceOption.HasValue())
{
if (!KubernetesUtilities.IsValidK8sObjectName(targetNamespaceOption.Value()))
{
throw new InvalidUsageException(_operationContext, Resources.Error_InvalidConfigurationValue, targetNamespaceOption.Template);
}
_targetNamespace = targetNamespaceOption.Value();
}
if (targetKubeConfigContextOption.HasValue())
{
_targetKubeConfigContext = targetKubeConfigContextOption.Value();
}
}