Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 674ce894b5 | |||
| 23137a0fed | |||
| dfe2f63787 | |||
| bc9d2048a9 | |||
| 8bcbb1fd04 | |||
| f11d2ac73a | |||
| 1e9b24a3df |
@@ -1,5 +1,13 @@
|
|||||||
######### FILE DI CONFIGURAZIONE PER SCRIPT API GIT #########
|
######### FILE DI CONFIGURAZIONE PER SCRIPT API GIT #########
|
||||||
|
|
||||||
|
#### CONF LOG ####
|
||||||
|
#cartella file di log
|
||||||
|
$logFolder = "c:\Steamware\Logs\Gitlab\"
|
||||||
|
#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
|
||||||
|
|
||||||
#### CONF GITLAB ####
|
#### CONF GITLAB ####
|
||||||
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2024
|
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2024
|
||||||
#$gitlabHead2024 = @{"PRIVATE-TOKEN" = "glpat-VjT_SAsBk3s-yWE1LDUF" }
|
#$gitlabHead2024 = @{"PRIVATE-TOKEN" = "glpat-VjT_SAsBk3s-yWE1LDUF" }
|
||||||
@@ -11,37 +19,6 @@ $gitlabHead = @{"PRIVATE-TOKEN" = "$($tokenGitlab)" }
|
|||||||
#nome utente che effettua i mirror push
|
#nome utente che effettua i mirror push
|
||||||
$userName = "replica"
|
$userName = "replica"
|
||||||
|
|
||||||
#### CONF GITLAB AZZANO ####
|
|
||||||
#destinazione mirror per azzano
|
|
||||||
$destinationAzzano = "gitlab-azzano.steamware.net"
|
|
||||||
#token autenticazione utente replica azzano
|
|
||||||
#token 2025:$tokenAzzano = "glpat-tCyVnkDQb3uB_yFywQtK"
|
|
||||||
|
|
||||||
#token autenticazione utente replica azzano Gennaio 2026:
|
|
||||||
$tokenAzzano = "glpat-xbCbgalMbPwJ9MDvZTU3rW86MQp1OnAH.01.0w17pjo4t"
|
|
||||||
#access token per autenticazione gitlab-azzano
|
|
||||||
$azzanoHead = @{"PRIVATE-TOKEN" = "$($tokenAzzano)" }
|
|
||||||
|
|
||||||
#### CONF GITLAB NEMBRO ####
|
|
||||||
#destinazione mirror per nembro
|
|
||||||
$destinationNembro = "gitlab-nembro.steamware.net"
|
|
||||||
#token autenticazione utente replica nembro
|
|
||||||
$tokenNembro = "glpat--9NqsusKLmHdF8z1kU9t"
|
|
||||||
#access token per autenticazione gitlab-nembro
|
|
||||||
$nembroHead = @{"PRIVATE-TOKEN" = "$($tokenNembro)" }
|
|
||||||
|
|
||||||
#### CONF gitea-nembro.steamware.net ####
|
|
||||||
#destinazione mirror per gitea
|
|
||||||
$giteaNembro = "gitea-nembro.steamware.net"
|
|
||||||
#nome utente gitea che effettua i mirror push
|
|
||||||
$giteaNembroUser = "replica"
|
|
||||||
#autenticazione replica gitea
|
|
||||||
$giteaNembroPass = "IXQkDchDwMah8E"
|
|
||||||
#token autenticazione utente replica gitea
|
|
||||||
$tokenGiteaNembro = "c58a2fdf6493bb690e8c39b393e06a121f8a6761"
|
|
||||||
#access token per autenticazione gitea da profilo replica
|
|
||||||
$giteaNembroHead = @{"Authorization" = "token $($tokenGiteaNembro)" }
|
|
||||||
|
|
||||||
#### CONF gitea.steamware.net ####
|
#### CONF gitea.steamware.net ####
|
||||||
#destinazione mirror per gitea
|
#destinazione mirror per gitea
|
||||||
$giteaSteamw = "gitea.steamware.net"
|
$giteaSteamw = "gitea.steamware.net"
|
||||||
@@ -66,10 +43,26 @@ $tokenGogs = "bb6d8e9a4d76445e33b12e1664140043fdaa8d87"
|
|||||||
#access token per autenticazione gogs da profilo replica
|
#access token per autenticazione gogs da profilo replica
|
||||||
$gogsHead = @{"Authorization" = "token $($tokenGogs)" }
|
$gogsHead = @{"Authorization" = "token $($tokenGogs)" }
|
||||||
|
|
||||||
#### CONF LOG ####
|
#### CONF gitea-azzano.steamware.net ####
|
||||||
#cartella file di log
|
#destinazione mirror per gitea
|
||||||
$logFolder = "c:\Steamware\Logs\Gitlab\"
|
$giteaAzzano = "gitea-azzano.steamware.net"
|
||||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
#nome utente gitea che effettua i mirror push
|
||||||
$logLevel = 3
|
$giteaAzzanoUser = "replica"
|
||||||
#output a terminale: 0=disattivo, 1=abilitato
|
#autenticazione replica gitea
|
||||||
$terminalOutput = 1
|
$giteaAzzanoPass = "kj5uQz9QpVdrwXj"
|
||||||
|
#token autenticazione utente replica gitea
|
||||||
|
$tokenGiteaAzzano = "9e9958e9d46d78cc098b3ba7341e750f2d2fd8a3"
|
||||||
|
#access token per autenticazione gitea da profilo replica
|
||||||
|
$giteaAzzanoHead = @{"Authorization" = "token $($tokenGiteaAzzano)" }
|
||||||
|
|
||||||
|
#### CONF gitea-nembro.steamware.net ####
|
||||||
|
#destinazione mirror per gitea
|
||||||
|
$giteaNembro = "gitea-nembro.steamware.net"
|
||||||
|
#nome utente gitea che effettua i mirror push
|
||||||
|
$giteaNembroUser = "replica"
|
||||||
|
#autenticazione replica gitea
|
||||||
|
$giteaNembroPass = "IXQkDchDwMah8E"
|
||||||
|
#token autenticazione utente replica gitea
|
||||||
|
$tokenGiteaNembro = "c58a2fdf6493bb690e8c39b393e06a121f8a6761"
|
||||||
|
#access token per autenticazione gitea da profilo replica
|
||||||
|
$giteaNembroHead = @{"Authorization" = "token $($tokenGiteaNembro)" }
|
||||||
@@ -48,7 +48,7 @@ Function FreshMirrorCreation {
|
|||||||
#compongo url da chiamare per creazione nuovo mirror
|
#compongo url da chiamare per creazione nuovo mirror
|
||||||
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectNumber + "/remote_mirrors"
|
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectNumber + "/remote_mirrors"
|
||||||
#creo url del nuovo mirror con username e token relativi a gitlab
|
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||||
$newMirror = "https://" + $user + ":" + $auth + "@" + $destination + "/" + $path
|
$newMirror = "http://" + $user + ":" + $auth + "@" + $destination + "/" + $path
|
||||||
#creo body da convertire in json
|
#creo body da convertire in json
|
||||||
$body =
|
$body =
|
||||||
@{
|
@{
|
||||||
@@ -68,4 +68,15 @@ Function FreshMirrorCreation {
|
|||||||
}
|
}
|
||||||
#scrivo ID e URL nuovo mirror
|
#scrivo ID e URL nuovo mirror
|
||||||
WriteLogOutput $logFile 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
WriteLogOutput $logFile 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
||||||
|
}
|
||||||
|
|
||||||
|
Function TryParse-Json {
|
||||||
|
param([string]$InputString)
|
||||||
|
|
||||||
|
try {
|
||||||
|
return $InputString | ConvertFrom-Json -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +62,8 @@ do {
|
|||||||
|
|
||||||
#foreach ($item in $parsedResponse) {
|
#foreach ($item in $parsedResponse) {
|
||||||
# WriteLogOutput $logFile 1 "ID: $($item.id) | Creato il: $($item.created_at) | URL: $($item.web_url)"
|
# WriteLogOutput $logFile 1 "ID: $($item.id) | Creato il: $($item.created_at) | URL: $($item.web_url)"
|
||||||
# $projectJobFound = $projectJobFound + 1
|
# $projectJobFound++
|
||||||
# $jobFound = $jobFound + 1
|
# $jobFound++
|
||||||
#compongo chiamata api per erase job
|
#compongo chiamata api per erase job
|
||||||
#$eraseUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/jobs/" + $item.id + "/erase"
|
#$eraseUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/jobs/" + $item.id + "/erase"
|
||||||
#$EraseResponse = Invoke-WebRequest -URI $eraseUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
#$EraseResponse = Invoke-WebRequest -URI $eraseUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
@@ -75,14 +75,14 @@ do {
|
|||||||
#}
|
#}
|
||||||
#WriteLogOutput $logFile 1 "Job trovati per il progetto $($projectCount): $($projectJobFound)"
|
#WriteLogOutput $logFile 1 "Job trovati per il progetto $($projectCount): $($projectJobFound)"
|
||||||
#$projectJobFound = 0
|
#$projectJobFound = 0
|
||||||
$existingProjects = $existingProjects + 1
|
$existingProjects++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
$parsedError = $_ | ConvertFrom-Json
|
$parsedError = $_ | ConvertFrom-Json
|
||||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||||
}
|
}
|
||||||
$projectCount = $projectCount + 1
|
$projectCount++
|
||||||
}
|
}
|
||||||
#fine ciclo principale
|
#fine ciclo principale
|
||||||
while ($projectCount -le $projectNumber)
|
while ($projectCount -le $projectNumber)
|
||||||
|
|||||||
@@ -65,18 +65,18 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
|||||||
WriteLogOutput $logFile 1 "--------------------"
|
WriteLogOutput $logFile 1 "--------------------"
|
||||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||||
if ($parsedResponse.Count -eq 0 ) {
|
if ($parsedResponse.Count -eq 0 ) {
|
||||||
$projectWithNoCommits = $projectWithNoCommits + 1
|
$projectWithNoCommits++
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$projectWithCommits = $projectWithCommits + 1
|
$projectWithCommits++
|
||||||
foreach ($item in $parsedResponse) {
|
foreach ($item in $parsedResponse) {
|
||||||
if ($item.web_url) {
|
if ($item.web_url) {
|
||||||
WriteLogOutput $logFile 1 "Date: $($item.committed_date) - Web Url: $($item.web_url)"
|
WriteLogOutput $logFile 1 "Date: $($item.committed_date) - Web Url: $($item.web_url)"
|
||||||
$recentCommits = $recentCommits + 1
|
$recentCommits++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$projectsFound = $projectsFound + 1
|
$projectsFound++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ $mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 1
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 300
|
$endProj = 300
|
||||||
#conteggio progetti trovati
|
#conteggio progetti trovati
|
||||||
$existingProjects = 0
|
$existingProjects = 0
|
||||||
#conteggio mirroring in errore
|
#conteggio mirroring in errore
|
||||||
@@ -62,16 +62,16 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished" e scrivo log
|
#verifico se i mirroring trovati per il progetto corrente hanno status "finished" e scrivo log
|
||||||
if ($item.update_status.Equals("finished")) {
|
if ($item.update_status.Equals("finished")) {
|
||||||
WriteLogOutput $logFile 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
WriteLogOutput $logFile 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
||||||
$mirrorSuccessCount = $mirrorSuccessCount + 1
|
$mirrorSuccessCount++
|
||||||
}
|
}
|
||||||
#per i mirroring che non hanno status "finished" scrivo log con relativo errore
|
#per i mirroring che non hanno status "finished" scrivo log con relativo errore
|
||||||
else {
|
else {
|
||||||
WriteLogOutput $logFile 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
WriteLogOutput $logFile 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
||||||
WriteLogOutput $logFile 1 "Error: $($item.last_error)"
|
WriteLogOutput $logFile 1 "Error: $($item.last_error)"
|
||||||
$mirrorErrorsCount = $mirrorErrorsCount + 1
|
$mirrorErrorsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$existingProjects = $existingProjects + 1
|
$existingProjects++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 200
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 300
|
$endProj = 300
|
||||||
|
#contatore mirror creati
|
||||||
|
$createdMirrors = 0
|
||||||
#nome file di log
|
#nome file di log
|
||||||
$logFile = "NewMirrorsCreation.log"
|
$logFile = "NewMirrorsCreation.log"
|
||||||
#nome file di log old
|
#nome file di log old
|
||||||
@@ -61,27 +63,26 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
|||||||
if ($gitlabResponse.Content -inotmatch "gitea.steamware.net") {
|
if ($gitlabResponse.Content -inotmatch "gitea.steamware.net") {
|
||||||
#chiamo funzione per creare mirror verso gitea-steamware
|
#chiamo funzione per creare mirror verso gitea-steamware
|
||||||
FreshMirrorCreation $projectCount $giteaSteamwUser $giteaSteamwPass $giteaSteamw $simplePath
|
FreshMirrorCreation $projectCount $giteaSteamwUser $giteaSteamwPass $giteaSteamw $simplePath
|
||||||
}
|
$createdMirrors++
|
||||||
#se la risposta non contiene "gitea-nembro" procedo a creare mirror relativo
|
|
||||||
if ($gitlabResponse.Content -inotmatch "gitea-nembro.steamware.net") {
|
|
||||||
#chiamo funzione per creare mirror verso gitea-nembro
|
|
||||||
FreshMirrorCreation $projectCount $giteaNembroUser $giteaNembroPass $giteaNembro $simplePath
|
|
||||||
}
|
}
|
||||||
#se la risposta non contiene "gogs" procedo a creare mirror relativo
|
#se la risposta non contiene "gogs" procedo a creare mirror relativo
|
||||||
if ($gitlabResponse.Content -inotmatch "gogs") {
|
if ($gitlabResponse.Content -inotmatch "gogs.steamware.net") {
|
||||||
#chiamo funzione per creare mirror verso gogs
|
#chiamo funzione per creare mirror verso gogs
|
||||||
FreshMirrorCreation $projectCount $gogsUser $gogsPass $gogsDestination $simplePath
|
FreshMirrorCreation $projectCount $gogsUser $gogsPass $gogsDestination $simplePath
|
||||||
|
$createdMirrors++
|
||||||
}
|
}
|
||||||
#se la risposta non contiene "gitlab-azzano" procedo a creare mirror relativo
|
#se la risposta non contiene "gitea-nembro" procedo a creare mirror relativo
|
||||||
if ($gitlabResponse.Content -inotmatch "gitlab-azzano") {
|
if ($gitlabResponse.Content -inotmatch "gitea-nembro") {
|
||||||
#chiamo funzione per creare mirror verso gitlab-azzano
|
#chiamo funzione per creare mirror verso gitea-nembro
|
||||||
FreshMirrorCreation $projectCount $userName $tokenAzzano $destinationAzzano $simplePath
|
FreshMirrorCreation $projectCount $giteaNembroUser $giteaNembroPass $giteaNembro $simplePath
|
||||||
|
$createdMirrors++
|
||||||
|
}
|
||||||
|
#se la risposta non contiene "gitea-azzano" procedo a creare mirror relativo
|
||||||
|
if ($gitlabResponse.Content -inotmatch "gitea-azzano") {
|
||||||
|
#chiamo funzione per creare mirror verso gitea-azzano
|
||||||
|
FreshMirrorCreation $projectCount $giteaAzzanoUser $giteaAzzanoPass $giteaAzzano $simplePath
|
||||||
|
$createdMirrors++
|
||||||
}
|
}
|
||||||
#OLD: se la risposta non contiene "gitlab-nembro" procedo a creare mirror relativo
|
|
||||||
#if ($gitlabResponse.Content -inotmatch "gitlab-nembro") {
|
|
||||||
# #chiamo funzione per creare mirror verso gitlab-nembro
|
|
||||||
# FreshMirrorCreation $projectCount $userName $tokenNembro $destinationNembro $simplePath
|
|
||||||
#}
|
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
@@ -103,6 +104,8 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
|
|
||||||
#scrivo a video le statistiche
|
#scrivo a video le statistiche
|
||||||
WriteLogOutput $logFile 0 ""
|
WriteLogOutput $logFile 0 ""
|
||||||
|
WriteLogOutput $logFile 0 "Nuovi mirror creati: $createdMirrors"
|
||||||
|
WriteLogOutput $logFile 0 ""
|
||||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||||
WriteLogOutput $logFile 0 ""
|
WriteLogOutput $logFile 0 ""
|
||||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno può cancellare i mirror desiderati
|
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno può cancellare i mirror desiderati
|
||||||
|
|
||||||
#IMPORTANTE: SCRIPT PERICOLOSO. TOGLIERE COMMENTO A RIGA 60 PER CANCELLARE.
|
#IMPORTANTE: SCRIPT PERICOLOSO. TOGLIERE COMMENTO A RIGA 62 PER CANCELLARE.
|
||||||
|
|
||||||
#importo file contenente configurazioni
|
#importo file contenente configurazioni
|
||||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||||
@@ -16,13 +16,15 @@ $mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 1
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 250
|
$endProj = 300
|
||||||
|
#contatore numero mirror cancellati
|
||||||
|
$deletedMirrors = 0
|
||||||
#nome file di log
|
#nome file di log
|
||||||
$logFile = "MirrorsDelete.log"
|
$logFile = "MirrorsDelete.log"
|
||||||
#nome file di log old
|
#nome file di log old
|
||||||
$oldLogFile = "MirrorsDelete.old"
|
$oldLogFile = "MirrorsDelete.old"
|
||||||
#stringa da cercare per cancellare il mirror
|
#stringa da cercare per cancellare il mirror
|
||||||
$mirrorToDelete = "gitlab-nembro"
|
$mirrorToDelete = "gitlab-azzano"
|
||||||
|
|
||||||
#creazione folder di Log se non esiste
|
#creazione folder di Log se non esiste
|
||||||
CheckLogFolder
|
CheckLogFolder
|
||||||
@@ -59,6 +61,7 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
|||||||
$deleteUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $gitResponse.id
|
$deleteUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $gitResponse.id
|
||||||
#Invoke-WebRequest -URI $deleteUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
#Invoke-WebRequest -URI $deleteUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||||
WriteLogOutput $logFile 1 "Eliminato mirror: $gitResponse"
|
WriteLogOutput $logFile 1 "Eliminato mirror: $gitResponse"
|
||||||
|
$deletedMirrors++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,6 +85,8 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
|
|
||||||
#scrivo a video le statistiche
|
#scrivo a video le statistiche
|
||||||
WriteLogOutput $logFile 0 ""
|
WriteLogOutput $logFile 0 ""
|
||||||
|
WriteLogOutput $logFile 0 "Numero mirror cancellati: $deletedMirrors"
|
||||||
|
WriteLogOutput $logFile 0 ""
|
||||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||||
WriteLogOutput $logFile 0 ""
|
WriteLogOutput $logFile 0 ""
|
||||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
|||||||
else {
|
else {
|
||||||
WriteLogOutput $logFile 0 $("Mirror Push: Unknown - " + $item.url)
|
WriteLogOutput $logFile 0 $("Mirror Push: Unknown - " + $item.url)
|
||||||
}
|
}
|
||||||
$mirrorCount = $mirrorCount + 1
|
$mirrorCount++
|
||||||
}
|
}
|
||||||
$existingProjects = $existingProjects + 1
|
$existingProjects++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ $mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 1
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 300
|
$endProj = 250
|
||||||
#inizializzo variabili vuote
|
#inizializzo variabili vuote
|
||||||
$mirrorId = ""
|
$mirrorId = ""
|
||||||
$mirrorUrl = ""
|
$mirrorUrl = ""
|
||||||
@@ -25,7 +25,7 @@ $logFile = "GitlabMirroringGitea.log"
|
|||||||
#nome file di log old
|
#nome file di log old
|
||||||
$oldLogFile = "GitlabMirroringGitea.old"
|
$oldLogFile = "GitlabMirroringGitea.old"
|
||||||
|
|
||||||
#gitea di destinazione
|
#gitea di destinazione (scegliere prima di esecuzione)
|
||||||
#$target = "steamware"
|
#$target = "steamware"
|
||||||
$target = "nembro"
|
$target = "nembro"
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ if ($target = "nembro"){
|
|||||||
#nome utente gitea nembro che effettua i mirror push
|
#nome utente gitea nembro che effettua i mirror push
|
||||||
$giteaUser = $giteaNembroUser
|
$giteaUser = $giteaNembroUser
|
||||||
#autenticazione replica gitea nembro
|
#autenticazione replica gitea nembro
|
||||||
$giteaPass = $giteaNembroPass
|
$giteaPass = $tokenGiteaNembro
|
||||||
#access token per autenticazione gitea nembro da profilo replica
|
#access token per autenticazione gitea nembro da profilo replica
|
||||||
$giteaHead = $giteaNembroHead
|
$giteaHead = $giteaNembroHead
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
###Gitlab: Rinnovamento mirrors esistenti###
|
###Gitlab: Rinnovamento mirrors esistenti (O CANCELLAZIONE)###
|
||||||
|
|
||||||
#Questo script viene utilizzato per cancellare e ricreare i mirror esistenti verso gitlab-nembro e gitlab-azzano. Da usare allo scadere dei token di autenticazione.
|
#Questo script viene utilizzato per cancellare e ricreare i mirror esistenti verso gitlab-nembro e gitlab-azzano. Da usare allo scadere dei token di autenticazione.
|
||||||
#Una volta inseriti i token nuovi nel file ApiScriptConfig, facendo girare questo script tutti i mirror verso nembro e azzano sono ricreati con il token nuovo.
|
#Una volta inseriti i token nuovi nel file ApiScriptConfig, facendo girare questo script tutti i mirror verso nembro e azzano sono ricreati con il token nuovo.
|
||||||
@@ -15,7 +15,7 @@ $mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
|||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 1
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 250
|
$endProj = 300
|
||||||
#inizializzo variabili vuote
|
#inizializzo variabili vuote
|
||||||
$mirrorId = ""
|
$mirrorId = ""
|
||||||
$mirrorUrl = ""
|
$mirrorUrl = ""
|
||||||
@@ -66,7 +66,7 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
if ($item.url.Contains("azzano")) {
|
if ($item.url.Contains("azzano")) {
|
||||||
$doExecute = "true"
|
$doExecute = "true"
|
||||||
$destinationToken = $tokenAzzano
|
$destinationToken = $tokenAzzano
|
||||||
$mirrorDestination = "@gitlab-azzano.steamware.net"
|
$mirrorDestination = $destinationAzzano
|
||||||
}
|
}
|
||||||
#controllo se l'url del mirror contiene nembro, riscrivo mirror
|
#controllo se l'url del mirror contiene nembro, riscrivo mirror
|
||||||
#elseif ($item.url.Contains("nembro")) {
|
#elseif ($item.url.Contains("nembro")) {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ $head = $azzanoHead
|
|||||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount $gitlabIstance**"
|
WriteLogOutput $logFile 1 "**PROGETTO $projectCount $gitlabIstance**"
|
||||||
foreach ($item in $parsedResponse) {
|
foreach ($item in $parsedResponse) {
|
||||||
WriteLogOutput $logFile 1 "Protected Branch Name: $($item.name) - Allow Force Push: $($item.allow_force_push)"
|
WriteLogOutput $logFile 1 "Protected Branch Name: $($item.name) - Allow Force Push: $($item.allow_force_push)"
|
||||||
$protectedProjects = $protectedProjects + 1
|
$protectedProjects++
|
||||||
if ($deleteProtection -eq 1) {
|
if ($deleteProtection -eq 1) {
|
||||||
#nuovo URL x delete
|
#nuovo URL x delete
|
||||||
$callUrlDelete = "https://" + $gitlabIstance + "/api/v4/projects/" + $projectCount + "/protected_branches/" + $item.name
|
$callUrlDelete = "https://" + $gitlabIstance + "/api/v4/projects/" + $projectCount + "/protected_branches/" + $item.name
|
||||||
@@ -69,7 +69,7 @@ $head = $azzanoHead
|
|||||||
Invoke-WebRequest -Method Delete -URI $callUrlDelete -Headers $head -ContentType "application/json" -UseBasicParsing
|
Invoke-WebRequest -Method Delete -URI $callUrlDelete -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$existingProjects = $existingProjects + 1
|
$existingProjects++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -57,15 +57,15 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||||
if ($item.status.Equals("success")) {
|
if ($item.status.Equals("success")) {
|
||||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
$pipelineSuccessCount++
|
||||||
}
|
}
|
||||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||||
else {
|
else {
|
||||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
$pipelineErrorsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
$projectsWithPipeline++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -57,15 +57,15 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||||
if ($item.status.Equals("success")) {
|
if ($item.status.Equals("success")) {
|
||||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
$pipelineSuccessCount++
|
||||||
}
|
}
|
||||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||||
else {
|
else {
|
||||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
$pipelineErrorsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
$projectsWithPipeline++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -60,15 +60,15 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||||
if ($item.status.Equals("success")) {
|
if ($item.status.Equals("success")) {
|
||||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
$pipelineSuccessCount++
|
||||||
}
|
}
|
||||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||||
else {
|
else {
|
||||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
$pipelineErrorsCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
$projectsWithPipeline++
|
||||||
}
|
}
|
||||||
#scrivo se trovo un errore durante il try/catch
|
#scrivo se trovo un errore durante il try/catch
|
||||||
catch {
|
catch {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 200
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 300
|
$endProj = 300
|
||||||
#nome file di log
|
#nome file di log
|
||||||
|
|||||||
@@ -12,25 +12,26 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 200
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 260
|
$endProj = 300
|
||||||
#nome file di log
|
#nome file di log
|
||||||
$logFile = "GiteaReposCreation.log"
|
$logFile = "GiteaReposCreation.log"
|
||||||
#nome file di log old
|
#nome file di log old
|
||||||
$oldLogFile = "GiteaReposCreation.old"
|
$oldLogFile = "GiteaReposCreation.old"
|
||||||
|
|
||||||
#gitea di destinazione
|
|
||||||
#$target = "steamware"
|
|
||||||
$target = "nembro"
|
|
||||||
|
|
||||||
#creazione folder di Log se non esiste
|
#creazione folder di Log se non esiste
|
||||||
CheckLogFolder
|
CheckLogFolder
|
||||||
|
|
||||||
#rotazione vecchio logFile da .log a .old se esiste
|
#rotazione vecchio logFile da .log a .old se esiste
|
||||||
RotateOldLog
|
RotateOldLog
|
||||||
|
|
||||||
if ($target = "steamware"){
|
#gitea di destinazione
|
||||||
|
#$target = "steamware"
|
||||||
|
#$target = "nembro"
|
||||||
|
$target = "azzano"
|
||||||
|
|
||||||
|
if ($target -eq "steamware"){
|
||||||
#destinazione mirror per gitea Steamw
|
#destinazione mirror per gitea Steamw
|
||||||
$giteaDestination = $giteaSteamw
|
$giteaDestination = $giteaSteamw
|
||||||
#nome utente gitea Steamw che effettua i mirror push
|
#nome utente gitea Steamw che effettua i mirror push
|
||||||
@@ -40,7 +41,7 @@ $giteaPass = $giteaSteamwPass
|
|||||||
#access token per autenticazione gitea Steamw da profilo replica
|
#access token per autenticazione gitea Steamw da profilo replica
|
||||||
$giteaHead = $giteaSteamwHead
|
$giteaHead = $giteaSteamwHead
|
||||||
}
|
}
|
||||||
if ($target = "nembro") {
|
if ($target -eq "nembro") {
|
||||||
#destinazione mirror per gitea nembro
|
#destinazione mirror per gitea nembro
|
||||||
$giteaDestination = $giteaNembro
|
$giteaDestination = $giteaNembro
|
||||||
#nome utente gitea nembro che effettua i mirror push
|
#nome utente gitea nembro che effettua i mirror push
|
||||||
@@ -50,6 +51,16 @@ $giteaPass = $giteaNembroPass
|
|||||||
#access token per autenticazione gitea nembro da profilo replica
|
#access token per autenticazione gitea nembro da profilo replica
|
||||||
$giteaHead = $giteaNembroHead
|
$giteaHead = $giteaNembroHead
|
||||||
}
|
}
|
||||||
|
if ($target -eq "azzano") {
|
||||||
|
#destinazione mirror per gitea azzano
|
||||||
|
$giteaDestination = $giteaAzzano
|
||||||
|
#nome utente gitea azzano che effettua i mirror push
|
||||||
|
$giteaUser = $giteaAzzanoUser
|
||||||
|
#autenticazione replica gitea nemazzanobro
|
||||||
|
$giteaPass = $giteaAzzanoPass
|
||||||
|
#access token per autenticazione gitea azzano da profilo replica
|
||||||
|
$giteaHead = $giteaAzzanoHead
|
||||||
|
}
|
||||||
|
|
||||||
#scrivo intestazione e inizio analisi
|
#scrivo intestazione e inizio analisi
|
||||||
WriteLogOutput $logFile 0 "--------------------"
|
WriteLogOutput $logFile 0 "--------------------"
|
||||||
@@ -76,7 +87,7 @@ for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
|||||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||||
foreach ($gitlabItem in $parsedGitlabResponse) {
|
foreach ($gitlabItem in $parsedGitlabResponse) {
|
||||||
WriteLogOutput $logFile 1 "Gitlab Project Name: $($gitlabItem.name)"
|
WriteLogOutput $logFile 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||||
$callGiteaUrl = "https://" + $giteaDestination + "/api/v1/orgs/Egalware/repos"
|
$callGiteaUrl = "http://" + $giteaDestination + "/api/v1/orgs/Egalware/repos"
|
||||||
#dichiaro un body da convertire in JSON con il nome del repo da creare (prendo path o name a seconda delle necessità)
|
#dichiaro un body da convertire in JSON con il nome del repo da creare (prendo path o name a seconda delle necessità)
|
||||||
$giteaBody =
|
$giteaBody =
|
||||||
@{
|
@{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
|||||||
# avvio stopwatch
|
# avvio stopwatch
|
||||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||||
#contatore ciclo do while
|
#contatore ciclo do while
|
||||||
$startProj = 200
|
$startProj = 1
|
||||||
#numero massimo di progetti da analizzare
|
#numero massimo di progetti da analizzare
|
||||||
$endProj = 300
|
$endProj = 300
|
||||||
#nome file di log
|
#nome file di log
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Aggiorna il livello di notifica GitLab per un range di utenti
|
||||||
|
e logga tutto in C:\Steamware\Logs\Gitlab\notificationLevelChange.log
|
||||||
|
#>
|
||||||
|
|
||||||
|
# importa configurazioni
|
||||||
|
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||||
|
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||||
|
|
||||||
|
$GitlabUrl = "https://gitlab.steamware.net"
|
||||||
|
$PrivateToken = $tokenGitlab
|
||||||
|
|
||||||
|
# Range utenti da aggiornare (modificabile)
|
||||||
|
$StartId = 1
|
||||||
|
$EndId = 50
|
||||||
|
|
||||||
|
# Livello notifiche da impostare (modificabile)
|
||||||
|
$NewLevel = "mention" # altri valori: disabled, participating, watch, global, custom
|
||||||
|
|
||||||
|
# Percorso log
|
||||||
|
$LogDir = "C:\Steamware\Logs\Gitlab"
|
||||||
|
$LogFile = Join-Path $LogDir "notificationLevelChange.log"
|
||||||
|
|
||||||
|
# Crea cartella log se non esiste
|
||||||
|
if (-not (Test-Path $LogDir)) {
|
||||||
|
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Header base
|
||||||
|
$baseHeaders = @{
|
||||||
|
"PRIVATE-TOKEN" = $PrivateToken
|
||||||
|
"Content-Type" = "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Corpo JSON della richiesta
|
||||||
|
$body = @{ level = $NewLevel } | ConvertTo-Json
|
||||||
|
|
||||||
|
# Inizializza log
|
||||||
|
"INFO [$((Get-Date).ToString('o'))] Starting notification level update for IDs $StartId-$EndId (level=$NewLevel)" |
|
||||||
|
Out-File -FilePath $LogFile -Encoding UTF8
|
||||||
|
|
||||||
|
# Ciclo utenti
|
||||||
|
for ($id = $StartId; $id -le $EndId; $id++) {
|
||||||
|
|
||||||
|
$separator = "----- USER $id -----"
|
||||||
|
$url = "$GitlabUrl/api/v4/notification_settings"
|
||||||
|
|
||||||
|
# Clona headers e aggiunge Sudo per modificare altri utenti
|
||||||
|
$headers = @{}
|
||||||
|
foreach ($k in $baseHeaders.Keys) { $headers[$k] = $baseHeaders[$k] }
|
||||||
|
$headers["Sudo"] = "$id"
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = Invoke-WebRequest `
|
||||||
|
-Method PUT `
|
||||||
|
-Uri $url `
|
||||||
|
-Headers $headers `
|
||||||
|
-Body $body `
|
||||||
|
-ErrorAction Stop
|
||||||
|
|
||||||
|
"$separator`nINFO [$((Get-Date).ToString('o'))] UPDATED id=$id level=$NewLevel status=$($response.StatusCode)" |
|
||||||
|
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$msg = $_.Exception.Message -replace "`r?`n"," "
|
||||||
|
"$separator`nERROR [$((Get-Date).ToString('o'))] FAILED id=$id message=$msg" |
|
||||||
|
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
}
|
||||||
|
|
||||||
|
Start-Sleep -Milliseconds 150
|
||||||
|
}
|
||||||
|
|
||||||
|
"INFO [$((Get-Date).ToString('o'))] Completed." |
|
||||||
|
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
|
||||||
|
Write-Host "Fatto. Log salvato in $LogFile"
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Recupera utenti GitLab per ID 1-100 e scrive output in C:\Steamware\Logs\Gitlab\gitlab_users_1-100.log
|
||||||
|
#>
|
||||||
|
|
||||||
|
#importo file contenente configurazioni
|
||||||
|
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||||
|
#importo file contenente funzioni
|
||||||
|
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||||
|
|
||||||
|
$GitlabUrl = "gitlab.steamware.net"
|
||||||
|
$PrivateToken = $tokenGitlab
|
||||||
|
|
||||||
|
# Configurazione
|
||||||
|
$StartId = 1
|
||||||
|
$EndId = 50
|
||||||
|
$LogDir = "C:\Steamware\Logs\Gitlab"
|
||||||
|
$LogFile = Join-Path -Path $LogDir -ChildPath "GitlabUsers.log"
|
||||||
|
|
||||||
|
# Crea cartella log se non esiste
|
||||||
|
try {
|
||||||
|
if (-not (Test-Path -Path $LogDir)) {
|
||||||
|
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Impossibile creare la cartella di log $LogDir. Errore: $($_.Exception.Message)"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Header autenticazione
|
||||||
|
$baseUrl = $GitlabUrl.TrimEnd('/')
|
||||||
|
$headers = @{ "PRIVATE-TOKEN" = $PrivateToken }
|
||||||
|
|
||||||
|
# Inizializza file di log (sovrascrive se esiste)
|
||||||
|
$startLine = "INFO [{0}] Starting GitLab users retrieval for IDs {1}-{2}" -f (Get-Date -Format o), $StartId, $EndId
|
||||||
|
$startLine | Out-File -FilePath $LogFile -Encoding UTF8
|
||||||
|
|
||||||
|
$retrieved = 0
|
||||||
|
$errors = 0
|
||||||
|
|
||||||
|
# inizializza contatore per numeratore
|
||||||
|
$counter = 1
|
||||||
|
$total = $EndId - $StartId + 1
|
||||||
|
|
||||||
|
for ($id = $StartId; $id -le $EndId; $id++) {
|
||||||
|
$url = "$baseUrl/api/v4/users/$id"
|
||||||
|
# crea prefisso numerato e separatore (es. --- 001/100 ---)
|
||||||
|
$num = "{0:D3}" -f $counter
|
||||||
|
$separator = "----- $num/$total -----"
|
||||||
|
|
||||||
|
try {
|
||||||
|
$user = Invoke-RestMethod -Uri $url -Headers $headers -Method Get -ErrorAction Stop
|
||||||
|
$json = $user | ConvertTo-Json -Depth 10 -Compress
|
||||||
|
$line = "{0} `nINFO [{1}] USER_FOUND id={2} data={3}" -f $separator, (Get-Date -Format o), $id, $json
|
||||||
|
$line | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
$retrieved++
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
$status = "unknown"
|
||||||
|
try {
|
||||||
|
if ($_.Exception.Response -ne $null) {
|
||||||
|
$status = $_.Exception.Response.StatusCode.value__
|
||||||
|
}
|
||||||
|
} catch { $status = "unknown" }
|
||||||
|
|
||||||
|
if ($status -eq 404) {
|
||||||
|
$line = "{0} `nWARN [{1}] USER_NOT_FOUND id={2} status=404 message=Not Found" -f $separator, (Get-Date -Format o), $id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$msg = $_.Exception.Message -replace "`r?`n", " "
|
||||||
|
$line = "{0} `nERROR [{1}] USER_ERROR id={2} status={3} message={4}" -f $separator, (Get-Date -Format o), $id, $status, $msg
|
||||||
|
}
|
||||||
|
$line | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
$errors++
|
||||||
|
}
|
||||||
|
|
||||||
|
$counter++
|
||||||
|
Start-Sleep -Milliseconds 200
|
||||||
|
}
|
||||||
|
|
||||||
|
$endLine = "INFO [{0}] Completed. Retrieved={1} Errors={2}" -f (Get-Date -Format o), $retrieved, $errors
|
||||||
|
$endLine | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||||
|
|
||||||
|
Write-Host "Fatto. Log salvato in $LogFile. Utenti recuperati: $retrieved. Errori: $errors."
|
||||||
Reference in New Issue
Block a user