-
Notifications
You must be signed in to change notification settings - Fork 249
Handle parameter escaping internally in cf-create-service.ps1 #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/handle-parameter-escaping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−22
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77aae53
Handle parameter escaping internally in cf-create-service.ps1
Copilot eb71b1b
Improve comment clarity for backslash escaping logic
Copilot 42a1d87
Use ConvertTo-Json for robust escaping of all parameters
Copilot edf73e1
Apply suggestions from code review
TimHess 88f5a76
PascalParams, camelVariables, enhance consistency in readme & scripts
TimHess d628598
sync readme and helpmessage on params
TimHess File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,28 @@ | ||
| #Requires -Version 7.0 | ||
|
|
||
| Param( | ||
| [Parameter(Mandatory = $true, HelpMessage = "Escaped UNC path. For example, if the path is '\\localhost\steeltoe_network_share', use '\\\\localhost\\steeltoe_network_share'.")][string]$NetworkAddress, | ||
| [Parameter(Mandatory=$true)][string]$UserName, | ||
| [Parameter(Mandatory=$true)][string]$Password, | ||
| [string]$ServiceName = "credhub", | ||
| [string]$ServicePlan = "default", | ||
| [string]$ServiceInstanceName = "sampleNetworkShare" | ||
| [Parameter(Mandatory = $true, HelpMessage = "UNC path to the network share. For example: '\\localhost\steeltoe_network_share'")][string]$NetworkAddress, | ||
| [Parameter(Mandatory = $true, HelpMessage = "The username for accessing the file share, can include domain. For example: 'DOMAIN\username'")][string]$UserName, | ||
| [Parameter(Mandatory = $true, HelpMessage = "The password for accessing the file share.")][string]$Password, | ||
| [Parameter(Mandatory = $false, HelpMessage = "The name of the service for storing credentials")][string]$ServiceName = "credhub", | ||
| [Parameter(Mandatory = $false, HelpMessage = "The service plan to use")][string]$ServicePlan = "default", | ||
| [Parameter(Mandatory = $false, HelpMessage = "The name of the service instance")][string]$ServiceInstanceName = "sampleNetworkShare" | ||
| ) | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| $ParamJSON = [string]::Format('{{\"location\":\"{0}\",\"username\":\"{1}\",\"password\":\"{2}\"}}', $NetworkAddress, $UserName, $Password) | ||
| # Build parameter object and convert to JSON using PowerShell's built-in JSON serialization | ||
| # This automatically handles escaping of special characters including backslashes, quotes, etc. | ||
| $params = @{ | ||
bart-vmware marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| location = $NetworkAddress | ||
| username = $UserName | ||
| password = $Password | ||
| } | ||
| $jsonParams = $params | ConvertTo-Json -Compress | ||
|
|
||
| Write-Host "cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $ParamJSON -t $ServiceInstanceName" | ||
| # Create a redacted copy of the parameters for logging so the password is not exposed | ||
| $redactedParams = $params.Clone() | ||
| $redactedParams['password'] = 'REDACTED' | ||
| $redactedJsonParams = $redactedParams | ConvertTo-Json -Compress | ||
|
|
||
| cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $ParamJSON -t $ServiceInstanceName | ||
| Write-Host "cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $redactedJsonParams -t $ServiceInstanceName" | ||
| cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $jsonParams -t $ServiceInstanceName | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.