查找存储库分支令牌



使用存储库的安全 API 时,使用从分支的"人类"名称派生的字母数字标识符引用各个分支。

此标识符是令牌的最后一部分。例如,主分支,标识符始终6d0061007300740065007200。 这不是后端系统分配的 GUID,而是计算值

我已经浏览了 API 文档,但找不到任何查找此标识符的方法。

只是想知道我是否错过了什么或找错了地方? 有谁知道是否有地方可以找到这些信息?

这是一个用PowerShell编写的粗略函数,但它可以将分支名称转换为必要的十六进制代码。

Function get-AzDoBranchTokenFromName {  
    <#
    .SYNOPSIS
    Convert branch name to token
    .DESCRIPTION
    Azure DevOps Services security stores Access Control Lists and other items
    for Branches using a alphanumeric identifier derived from the text name of
    the branch.  This function will convert the name, like "master", into the 
    appropriate string, like 6d0061007300740065007200
    .PARAMETER branchName
    The human name of the git repository branch
    .EXAMPLE
    get-AzDoBranchTokenFromName -branchName "master"
    .NOTES
    The fun part is trying to go backwards (from hex to string).  Need to 
    work on that yet. 
    #>
    param(  
        # The sting you wish to Convert
        [Parameter(Mandatory=$true)]
        [string]
        $branchName   
    )
    # convert a string to an array of bytes    
    $bytes = [System.Text.Encoding]::Unicode.GetBytes($branchName)    
    # create a new variable twice as long as $bytes
    $Hex = [System.Text.StringBuilder]::new($Bytes.Length * 2)    
    # take each byte, format it as two hex characters and shove it into $Hex
    ForEach ($byte in $bytes) {      
        if ($byte -eq 47) {
            #Write-Output "YATZEE!!!!"
            $Hex.Append("/") | Out-Null
        }else{
        $Hex.AppendFormat("{0:x2}", $byte) | Out-Null    
        }
    }
    # convert $Hex back to a string    
    $Hex.ToString()
}

最新更新