$p = '19mNqNXIoZ4c3EriFNfzfkgpGNOvLjpOqqZnTFXKnzjxWJ5zURjgJQQJ99CBACAAAAAamI5kAAASAZDOAMPp'
$t = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(':' + $p))
$h = @{ Authorization = 'Basic ' + $t; 'Content-Type' = 'application/json' }
$base = 'https://dev.azure.com/CN-Squad/Invista%20FIDC%20-%20Nexus/_apis'
$repoId = 'ae7542f8-d76e-4a45-b8b2-745e18cd2f26'

# Ler o script oci_kubeconfig.sh
Write-Host "=== cd/scripts/oci_kubeconfig.sh ===" -ForegroundColor Cyan
try {
  $content = Invoke-RestMethod -Uri "$base/git/repositories/$repoId/items?path=/cd/scripts/oci_kubeconfig.sh`&versionDescriptor.version=main`&api-version=7.0" -Headers $h
  Write-Host $content
} catch {
  # tentar na raiz
  $tree = Invoke-RestMethod -Uri "$base/git/repositories/$repoId/items?scopePath=/cd/scripts`&recursionLevel=OneLevel`&api-version=7.0" -Headers $h -ErrorAction SilentlyContinue
  if ($tree) {
    $tree.value | Select-Object path | Format-Table
  } else {
    Write-Host "  pasta /cd/scripts nao encontrada"
    # listar raiz
    $root = Invoke-RestMethod -Uri "$base/git/repositories/$repoId/items?scopePath=/`&recursionLevel=OneLevel`&api-version=7.0" -Headers $h
    $root.value | Select-Object path | Format-Table
  }
}
