Support stored Gitea credentials for releases

This commit is contained in:
2026-09-08 12:16:33 -06:00
parent 93871b62b0
commit 991fc70600
+17 -5
View File
@@ -27,7 +27,9 @@ foreach ($assetPath in $assetPaths) {
}
$token = $env:GITEA_TOKEN
if (-not $token) {
$authorizationScheme = 'token'
$authorizationParameter = $token
if (-not $authorizationParameter) {
$credentialInput = "protocol=$($GiteaBaseUri.Scheme)`nhost=$($GiteaBaseUri.Host)`n`n"
$credentialOutput = $credentialInput | & git credential fill
if ($LASTEXITCODE -ne 0) {
@@ -40,17 +42,25 @@ if (-not $token) {
$credentialValues[$parts[0]] = $parts[1]
}
}
$token = $credentialValues.password
if ($credentialValues.username -and $credentialValues.password) {
$authorizationScheme = 'Basic'
$basicCredential = '{0}:{1}' -f $credentialValues.username,$credentialValues.password
$authorizationParameter = [Convert]::ToBase64String(
[Text.Encoding]::UTF8.GetBytes($basicCredential))
$basicCredential = $null
}
if (-not $token) {
throw 'No Gitea token is available. Set GITEA_TOKEN for this process or sign in through Git Credential Manager.'
}
if (-not $authorizationParameter) {
throw 'No Gitea credential is available. Set GITEA_TOKEN for this process or sign in through Git Credential Manager.'
}
Add-Type -AssemblyName System.Net.Http
$handler = [Net.Http.HttpClientHandler]::new()
$client = [Net.Http.HttpClient]::new($handler)
$client.BaseAddress = [uri]($GiteaBaseUri.AbsoluteUri.TrimEnd('/') + '/')
$client.DefaultRequestHeaders.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new('token', $token)
$client.DefaultRequestHeaders.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new(
$authorizationScheme,
$authorizationParameter)
$client.DefaultRequestHeaders.UserAgent.ParseAdd('SGU-CredentialProvider-Release/1.0')
function Invoke-GiteaJson {
@@ -156,6 +166,8 @@ Las contraseñas se solicitan de forma interactiva y no se escriben en archivos
}
finally {
$token = $null
$authorizationParameter = $null
$credentialValues = $null
$client.Dispose()
$handler.Dispose()
}