Functions/Update-ArtifactoryStorageInfo.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#PSScriptInfo
 
.VERSION 1.0.0
 
.GUID
 
.AUTHOR Artsiom Krot
 
.PROJECTURI https://github.com/artyom-krot/PS.JfrogArtifactory
 
.RELEASENOTES
 
 
Script file name:
 
    Update-ArtifactoryStorageInfo.ps1
 
.DESCRIPTION
 
    The script is an integral part of PS.JfrogArtifactory solution (https://github.com/artyom-krot/PS.JfrogArtifactory)
 
    Jfrog ref documentation: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-RefreshStorageSummaryInfo
 
#>



function Update-ArtifactoryStorageInfo {
    <#
    .SYNOPSIS
        PowerShell script for invoking rest api call to jfrog artifactory to refresh the information about the storage.
 
    .DESCRIPTION
         
    .INPUTS
 
    .OUTPUTS
        Refreshes storage summary information regarding binaries, file store and repositories.
         
    .NOTES
     
    .EXAMPLE
         
 
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Low')]
    param(
        [parameter(Position = 0, Mandatory = $false)]
        [switch]
        $Force
    )

    $artifactoryParameters = Get-ArtifactoryParameters

    if ($Force -or $PSCmdlet.ShouldProcess("Trigger update storage information job for the '$($artifactoryParameters.serverUri)'")) {
        try {   
            $responseMessage =  (Invoke-ArtifactoryRestApi -RestApiPath "/api/storageinfo/calculate" `
                                                          -Method POST `
                                                          -ContentType 'application/json').info
        } 
        catch [System.Net.WebException] {
            $response = $_.Exception.Response
            $responseMessage =  'Failed to trigger {0} due to status code {1} ({2}).' -f $response.ResponseUri, [int]($response.StatusCode), $response.StatusDescription
            Write-Error ($responseMessage)
        }
    }  
    return $responseMessage
}