controls/secretmanager-edit-modal.ps1
function New-UDEditSecretManagerModal { param ( [Parameter(Mandatory = $true)] $SecretManager ) Show-UDModal -Width "75%" -Content { New-UDPageHeader -Text ("Edit a Secret Manager") New-UDParagraph -Text " " #Spacer New-UDTabContainer -Tabs { New-UDTab -Text 'General' -Content { New-UDParagraph -Text "General Secret Manager Settings" New-UDCard -Content { New-UDTextbox -Id "EditSecretManagerModalTextBoxName" -Label "Name" -Type text -Value $SecretManager.Name New-UDTextbox -Id "EditSecretManagerModalTextBoxDescription" -Label "Description" -Type text -Value $SecretManager.Description } } New-UDTab -Text 'Get Script' -Content { New-UDElement -Tag 'div' -Attributes @{ style = @{ height = "620px" } } -Content { New-UDParagraph -Text "Get Script Content" New-UDCodeEditor -Id 'EditSecretManagerGetScriptBlockEditor' -Language 'powershell' -Code $SecretManager.GetSecretScript -Theme 'vs-dark' -Autosize } } New-UDTab -Text 'Set Script' -Content { New-UDElement -Tag 'div' -Attributes @{ style = @{ height = "620px" } } -Content { New-UDParagraph -Text "Set Script Content" New-UDCodeEditor -Id 'EditSecretManagerSetScriptBlockEditor' -Language 'powershell' -Code $SecretManager.SetSecretScript -Theme 'vs-dark' -Autosize } } New-UDTab -Text "Execution Options" -Content { New-UDParagraph -Text "Execution Options" New-UDCard -Content { $PowerShellVersions = Get-UAPowerShellVersion New-UDSelect -Id "EditSecretManagerModalSelectPowerShellVersion" -Label "Required PowerShell Version" -Option { New-UDSelectOption -Name "Default" -Value "Any" $PowerShellVersions | ForEach-Object { New-UDSelectOption -Name $_.Version -Value $_.Version } } -OnChange { } } } New-UDTab -Text 'Finalize' -Content { New-UDParagraph -Text "Secret Manager Finalization" New-UDElement -Tag div -Attributes @{ style = @{ textAlign = "right" } } -Content { New-UDButton -Text "Save Changes" -Icon folder_plus -OnClick { # Get Input Data $Name = ((Get-UDElement -Id 'EditSecretManagerModalTextBoxName').Attributes["value"]) $Description = ((Get-UDElement -Id 'EditSecretManagerModalTextBoxDescription').Attributes["value"]) $RequiredPowerShellVersion = ((Get-UDElement -Id 'EditSecretManagerModalSelectPowerShellVersion').Attributes["value"]) $GetScriptBlock = [ScriptBlock]::Create((Get-UDElement -Id 'EditSecretManagerGetScriptBlockEditor').Attributes["code"]) $SetScriptBlock = [ScriptBlock]::Create((Get-UDElement -Id 'EditSecretManagerSetScriptBlockEditor').Attributes["code"]) # Null Checks if ($null -eq $GetScriptBlock -or $GetScriptBlock -eq "" -or $GetScriptBlock -eq " " -or $GetScriptBlock -eq "null"){$GetScriptBlock = [ScriptBlock]::Create("#Script")} if ($null -eq $SetScriptBlock -or $SetScriptBlock -eq "" -or $SetScriptBlock -eq " " -or $SetScriptBlock -eq "null"){$SetScriptBlock = [ScriptBlock]::Create("#Script")} if($RequiredPowerShellVersion -eq "Any" -or $RequiredPowerShellVersion -eq "null") { $RequiredPowerShellVersion = $null } # Create SCript $SecretManager | Set-UASecretManager -Name $Name -Description $Description -Get ($GetScriptBlock) -Set ($SetScriptBlock) -RequiredPowerShellVersion $RequiredPowerShellVersion # Grid Sync Sync-UDElement -Id "SecretsGrid" -Broadcast Hide-UDModal } } } } } } |