Support stored Gitea credentials for releases
This commit is contained in:
@@ -27,7 +27,9 @@ foreach ($assetPath in $assetPaths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$token = $env:GITEA_TOKEN
|
$token = $env:GITEA_TOKEN
|
||||||
if (-not $token) {
|
$authorizationScheme = 'token'
|
||||||
|
$authorizationParameter = $token
|
||||||
|
if (-not $authorizationParameter) {
|
||||||
$credentialInput = "protocol=$($GiteaBaseUri.Scheme)`nhost=$($GiteaBaseUri.Host)`n`n"
|
$credentialInput = "protocol=$($GiteaBaseUri.Scheme)`nhost=$($GiteaBaseUri.Host)`n`n"
|
||||||
$credentialOutput = $credentialInput | & git credential fill
|
$credentialOutput = $credentialInput | & git credential fill
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
@@ -40,17 +42,25 @@ if (-not $token) {
|
|||||||
$credentialValues[$parts[0]] = $parts[1]
|
$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) {
|
if (-not $authorizationParameter) {
|
||||||
throw 'No Gitea token is available. Set GITEA_TOKEN for this process or sign in through Git Credential Manager.'
|
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
|
Add-Type -AssemblyName System.Net.Http
|
||||||
$handler = [Net.Http.HttpClientHandler]::new()
|
$handler = [Net.Http.HttpClientHandler]::new()
|
||||||
$client = [Net.Http.HttpClient]::new($handler)
|
$client = [Net.Http.HttpClient]::new($handler)
|
||||||
$client.BaseAddress = [uri]($GiteaBaseUri.AbsoluteUri.TrimEnd('/') + '/')
|
$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')
|
$client.DefaultRequestHeaders.UserAgent.ParseAdd('SGU-CredentialProvider-Release/1.0')
|
||||||
|
|
||||||
function Invoke-GiteaJson {
|
function Invoke-GiteaJson {
|
||||||
@@ -156,6 +166,8 @@ Las contraseñas se solicitan de forma interactiva y no se escriben en archivos
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
$token = $null
|
$token = $null
|
||||||
|
$authorizationParameter = $null
|
||||||
|
$credentialValues = $null
|
||||||
$client.Dispose()
|
$client.Dispose()
|
||||||
$handler.Dispose()
|
$handler.Dispose()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user