Skip to content

Commit 88f5a76

Browse files
committed
PascalParams, camelVariables, enhance consistency in readme & scripts
1 parent edf73e1 commit 88f5a76

4 files changed

Lines changed: 27 additions & 21 deletions

File tree

FileShares/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ Before deploying the app, you must create an entry in CredHub to contain the cre
7575
> The [cf-create-service.ps1](scripts/cf-create-service.ps1) script requires PowerShell 7 or later.
7676

7777
1. Run [cf-create-service.ps1](scripts/cf-create-service.ps1) to create a service instance in CredHub, using parameters to set the required values:
78-
* `-NetworkAddress \\<hostname>\<sharename>` - UNC path of the fileshare
79-
* `-UserName <username>` - the username for accessing the fileshare (can include domain, e.g., `DOMAIN\username`)
80-
* `-Password <password>` - the password for accessing the fileshare
78+
* `-NetworkAddress \\<hostname>\<sharename>` - UNC path to the network share (required). For example: `\\localhost\steeltoe_network_share`
79+
* `-UserName <username>` - the username for accessing the fileshare, can include domain (e.g., `DOMAIN\username`) (required)
80+
* `-Password <password>` - the password for accessing the fileshare (required)
81+
* `-ServiceName credhub` - the name of the service
82+
* `-ServicePlan default` - the service plan
83+
* `-ServiceInstanceName sampleNetworkShare` - the name of the service instance
8184

8285
### Deploy the app
8386

FileShares/scripts/add-user-and-share.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#Requires -Modules Microsoft.PowerShell.LocalAccounts, SmbShare
33

44
Param(
5-
[string]$ShareName = "steeltoe_network_share",
6-
[string]$SharePath = "c:\steeltoe_network_share",
7-
[string]$UserName = "shareWriteUser",
8-
[string]$Password = "thisIs1Pass!"
5+
[Parameter(Mandatory = $false)][string]$ShareName = "steeltoe_network_share",
6+
[Parameter(Mandatory = $false)][string]$SharePath = "c:\steeltoe_network_share",
7+
[Parameter(Mandatory = $false)][string]$UserName = "shareWriteUser",
8+
[Parameter(Mandatory = $false)][string]$Password = "thisIs1Pass!"
99
)
1010
$ErrorActionPreference = "Stop"
11+
1112
if ($PSVersionTable.PSVersion.Major -lt 6)
1213
{
1314
Write-Output "Running in Windows PowerShell (version < 6)"
@@ -18,7 +19,7 @@ else
1819
Add-Type -AssemblyName System.Management.Automation
1920
Import-Module Microsoft.PowerShell.LocalAccounts -SkipEditionCheck
2021
}
21-
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
22+
$securePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
2223

2324
if (Get-LocalUser -Name $UserName -ErrorAction SilentlyContinue)
2425
{
@@ -28,7 +29,7 @@ else
2829
{
2930
Write-Host "Creating local user $UserName..."
3031
New-LocalUser $UserName `
31-
-Password $SecurePassword `
32+
-Password $securePassword `
3233
-FullName "SMB ReadWrite" `
3334
-Description "For write access to $ShareName" | Out-Null
3435
Write-Host "Done creating user."

FileShares/scripts/cf-create-service.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Param(
44
[Parameter(Mandatory = $true, HelpMessage = "UNC path to the network share. For example: '\\localhost\steeltoe_network_share'")][string]$NetworkAddress,
5-
[Parameter(Mandatory=$true)][string]$UserName,
6-
[Parameter(Mandatory=$true)][string]$Password,
7-
[string]$ServiceName = "credhub",
8-
[string]$ServicePlan = "default",
9-
[string]$ServiceInstanceName = "sampleNetworkShare"
5+
[Parameter(Mandatory = $true)][string]$UserName,
6+
[Parameter(Mandatory = $true)][string]$Password,
7+
[Parameter(Mandatory = $false)][string]$ServiceName = "credhub",
8+
[Parameter(Mandatory = $false)][string]$ServicePlan = "default",
9+
[Parameter(Mandatory = $false)][string]$ServiceInstanceName = "sampleNetworkShare"
1010
)
1111
$ErrorActionPreference = "Stop"
1212

@@ -17,12 +17,12 @@ $params = @{
1717
username = $UserName
1818
password = $Password
1919
}
20-
$ParamJSON = $params | ConvertTo-Json -Compress
20+
$jsonParams = $params | ConvertTo-Json -Compress
2121

2222
# Create a redacted copy of the parameters for logging so the password is not exposed
2323
$redactedParams = $params.Clone()
2424
$redactedParams['password'] = 'REDACTED'
25-
$ParamJSONRedacted = $redactedParams | ConvertTo-Json -Compress
25+
$redactedJsonParams = $redactedParams | ConvertTo-Json -Compress
2626

27-
Write-Host "cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $ParamJSONRedacted -t $ServiceInstanceName"
28-
cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $ParamJSON -t $ServiceInstanceName
27+
Write-Host "cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $redactedJsonParams -t $ServiceInstanceName"
28+
cf create-service $ServiceName $ServicePlan $ServiceInstanceName -c $jsonParams -t $ServiceInstanceName

FileShares/scripts/remove-user-and-share.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#Requires -Modules Microsoft.PowerShell.LocalAccounts, SmbShare
33

44
Param(
5-
[string]$ShareName = "steeltoe_network_share",
6-
[string]$SharePath = "c:\steeltoe_network_share",
7-
[string]$UserName = "shareWriteUser"
5+
[Parameter(Mandatory = $false)][string]$ShareName = "steeltoe_network_share",
6+
[Parameter(Mandatory = $false)][string]$SharePath = "c:\steeltoe_network_share",
7+
[Parameter(Mandatory = $false)][string]$UserName = "shareWriteUser"
88
)
99
$ErrorActionPreference = "Stop"
10+
1011
if ($PSVersionTable.PSVersion.Major -lt 6)
1112
{
1213
Write-Output "Running in Windows PowerShell (version < 6)"
@@ -17,6 +18,7 @@ else
1718
Add-Type -AssemblyName System.Management.Automation
1819
Import-Module Microsoft.PowerShell.LocalAccounts -SkipEditionCheck
1920
}
21+
2022
if (Get-SmbShare $ShareName -ErrorAction SilentlyContinue)
2123
{
2224
Remove-SmbShare -Name $ShareName

0 commit comments

Comments
 (0)