Merge commit '1de09f98c766c981aa9f64c22a20edfa95e22ef3' into develop
This commit is contained in:
@@ -6,8 +6,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
#token per autenticazione
|
#access token per autenticazione
|
||||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$projectCount = 1
|
$projectCount = 1
|
||||||
@@ -6,8 +6,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
#token per autenticazione
|
#access token per autenticazione
|
||||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$projectCount = 1
|
$projectCount = 1
|
||||||
@@ -25,10 +27,10 @@ $mirrorErrorsCount = 0
|
|||||||
$mirrorSuccessCount = 0
|
$mirrorSuccessCount = 0
|
||||||
|
|
||||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||||
$logLevel = 0
|
$logLevel = 3
|
||||||
|
|
||||||
#output a terminale: 0=disattivo, 1=abilitato
|
#output a terminale: 0=disattivo, 1=abilitato
|
||||||
$terminalOutput = 0
|
$terminalOutput = 1
|
||||||
|
|
||||||
#cartella file di log
|
#cartella file di log
|
||||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||||
@@ -93,13 +95,13 @@ do
|
|||||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished"
|
#verifico se i mirroring trovati per il progetto corrente hanno status "finished"
|
||||||
if($item.update_status.Equals("finished"))
|
if($item.update_status.Equals("finished"))
|
||||||
{
|
{
|
||||||
WriteLogOutput 2 "Mirror: $($item.url) - Status: $($item.update_status)"
|
WriteLogOutput 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
||||||
$mirrorSuccessCount=$mirrorSuccessCount+1
|
$mirrorSuccessCount=$mirrorSuccessCount+1
|
||||||
}
|
}
|
||||||
#i mirroring che non hanno status "finished" vengono loggati con relativo errore
|
#i mirroring che non hanno status "finished" vengono loggati con relativo errore
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteLogOutput 1 "Mirror: $($item.url) - Status: $($item.update_status)"
|
WriteLogOutput 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
||||||
WriteLogOutput 1 "Error: $($item.last_error)"
|
WriteLogOutput 1 "Error: $($item.last_error)"
|
||||||
$mirrorErrorsCount=$mirrorErrorsCount+1
|
$mirrorErrorsCount=$mirrorErrorsCount+1
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,10 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
#token per autenticazione
|
#access token per autenticazione
|
||||||
$head = @{"PRIVATE-TOKEN"="glpat-dQsUhS-GxNomkh1GnjHZ"}
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$projectCount = 1
|
$projectCount = 1
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
################START SCRIPT################
|
||||||
|
|
||||||
|
#rilevo time per log inizio analisi
|
||||||
|
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
# avvio stopwatch
|
||||||
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo replica su gitea2.steamware.net
|
||||||
|
$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||||
|
|
||||||
|
#contatore ciclo do while
|
||||||
|
$projectCount = 1
|
||||||
|
|
||||||
|
#numero massimo di progetti da analizzare
|
||||||
|
$projectNumber = 200
|
||||||
|
|
||||||
|
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||||
|
$logLevel = 2
|
||||||
|
|
||||||
|
#output a terminale: 0=disattivo, 1=abilitato
|
||||||
|
$terminalOutput = 1
|
||||||
|
|
||||||
|
#cartella file di log
|
||||||
|
$GitLogFolder="C:\Steamware\Logs\Gitlab\"
|
||||||
|
|
||||||
|
#nome file di log
|
||||||
|
$logFile = Join-Path $GitLogFolder "GiteaReposCreation.log"
|
||||||
|
|
||||||
|
#dichiaro funzione per scrittura output
|
||||||
|
Function WriteLogOutput
|
||||||
|
{
|
||||||
|
Param ($logType, [string]$logString)
|
||||||
|
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||||
|
if($logType -le $logLevel)
|
||||||
|
{
|
||||||
|
Add-content $logFile -value "$logString"
|
||||||
|
#scrivo su terminale la stringa se $terminalOutput=1
|
||||||
|
if($terminalOutput -eq 1)
|
||||||
|
{
|
||||||
|
Write-Output($logString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#creazione folder di Log se non già esistente
|
||||||
|
if (Test-Path $GitLogFolder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
New-Item $GitLogFolder -ItemType Directory
|
||||||
|
}
|
||||||
|
|
||||||
|
#scrivo intestazione e inizio analisi
|
||||||
|
WriteLogOutput 0 "--------------------"
|
||||||
|
Switch ($logLevel)
|
||||||
|
{
|
||||||
|
0 {WriteLogOutput 0 "LOG SINTETICO GITEA"}
|
||||||
|
1 {WriteLogOutput 0 "LOG ERRORI GITEA"}
|
||||||
|
2 {WriteLogOutput 0 "LOG FULL GITEA"}
|
||||||
|
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITEA"}
|
||||||
|
}
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||||
|
|
||||||
|
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||||
|
do
|
||||||
|
{
|
||||||
|
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
|
$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
||||||
|
#scrivo il numero del progetto nel terminale e su file
|
||||||
|
WriteLogOutput 1 ""
|
||||||
|
WriteLogOutput 1 "--------------------"
|
||||||
|
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||||
|
foreach($gitlabItem in $parsedGitlabResponse)
|
||||||
|
{
|
||||||
|
WriteLogOutput 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||||
|
$callGiteaUrl = "https://gitea2.steamware.net/api/v1/orgs/Egalware/repos"
|
||||||
|
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
||||||
|
$giteaBody =
|
||||||
|
@{
|
||||||
|
name = $($gitlabItem.name);
|
||||||
|
}
|
||||||
|
# Converting my hash to json format
|
||||||
|
$GiteaJSON = $giteaBody | ConvertTo-Json
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$giteaResponse = Invoke-WebRequest -URI $callGiteaUrl -Method POST -Headers $giteaHead -ContentType "application/json" -Body $GiteaJSON
|
||||||
|
$parsedGiteaResponse = $giteaResponse.Content | ConvertFrom-Json
|
||||||
|
foreach($giteaItem in $parsedGiteaResponse)
|
||||||
|
{
|
||||||
|
WriteLogOutput 1 "Gitea New Project Name: $($giteaItem.name)"
|
||||||
|
WriteLogOutput 1 "Status: $($giteaResponse.StatusDescription)"
|
||||||
|
WriteLogOutput 1 "When: $($giteaItem.created_at)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
WriteLogOutput 3 ""
|
||||||
|
WriteLogOutput 3 "--------------------"
|
||||||
|
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||||
|
}
|
||||||
|
$projectCount=$projectCount+1
|
||||||
|
}
|
||||||
|
#fine ciclo principale
|
||||||
|
while($projectCount -le $projectNumber)
|
||||||
|
|
||||||
|
# fermo stopwatch e calcolo durata script
|
||||||
|
$mainStopWatch.Stop()
|
||||||
|
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||||
|
|
||||||
|
#rilevo time per log fine analisi
|
||||||
|
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
#scrivo a video le statistiche
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
################START SCRIPT################
|
||||||
|
|
||||||
|
#rilevo time per log inizio analisi
|
||||||
|
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
# avvio stopwatch
|
||||||
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo replica su gitea2.steamware.net
|
||||||
|
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||||
|
$giteaPass = "ajejebrazorf92!"
|
||||||
|
|
||||||
|
#nome utente che effettua i mirror push
|
||||||
|
$userName = "replica"
|
||||||
|
|
||||||
|
#contatore ciclo do while
|
||||||
|
$projectCount = 1
|
||||||
|
|
||||||
|
#numero massimo di progetti
|
||||||
|
$projectNumber = 200
|
||||||
|
|
||||||
|
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||||
|
$logLevel = 3
|
||||||
|
|
||||||
|
#output a terminale: 0=disattivo, 1=abilitato
|
||||||
|
$terminalOutput = 1
|
||||||
|
|
||||||
|
#inizializzo variabili vuote
|
||||||
|
$mirrorId = ""
|
||||||
|
$mirrorUrl = ""
|
||||||
|
$body = ""
|
||||||
|
$jsonBody = ""
|
||||||
|
|
||||||
|
#cartella file di log
|
||||||
|
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||||
|
|
||||||
|
#nome file di log
|
||||||
|
$logFile = Join-Path $GitLogFolder "GitlabMirroringGitea.log"
|
||||||
|
|
||||||
|
#dichiaro funzione per scrittura output
|
||||||
|
Function WriteLogOutput
|
||||||
|
{
|
||||||
|
Param ($logType, [string]$logString)
|
||||||
|
if($logType -le $logLevel)
|
||||||
|
{
|
||||||
|
#scrivo su file la stringa
|
||||||
|
Add-content $logFile -value "$logString"
|
||||||
|
#scrivo su terminale la stringa se $terminalOutput=1
|
||||||
|
if($terminalOutput -eq 1){
|
||||||
|
Write-Output($logString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#creazione folder di Log se non già esistente
|
||||||
|
if (Test-Path $GitLogFolder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
New-Item $GitLogFolder -ItemType Directory
|
||||||
|
}
|
||||||
|
|
||||||
|
#scrivo intestazione e inizio analisi
|
||||||
|
WriteLogOutput 0 "--------------------"
|
||||||
|
Switch ($logLevel)
|
||||||
|
{
|
||||||
|
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB MIRRORING"}
|
||||||
|
1 {WriteLogOutput 0 "LOG ERRORI GITLAB MIRRORING"}
|
||||||
|
2 {WriteLogOutput 0 "LOG FULL GITLAB MIRRORING"}
|
||||||
|
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB MIRRORING"}
|
||||||
|
}
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||||
|
|
||||||
|
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||||
|
do
|
||||||
|
{
|
||||||
|
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||||
|
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||||
|
try
|
||||||
|
{
|
||||||
|
#parsing della risposta api convertita da json
|
||||||
|
$Response = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
|
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||||
|
#scrivo il numero del progetto
|
||||||
|
WriteLogOutput 1 ""
|
||||||
|
WriteLogOutput 1 "--------------------"
|
||||||
|
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||||
|
foreach($item in $parsedResponse)
|
||||||
|
{
|
||||||
|
$doExecute = "false"
|
||||||
|
$token = ""
|
||||||
|
$mirrorUrl = ""
|
||||||
|
$trunkedPath = ""
|
||||||
|
#controllo se l'url del mirror contiene gitea
|
||||||
|
if($item.url.Contains("gitea"))
|
||||||
|
{
|
||||||
|
$doExecute = "true"
|
||||||
|
$token = $giteaPass
|
||||||
|
$mirrorDestination = "@gitea2.steamware.net"
|
||||||
|
}
|
||||||
|
#verifico se devo effettuare cancellazione e creazione nuovo mirror
|
||||||
|
if($doExecute -eq "true")
|
||||||
|
{
|
||||||
|
#salvo id mirror e url mirror
|
||||||
|
$mirrorId = $($item.id)
|
||||||
|
$mirrorUrl = $($item.url)
|
||||||
|
WriteLogOutput 1 "ID: $mirrorId - URL: $mirrorUrl"
|
||||||
|
#tronco url fino a ".net"
|
||||||
|
$splitUrl = $mirrorUrl -split '.steamware.net/'
|
||||||
|
$trunkedPath = $splitUrl[1]
|
||||||
|
#compongo URL per cancellare mirror con ID trovato
|
||||||
|
$callUrlDeleteMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $mirrorId
|
||||||
|
#chiamata api con method delete che cancella mirror con id specificato
|
||||||
|
Invoke-WebRequest -Method Delete -URI $callUrlDeleteMirror -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
|
#compongo url da chiamare per creazione nuovo mirror
|
||||||
|
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||||
|
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||||
|
$newMirror = "https://" + $userName + ":" + $token + $mirrorDestination + "/" + $trunkedPath
|
||||||
|
#creo body da convertire in json
|
||||||
|
$body =
|
||||||
|
@{
|
||||||
|
url = $newMirror
|
||||||
|
enabled = 1
|
||||||
|
}
|
||||||
|
#converto body in json prima di passarlo alla chiamata POST
|
||||||
|
$jsonBody = ConvertTo-Json -InputObject $body
|
||||||
|
#chiamata api POST che crea mirror con url e body specificati
|
||||||
|
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $gitlabHead -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||||
|
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||||
|
foreach($item in $parsedRebuild){
|
||||||
|
$mirrorId = $($item.id)
|
||||||
|
$mirrorUrl = $($item.url)
|
||||||
|
}
|
||||||
|
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror ricostruito con successo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#scrivo se trovo un errore (in particolare progetto ID non trovato) durante il try/catch
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
WriteLogOutput 3 ""
|
||||||
|
WriteLogOutput 3 "--------------------"
|
||||||
|
WriteLogOutput 3 "**ERRORE: PROGETTO $projectCount NON ESISTENTE**"
|
||||||
|
}
|
||||||
|
$projectCount=$projectCount+1
|
||||||
|
}
|
||||||
|
#fine ciclo principale
|
||||||
|
while($projectCount -le $projectNumber)
|
||||||
|
|
||||||
|
# fermo stopwatch e calcolo durata script
|
||||||
|
$mainStopWatch.Stop()
|
||||||
|
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||||
|
|
||||||
|
#rilevo time per log fine analisi
|
||||||
|
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
#scrivo a video le statistiche
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
################START SCRIPT################
|
||||||
|
|
||||||
|
#rilevo time per log inizio analisi
|
||||||
|
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
# avvio stopwatch
|
||||||
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
|
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
|
#access token per autenticazione
|
||||||
|
#creato da profilo replica su gitea2.steamware.net
|
||||||
|
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||||
|
$giteaPass = "ajejebrazorf92!"
|
||||||
|
|
||||||
|
#nome utente gitea che effettua i mirror push
|
||||||
|
$giteaUser = "replica"
|
||||||
|
|
||||||
|
#password replcia gogs
|
||||||
|
$gogsPass = "viaDante16!"
|
||||||
|
|
||||||
|
#nome utente gogs che effettua i mirror push
|
||||||
|
$gogsUser = "replica"
|
||||||
|
|
||||||
|
#contatore ciclo do while
|
||||||
|
$projectCount = 140
|
||||||
|
|
||||||
|
#numero massimo di progetti da analizzare
|
||||||
|
$projectNumber = 1
|
||||||
|
|
||||||
|
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||||
|
$logLevel = 2
|
||||||
|
|
||||||
|
#output a terminale: 0=disattivo, 1=abilitato
|
||||||
|
$terminalOutput = 1
|
||||||
|
|
||||||
|
#cartella file di log
|
||||||
|
$GitLogFolder="C:\Steamware\Logs\Gitlab\"
|
||||||
|
|
||||||
|
#nome file di log
|
||||||
|
$logFile = Join-Path $GitLogFolder "GiteaNewMirrors.log"
|
||||||
|
|
||||||
|
#dichiaro funzione per scrittura output
|
||||||
|
Function WriteLogOutput
|
||||||
|
{
|
||||||
|
Param ($logType, [string]$logString)
|
||||||
|
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||||
|
if($logType -le $logLevel)
|
||||||
|
{
|
||||||
|
Add-content $logFile -value "$logString"
|
||||||
|
#scrivo su terminale la stringa se $terminalOutput=1
|
||||||
|
if($terminalOutput -eq 1)
|
||||||
|
{
|
||||||
|
Write-Output($logString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#funzione che crea mirror con chiamata API
|
||||||
|
Function FreshMirrorCreation
|
||||||
|
{
|
||||||
|
Param ($projectNumber, $user, $auth, $destination, $path)
|
||||||
|
#compongo url da chiamare per creazione nuovo mirror
|
||||||
|
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectNumber + "/remote_mirrors"
|
||||||
|
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||||
|
$newMirror = "https://" + $user + ":" + $auth + $destination + "/" + $path
|
||||||
|
#creo body da convertire in json
|
||||||
|
$body =
|
||||||
|
@{
|
||||||
|
url = $newMirror
|
||||||
|
enabled = 1
|
||||||
|
}
|
||||||
|
#converto body in json prima di passarlo alla chiamata POST
|
||||||
|
$jsonBody = ConvertTo-Json -InputObject $body
|
||||||
|
#chiamata api POST che crea mirror con url e body specificati
|
||||||
|
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $gitlabHead -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||||
|
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||||
|
foreach($item in $parsedRebuild){
|
||||||
|
$mirrorId = $($item.id)
|
||||||
|
$mirrorUrl = $($item.url)
|
||||||
|
}
|
||||||
|
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
||||||
|
}
|
||||||
|
|
||||||
|
#creazione folder di Log se non già esistente
|
||||||
|
if (Test-Path $GitLogFolder)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
New-Item $GitLogFolder -ItemType Directory
|
||||||
|
}
|
||||||
|
|
||||||
|
#scrivo intestazione e inizio analisi
|
||||||
|
WriteLogOutput 0 "--------------------"
|
||||||
|
Switch ($logLevel)
|
||||||
|
{
|
||||||
|
0 {WriteLogOutput 0 "LOG SINTETICO NUOVI MIRROR"}
|
||||||
|
1 {WriteLogOutput 0 "LOG ERRORI NUOVI MIRROR"}
|
||||||
|
2 {WriteLogOutput 0 "LOG FULL NUOVI MIRROR"}
|
||||||
|
3 {WriteLogOutput 0 "LOG AMPOLLOSO NUOVI MIRROR"}
|
||||||
|
}
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||||
|
|
||||||
|
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||||
|
do
|
||||||
|
{
|
||||||
|
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$gitlabResponse = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
|
#$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
||||||
|
#scrivo il numero del progetto nel terminale e su file
|
||||||
|
WriteLogOutput 1 ""
|
||||||
|
WriteLogOutput 1 "--------------------"
|
||||||
|
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||||
|
if($gitlabResponse.Content -eq "[]")
|
||||||
|
{
|
||||||
|
$callUrl2 = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||||
|
$gitlabResponse2 = Invoke-WebRequest -URI $callUrl2 -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
|
$parsedResponse2 = $gitlabResponse2.Content | ConvertFrom-Json
|
||||||
|
$repoPath = $($parsedResponse2.path)
|
||||||
|
$path = "Egalware/" + $repoPath + ".git"
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FreshMirrorCreation $projectCount $giteaUser $giteaPass "@gitea2.steamware.net" $path
|
||||||
|
FreshMirrorCreation $projectCount $gogsUser $gogsPass "@gogs.steamware.net" $path
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
WriteLogOutput 3 ""
|
||||||
|
WriteLogOutput 3 "--------------------"
|
||||||
|
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||||
|
}
|
||||||
|
$projectCount=$projectCount+1
|
||||||
|
}
|
||||||
|
#fine ciclo principale
|
||||||
|
while($projectCount -le $projectNumber)
|
||||||
|
|
||||||
|
# fermo stopwatch e calcolo durata script
|
||||||
|
$mainStopWatch.Stop()
|
||||||
|
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||||
|
|
||||||
|
#rilevo time per log fine analisi
|
||||||
|
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||||
|
|
||||||
|
#scrivo a video le statistiche
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
|
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||||
|
WriteLogOutput 0 ""
|
||||||
@@ -6,17 +6,20 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
|
|
||||||
#token per autenticazione gitlab.steamware.net
|
#access token per autenticazione creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||||
$head = @{"PRIVATE-TOKEN"="glpat-pmkiVSJMhNyAySEKp2nA"}
|
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||||
|
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||||
|
|
||||||
#nome utente che effettua i mirror push
|
#nome utente che effettua i mirror push
|
||||||
$userName = "replica"
|
$userName = "replica"
|
||||||
|
|
||||||
#token autenticazione utente replica azzano
|
#token autenticazione utente replica azzano creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||||
$tokenAzzano = "glpat-gADkrEhkEsvQxGxKez4y"
|
#$tokenAzzano = "glpat-gADkrEhkEsvQxGxKez4y" <<< TOKEN 2023 (IN DISUSO)
|
||||||
|
$tokenAzzano = "glpat-UHLqByZZr8tns6jwc4_-"
|
||||||
|
|
||||||
#token autenticazione utente replica nembro
|
#token autenticazione utente replica nembro creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||||
$tokenNembro = "glpat-TzZkRUoYAdKikgwFXW_E"
|
#$tokenNembro = "glpat-TzZkRUoYAdKikgwFXW_E" <<< TOKEN 2023 (IN DISUSO)
|
||||||
|
$tokenNembro = "glpat-puycZnyztFioe5tmkaso"
|
||||||
|
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$projectCount = 1
|
$projectCount = 1
|
||||||
@@ -99,6 +102,7 @@ do
|
|||||||
$doExecute = "false"
|
$doExecute = "false"
|
||||||
$token = ""
|
$token = ""
|
||||||
$mirrorUrl = ""
|
$mirrorUrl = ""
|
||||||
|
$mirrorId = ""
|
||||||
$trunkedPath = ""
|
$trunkedPath = ""
|
||||||
#controllo se l'url del mirror contiene azzano
|
#controllo se l'url del mirror contiene azzano
|
||||||
if($item.url.Contains("azzano"))
|
if($item.url.Contains("azzano"))
|
||||||
@@ -140,8 +144,13 @@ do
|
|||||||
#converto body in json prima di passarlo alla chiamata POST
|
#converto body in json prima di passarlo alla chiamata POST
|
||||||
$jsonBody = ConvertTo-Json -InputObject $body
|
$jsonBody = ConvertTo-Json -InputObject $body
|
||||||
#chiamata api POST che crea mirror con url e body specificati
|
#chiamata api POST che crea mirror con url e body specificati
|
||||||
Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $head -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $head -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||||
WriteLogOutput 1 "ID: $mirrorId - URL: $mirrorUrl - Mirror ricostruito con successo"
|
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||||
|
foreach($item in $parsedRebuild){
|
||||||
|
$mirrorId = $($item.id)
|
||||||
|
$mirrorUrl = $($item.url)
|
||||||
|
}
|
||||||
|
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror ricostruito con successo"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user