Skip to content

Commit

Permalink
Merge pull request #849 from Splaxi/impl-product-details-on-shared-lc…
Browse files Browse the repository at this point in the history
…s-assets

Feature: Add product build and product version for shared asset files
  • Loading branch information
Splaxi authored Jul 9, 2024
2 parents 9094b88 + 826a875 commit b04ea18
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 9 deletions.
48 changes: 43 additions & 5 deletions d365fo.tools/functions/get-d365lcssharedassetfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
.PARAMETER Latest
Instruct the cmdlet to only fetch the latest file from the Asset Library from LCS
.PARAMETER SkipSasGeneration
Instruct the cmdlet to only fetch the meta data from the asset file (entry)
This is to speed up the listing of entries, in some of the larger areas in the Shared Asset Library
.PARAMETER RetryTimeout
The retry timeout, before the cmdlet should quit retrying based on the 429 status code
Expand Down Expand Up @@ -200,6 +205,18 @@
The default values can be configured using Set-D365LcsApiConfig.
.EXAMPLE
PS C:\> Get-D365LcsSharedAssetFile -FileType SoftwareDeployablePackage -SkipSasGeneration
This will list all Software Deployable Packages in the shared asset library, but skip the SAS / Download generation
It will search for SoftwareDeployablePackage by using the FileType parameter.
This will increase the speed getting the list of assets - but you will not get a downloadable link.
All default values will come from the configuration available from Get-D365LcsApiConfig.
The default values can be configured using Set-D365LcsApiConfig.
.LINK
Get-D365LcsApiConfig
Expand Down Expand Up @@ -246,6 +263,8 @@ function Get-D365LcsSharedAssetFile {
[Alias('GetLatest')]
[switch] $Latest,

[switch] $SkipSasGeneration,

[Timespan] $RetryTimeout = "00:00:00",

[switch] $EnableException
Expand All @@ -257,14 +276,26 @@ function Get-D365LcsSharedAssetFile {
$BearerToken = "Bearer $BearerToken"
}

$assets = Get-LcsSharedAssetFile -BearerToken $BearerToken -LcsApiUri $LcsApiUri -FileType $([int]$FileType) -RetryTimeout $RetryTimeout
$colTemp = Get-LcsSharedAssetFile -BearerToken $BearerToken -LcsApiUri $LcsApiUri -FileType $([int]$FileType) -RetryTimeout $RetryTimeout

$assets = $colTemp | Select-PSFObject -TypeName "D365FO.TOOLS.Lcs.Asset.File" -Property "*", "Id as AssetId", `
@{Name = "ProductVersion"; Expression = { [System.Version]$($_.Name.Split(" ") | Select-Object -Last 1 ) } }, `
@{Name = "ProductBuild"; Expression = { [System.Version]$($_.FileName.Split("_") | Select-Object -First 1 -Skip 1) } }

if (Test-PSFFunctionInterrupt) { return }

if ($Latest) {
$latestSharedAsset = $assets | Sort-Object -Property "ModifiedDate" -Descending | Select-Object -First 1
$latestSharedAsset = Get-LcsFileAsset -BearerToken $BearerToken -ProjectId $ProjectId -LcsApiUri $LcsApiUri -AssetId $latestSharedAsset.Id -RetryTimeout $RetryTimeout
$latestSharedAsset | Select-PSFObject -TypeName "D365FO.TOOLS.Lcs.Asset.File" "*", "Id as AssetId"

if ($SkipSasGeneration -eq $false) {
$latestSharedAsset = Get-LcsFileAsset -BearerToken $BearerToken -ProjectId $ProjectId -LcsApiUri $LcsApiUri -AssetId $latestSharedAsset.Id -RetryTimeout $RetryTimeout
$latestSharedAsset | Select-PSFObject -TypeName "D365FO.TOOLS.Lcs.Asset.File" -Property "*", "Id as AssetId", `
@{Name = "ProductVersion"; Expression = { [System.Version]$($_.Name.Split(" ") | Select-Object -Last 1 ) } }, `
@{Name = "ProductBuild"; Expression = { [System.Version]$($_.FileName.Split("_") | Select-Object -First 1 -Skip 1) } }
}
else {
$latestSharedAsset
}
}
else {
foreach ($obj in $assets) {
Expand All @@ -274,8 +305,15 @@ function Get-D365LcsSharedAssetFile {
if ($obj.FileDescription -NotLike $AssetDescription) { continue }
if ($obj.Id -NotLike $AssetId) { continue }

$obj = Get-LcsFileAsset -BearerToken $BearerToken -ProjectId $ProjectId -LcsApiUri $LcsApiUri -AssetId $obj.Id -RetryTimeout $RetryTimeout
$obj | Select-PSFObject -TypeName "D365FO.TOOLS.Lcs.Asset.File" "*", "Id as AssetId"
if ($SkipSasGeneration -eq $false) {
$obj = Get-LcsFileAsset -BearerToken $BearerToken -ProjectId $ProjectId -LcsApiUri $LcsApiUri -AssetId $obj.Id -RetryTimeout $RetryTimeout
$obj | Select-PSFObject -TypeName "D365FO.TOOLS.Lcs.Asset.File" -Property "*", "Id as AssetId", `
@{Name = "ProductVersion"; Expression = { [System.Version]$($_.Name.Split(" ") | Select-Object -Last 1 ) } }, `
@{Name = "ProductBuild"; Expression = { [System.Version]$($_.FileName.Split("_") | Select-Object -First 1 -Skip 1) } }
}
else {
$obj
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion d365fo.tools/internal/tepp/assignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Register-PSFTeppArgumentCompleter -Command Get-D365LcsAssetValidationStatus -Par
Register-PSFTeppArgumentCompleter -Command Get-D365LcsDatabaseBackups -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Register-PSFTeppArgumentCompleter -Command Get-D365LcsDatabaseOperationStatus -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Register-PSFTeppArgumentCompleter -Command Get-D365LcsDeploymentStatus -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls

Register-PSFTeppArgumentCompleter -Command Get-D365LcsEnvironmentHistory -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Register-PSFTeppArgumentCompleter -Command Get-D365LcsEnvironmentMetadata -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Register-PSFTeppArgumentCompleter -Command Get-D365LcsSharedAssetFile -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls

Register-PSFTeppArgumentCompleter -Command Invoke-D365LcsDatabaseExport -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Register-PSFTeppArgumentCompleter -Command Invoke-D365LcsDatabaseRefresh -Parameter LcsApiUri -Name d365fo.tools.lcs.api.urls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter SkipSasGeneration' {
$parameter = (Get-Command Get-D365LcsSharedAssetFile).Parameters['SkipSasGeneration']
$parameter.Name | Should -Be 'SkipSasGeneration'
$parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be '__AllParameterSets'
$parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets'
$parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].Position | Should -Be -2147483648
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter RetryTimeout' {
$parameter = (Get-Command Get-D365LcsSharedAssetFile).Parameters['RetryTimeout']
$parameter.Name | Should -Be 'RetryTimeout'
Expand Down Expand Up @@ -172,7 +185,7 @@
Describe "Testing parameterset __AllParameterSets" {
<#
__AllParameterSets -
__AllParameterSets -ProjectId -FileType -AssetName -AssetVersion -AssetFilename -AssetDescription -AssetId -BearerToken -LcsApiUri -Latest -RetryTimeout -EnableException
__AllParameterSets -ProjectId -FileType -AssetName -AssetVersion -AssetFilename -AssetDescription -AssetId -BearerToken -LcsApiUri -Latest -SkipSasGeneration -RetryTimeout -EnableException
#>
}

Expand Down
35 changes: 33 additions & 2 deletions docs/Get-D365LcsSharedAssetFile.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Get information for assets from the shared asset library of LCS
```
Get-D365LcsSharedAssetFile [[-ProjectId] <Int32>] [[-FileType] <LcsAssetFileType>] [[-AssetName] <String>]
[[-AssetVersion] <String>] [[-AssetFilename] <String>] [[-AssetDescription] <String>] [[-AssetId] <String>]
[[-BearerToken] <String>] [[-LcsApiUri] <String>] [-Latest] [[-RetryTimeout] <TimeSpan>] [-EnableException]
[<CommonParameters>]
[[-BearerToken] <String>] [[-LcsApiUri] <String>] [-Latest] [-SkipSasGeneration] [[-RetryTimeout] <TimeSpan>]
[-EnableException] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -125,6 +125,20 @@ All default values will come from the configuration available from Get-D365LcsAp

The default values can be configured using Set-D365LcsApiConfig.

### EXAMPLE 9
```
Get-D365LcsSharedAssetFile -FileType SoftwareDeployablePackage -SkipSasGeneration
```

This will list all Software Deployable Packages in the shared asset library, but skip the SAS / Download generation
It will search for SoftwareDeployablePackage by using the FileType parameter.

This will increase the speed getting the list of assets - but you will not get a downloadable link.

All default values will come from the configuration available from Get-D365LcsApiConfig.

The default values can be configured using Set-D365LcsApiConfig.

## PARAMETERS

### -ProjectId
Expand Down Expand Up @@ -346,6 +360,23 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -SkipSasGeneration
Instruct the cmdlet to only fetch the meta data from the asset file (entry)
This is to speed up the listing of entries, in some of the larger areas in the Shared Asset Library
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -RetryTimeout
The retry timeout, before the cmdlet should quit retrying based on the 429 status code
Expand Down

0 comments on commit b04ea18

Please sign in to comment.