cs-codex-dist-tests/Framework/KubernetesWorkflow/K8sNameUtils.cs

34 lines
857 B
C#
Raw Normal View History

2023-09-15 10:25:10 +00:00
namespace KubernetesWorkflow
{
public static class K8sNameUtils
{
public static string Format(string s)
{
return Format(s, 62);
}
public static string FormatPortName(string s)
{
return Format(s, 15);
}
private static string Format(string s, int maxLength)
2023-09-15 10:25:10 +00:00
{
var result = s.ToLowerInvariant()
.Replace("_", "-")
2023-09-15 10:25:10 +00:00
.Replace(" ", "-")
.Replace(":", "-")
.Replace("/", "-")
.Replace("\\", "-")
.Replace("[", "-")
.Replace("]", "-")
.Replace(",", "-");
result = result.Trim('-');
if (result.Length > maxLength) result = result.Substring(0, maxLength);
return result;
2023-09-15 10:25:10 +00:00
}
}
}