Skip to content

Commit 0880be4

Browse files
Refactor repository
1 parent dfa7fbf commit 0880be4

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/dsc/psresourceget.ps1

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,33 +323,27 @@ function SetOperation {
323323
'repository' {
324324
$rep = Get-PSResourceRepository -Name $inputObj.Name -ErrorAction SilentlyContinue
325325

326-
$splatt = @{}
327-
328-
if ($inputObj.Name) {
329-
$splatt['Name'] = $inputObj.Name
330-
}
331-
332-
if ($inputObj.Uri) {
333-
$splatt['Uri'] = $inputObj.Uri
334-
}
335-
336-
if ($inputObj.Trusted) {
337-
$splatt['Trusted'] = $inputObj.Trusted
338-
}
326+
$properties = @('Name', 'Uri', 'Trusted', 'Priority', 'RepositoryType')
339327

340-
if ($null -ne $inputObj.Priority ) {
341-
$splatt['Priority'] = $inputObj.Priority
342-
}
328+
$splatt = @{}
343329

344-
if ($inputObj.repositoryType) {
345-
$splatt['ApiVersion'] = $inputObj.repositoryType
330+
foreach($property in $properties) {
331+
if ($null -ne $inputObj.PSObject.Properties[$property]) {
332+
$splatt[$property] = $inputObj.$property
333+
}
346334
}
347335

348336
if ($null -eq $rep) {
349337
Register-PSResourceRepository @splatt
350338
}
351339
else {
352-
Set-PSResourceRepository @splatt
340+
if ($inputObj._exist -eq $false) {
341+
Write-Trace -message "Repository $($inputObj.Name) exists and _exist is false. Deleting it." -level info
342+
Unregister-PSResourceRepository -Name $inputObj.Name
343+
}
344+
else {
345+
Set-PSResourceRepository @splatt
346+
}
353347
}
354348

355349
return GetOperation -ResourceType $ResourceType

0 commit comments

Comments
 (0)