refactor: Use HTTP Basic Auth instead of tokens for package uploads
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions
- Replace token-based auth with HTTP Basic Auth (username/password) - Scripts now use FORGEJO_USER and FORGEJO_PASS environment variables - Same credentials used for git repository access - No special token creation needed - Simpler setup: set env vars and run upload script - Both Windows and macOS scripts updated
This commit is contained in:
parent
1b37335f8a
commit
e4a3a9a2cc
3 changed files with 80 additions and 177 deletions
|
|
@ -1,16 +1,17 @@
|
|||
# Upload Windows Build to Forgejo Packages
|
||||
# Usage: .\upload_to_packages.ps1 -Version 1.0.0
|
||||
# Set token via: $env:FORGEJO_TOKEN = "your_token"
|
||||
# Or store in Credential Manager: .\upload_to_packages.ps1 -SaveToken
|
||||
# Uses your Forgejo credentials (same as git)
|
||||
# Set via: $env:FORGEJO_USER = "username"; $env:FORGEJO_PASS = "password"
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$Version,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$ForgejoToken,
|
||||
[string]$ForgejoUser,
|
||||
|
||||
[switch]$SaveToken,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$ForgejoPW,
|
||||
|
||||
[string]$ForgejoUrl = "https://git.him-tools.de",
|
||||
[string]$Repo = "HIM-public/webdrop-bridge",
|
||||
|
|
@ -18,58 +19,24 @@ param(
|
|||
[string]$ChecksumPath = "build\dist\windows\WebDropBridge.exe.sha256"
|
||||
)
|
||||
|
||||
# Helper function to manage credentials
|
||||
function Get-ForgejoToken {
|
||||
param([switch]$Save, [string]$Token)
|
||||
|
||||
if ($Save -and $Token) {
|
||||
# Save to Credential Manager
|
||||
$cred = New-Object System.Management.Automation.PSCredential(
|
||||
"forgejo",
|
||||
(ConvertTo-SecureString $Token -AsPlainText -Force)
|
||||
)
|
||||
$cred | Export-Clixml -Path "$env:APPDATA\forgejo_token.xml" -Force
|
||||
Write-Host "✓ Token saved to Credential Manager" -ForegroundColor Green
|
||||
return $Token
|
||||
}
|
||||
|
||||
# Try to load from Credential Manager
|
||||
if (Test-Path "$env:APPDATA\forgejo_token.xml") {
|
||||
$cred = Import-Clixml -Path "$env:APPDATA\forgejo_token.xml"
|
||||
return $cred.GetNetworkCredential().Password
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
# Handle -SaveToken flag
|
||||
if ($SaveToken) {
|
||||
if (-not $ForgejoToken) {
|
||||
$ForgejoToken = Read-Host "Enter Forgejo token to save" -AsSecureString | %{[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($_))}
|
||||
}
|
||||
Get-ForgejoToken -Save -Token $ForgejoToken
|
||||
exit 0
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Get token from sources (in order of priority)
|
||||
if (-not $ForgejoToken) {
|
||||
# Try environment variable first
|
||||
$ForgejoToken = $env:FORGEJO_TOKEN
|
||||
# Get credentials from sources (in order of priority)
|
||||
if (-not $ForgejoUser) {
|
||||
$ForgejoUser = $env:FORGEJO_USER
|
||||
}
|
||||
|
||||
if (-not $ForgejoToken) {
|
||||
# Try Credential Manager
|
||||
$ForgejoToken = Get-ForgejoToken
|
||||
if (-not $ForgejoPW) {
|
||||
$ForgejoPW = $env:FORGEJO_PASS
|
||||
}
|
||||
|
||||
if (-not $ForgejoToken) {
|
||||
Write-Host "ERROR: No Forgejo token found!" -ForegroundColor Red
|
||||
Write-Host "Set token using one of these methods:" -ForegroundColor Yellow
|
||||
Write-Host " 1. Environment variable: `$env:FORGEJO_TOKEN = 'your_token'"
|
||||
Write-Host " 2. Credential Manager: .\upload_to_packages.ps1 -SaveToken"
|
||||
Write-Host " 3. Parameter: -ForgejoToken 'your_token'"
|
||||
if (-not $ForgejoUser -or -not $ForgejoPW) {
|
||||
Write-Host "ERROR: Forgejo credentials not found!" -ForegroundColor Red
|
||||
Write-Host "Set credentials using environment variables:" -ForegroundColor Yellow
|
||||
Write-Host " `$env:FORGEJO_USER = 'your_username'"
|
||||
Write-Host " `$env:FORGEJO_PASS = 'your_password'"
|
||||
Write-Host "" -ForegroundColor Yellow
|
||||
Write-Host "These should match your Forgejo login credentials."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
@ -100,12 +67,15 @@ $checksum = Get-Content $ChecksumPath -Raw
|
|||
Write-Host "File: WebDropBridge.exe ($([math]::Round($exeSize, 2)) MB)"
|
||||
Write-Host "Checksum: $($checksum.Substring(0, 16))..."
|
||||
|
||||
# Create basic auth header
|
||||
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${ForgejoUser}:${ForgejoPW}"))
|
||||
|
||||
# Upload executable
|
||||
Write-Host "`nUploading executable..." -ForegroundColor Yellow
|
||||
$exeUrl = "$ForgejoUrl/api/v1/repos/$Repo/packages/generic/webdrop-bridge/$Version/WebDropBridge.exe"
|
||||
|
||||
$headers = @{
|
||||
"Authorization" = "token $ForgejoToken"
|
||||
"Authorization" = "Basic $auth"
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue