Skip to content

Commit

Permalink
String parsing improvements to service directory resource names (#3644)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Broderick Phillips <[email protected]>
  • Loading branch information
azure-sdk and benbp authored May 12, 2022
1 parent fc2f7c5 commit f4a5dbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ try {
$BaseName = 't' + (New-Guid).ToString('n').Substring(0, 16)
Log "Generated base name '$BaseName' for CI build"
} else {
$BaseName = GetBaseName $UserName $ServiceDirectory
$BaseName = GetBaseName $UserName (GetServiceLeafDirectoryName $ServiceDirectory)
Log "BaseName was not set. Using default base name '$BaseName'"
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ try {
$ResourceGroupName
} elseif ($CI) {
# Format the resource group name based on resource group naming recommendations and limitations.
"rg-{0}-$BaseName" -f ($serviceName -replace '[\\\/:]', '-').Substring(0, [Math]::Min($serviceName.Length, 90 - $BaseName.Length - 4)).Trim('-')
"rg-{0}-$BaseName" -f ($serviceName -replace '[\.\\\/:]', '-').ToLowerInvariant().Substring(0, [Math]::Min($serviceName.Length, 90 - $BaseName.Length - 4)).Trim('-')
} else {
"rg-$BaseName"
}
Expand Down
5 changes: 3 additions & 2 deletions eng/common/TestResources/SubConfig-Helpers.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function BuildServiceDirectoryPrefix([string]$serviceName) {
$serviceName = $serviceName -replace '[\./\\]', '_'
return $serviceName.ToUpperInvariant() + "_"
}

Expand All @@ -17,8 +18,8 @@ function GetUserName() {

function GetBaseName([string]$user, [string]$serviceDirectoryName) {
# Handle service directories in nested directories, e.g. `data/aztables`
$serviceDirectorySafeName = $serviceDirectoryName -replace '[/\\]', ''
return "$user$serviceDirectorySafeName"
$serviceDirectorySafeName = $serviceDirectoryName -replace '[\./\\]', ''
return "$user$serviceDirectorySafeName".ToLowerInvariant()
}

function ShouldMarkValueAsSecret([string]$serviceName, [string]$key, [string]$value, [array]$allowedValues = @())
Expand Down

0 comments on commit f4a5dbe

Please sign in to comment.