Script RenewGitlabMirroring funzionante
This commit is contained in:
+46
-17
@@ -30,11 +30,17 @@ $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 "GitlabMirroring.log"
|
||||
$logFile = Join-Path $GitLogFolder "GitlabRebuildMirroring.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
@@ -84,32 +90,55 @@ do
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
#scrivo il numero del progetto
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
#verifico se i mirroring trovati per il progetto corrente contengono "azzano" nell'url
|
||||
$doExecute = "false"
|
||||
$token = ""
|
||||
$mirrorUrl = ""
|
||||
if($item.url.Contains("azzano"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $tokenAzzano
|
||||
$mirrorDestination = "@gitlab-azzano.steamware.net"
|
||||
}
|
||||
elseif($item.url.Contains("nembro"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $tokenNembro
|
||||
$mirrorDestination = "@gitlab-nembro.steamware.net"
|
||||
}
|
||||
#verifico se i mirroring trovati per il progetto corrente contengono "azzano" nell'url
|
||||
if($doExecute -eq "true")
|
||||
{
|
||||
#salvo id mirror e url mirror
|
||||
$id = $($item.id)
|
||||
$url = $($item.url)
|
||||
WriteLogOutput 2 "ID: $id - URL: $url"
|
||||
#tronco fino a azzano o nembro
|
||||
$trunk = $url.Remove(0, ($url.Length - 18))
|
||||
WriteLogOutput 2 "Truncated: $trunk"
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
WriteLogOutput 1 "ID: $mirrorId - URL: $mirrorUrl"
|
||||
#tronco url fino a azzano
|
||||
$trunkedPath = $mirrorUrl.Remove(0, ($mirrorUrl.Length - 18))
|
||||
#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
|
||||
$callUrlDeleteMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $id
|
||||
Invoke-WebRequest -URI $callUrlDeleteMirror -Method Delete -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
#chiamata api con method post che crea mirror con username e token specificati
|
||||
Invoke-WebRequest -Method Delete -URI $callUrlDeleteMirror -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
#compongo url da chiamare per creazione nuovo mirror
|
||||
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
$newMirrorUrl = "https://" + $userName + ":" + $tokenAzzano + "@gitlab-azzano.steamware.net" + $trunk
|
||||
$jsonBody
|
||||
|
||||
#converto body in json prima di passarlo
|
||||
Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $head -ContentType "application/json" -Body -UseBasicParsing
|
||||
#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
|
||||
Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $head -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||
WriteLogOutput 1 "Mirror $mirrorDestination$trunkedPath Ricostruito con successo"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user