Skip to content
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

(#240) Parameterize setup #284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

steviecoaster
Copy link
Contributor

@steviecoaster steviecoaster commented Dec 4, 2024

Description Of Changes

Adds parameterization to both ClientSetup.ps1 and Register-C4bEndpoint.ps1 to allow an end user to customize the installation of Chocolatey For Business on an endpoint.

Motivation and Context

An opinionated approach is nice, but allowing some level of customization that is easy for the end user is a nice added touch to really improve the overall experience with our tooling.

Testing

  1. Manually tested changes in a lab environment locally

Operating Systems Testing

  • Windows Server 2019

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v3 compatibility checked?

Related Issue

Fixes #240

@steviecoaster steviecoaster force-pushed the gh240 branch 3 times, most recently from c2d1bb6 to 78f53cf Compare December 4, 2024 18:33
@steviecoaster steviecoaster requested review from JPRuskin and ryanrichter94 and removed request for JPRuskin December 4, 2024 18:33
@steviecoaster steviecoaster force-pushed the gh240 branch 2 times, most recently from c1f8e77 to 86402af Compare December 11, 2024 01:58
This script adds parameterization to the ClientSetup.ps1 script that is
hosted within the Nexus repository. It also adds parameterization to the
registration script that is executed on a client so you can customize the
installation.
Copy link
Member

@JPRuskin JPRuskin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of single-character variables that I think could be expanded to have helpful names, to ease legibility and maintainability in the future, but I haven't made suggestions as they generally spanned a fair number of lines and got muddled with other comments.

$ProxyCredential,

#Install the Chocolatey Licensed Extension with right-click context menus available
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Install the Chocolatey Licensed Extension with right-click context menus available
# Install the Chocolatey Licensed Extension with right-click context menus available.

Matching the format of the other param comments.



Write-Host "Applying user supplied configuration" -ForegroundColor Cyan
#How we call choco from here changes as we need to be more dynamic with thingsii .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#How we call choco from here changes as we need to be more dynamic with thingsii .
# How we call choco from here changes as we need to be more dynamic with things.

@@ -158,3 +187,128 @@ if ($ServiceSalt) {
}
choco feature enable --name="'useChocolateyCentralManagement'"
choco feature enable --name="'useChocolateyCentralManagementDeployments'"


Write-Host "Applying user supplied configuration" -ForegroundColor Cyan
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Write-Host "Applying user supplied configuration" -ForegroundColor Cyan
if ($AdditionalConfiguration -or $AdditionalFeatures -or $AdditionalSources -or AdditionalPackages) {
Write-Host "Applying user supplied configuration" -ForegroundColor Cyan
}

$package.ContainsKey('Pin') { $c.Add('--pin') }
}

#Ensure packages install and they don't flood the console output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Ensure packages install and they don't flood the console output
# Ensure packages install and they don't flood the console output


$PSBoundParameters.ContainsKey('IncludePackageTools') {
$params.Add('IncludePackageTools',$IncludePackageTools)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$params.Add('IncludePackageTools',$IncludePackageTools)
$params.Add('IncludePackageTools', $IncludePackageTools)

#>
Foreach ($a in $AdditionalSources) {
$c = [System.Collections.Generic.List[string]]::new()
#Required items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Required items
# Required items

CertificatePassword = 's0mepa$$'
}
#>
Foreach ($a in $AdditionalSources) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Foreach ($a in $AdditionalSources) {
foreach ($a in $AdditionalSources) {

choco source add --name="'ChocolateyInternal'" --source="'$RepositoryUrl'" --allow-self-service --priority=1
}

#Environment base Source configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Environment base Source configuration
# Environment base source configuration

Comment on lines +98 to +124
Credential = $RepositoryCredential
ClientSalt = $ClientCommunicationSalt
ServiceSalt = $ServiceCommunicationSalt
RepositoryUrl = $RepositoryUrl
}

switch ($true) {
$PSBoundParameters.ContainsKey('AdditionalConfiguration') {
$params.Add('AdditionalConfiguration', $AdditionalConfiguration)
}
$PSBoundParameters.ContainsKey('AdditionalFeatures') {
$params.add('AdditionalFeatures', $AdditionalFeatures)
}

$PSBoundParameters.ContainsKey('AdditionalPackages') {
$params.Add('AdditionalPackages', $AdditionalPackages)
}

$PSBoundParameters.ContainsKey('AdditionalSources') {
$params.Add('AdditionalSources', $AdditionalSources)
}

$PSBoundParameters.ContainsKey('IncludePackageTools') {
$params.Add('IncludePackageTools', $IncludePackageTools)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of all this, given we control the params, is it worth literally just parsing and passing PSBoundParams? I think the only thing that would need changing is FQDN/RepositoryUrl.

Suggested change
$params = @{
Credential = $RepositoryCredential
ClientSalt = $ClientCommunicationSalt
ServiceSalt = $ServiceCommunicationSalt
RepositoryUrl = $RepositoryUrl
}
switch ($true) {
$PSBoundParameters.ContainsKey('AdditionalConfiguration') {
$params.Add('AdditionalConfiguration', $AdditionalConfiguration)
}
$PSBoundParameters.ContainsKey('AdditionalFeatures') {
$params.add('AdditionalFeatures', $AdditionalFeatures)
}
$PSBoundParameters.ContainsKey('AdditionalPackages') {
$params.Add('AdditionalPackages', $AdditionalPackages)
}
$PSBoundParameters.ContainsKey('AdditionalSources') {
$params.Add('AdditionalSources', $AdditionalSources)
}
$PSBoundParameters.ContainsKey('IncludePackageTools') {
$params.Add('IncludePackageTools', $IncludePackageTools)
}
}
$params = $PSBoundParameters
foreach ($Parameter in @("FQDN", "TrustCertificate")) {
$null = $params.Remove($Parameter)
}
$params += @{
RepositoryUrl = $RepositoryUrl
}

Please note, I've not tested this (and there's probably more properties to nuke), but it seems like there's less code to maintain with this approach.

$c.Add("--name='$($a.Name)'")
$c.Add("--source='$($a.Source)'")

#Add credentials if source has them
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#Add credentials if source has them
# Add credentials if source has them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClientSetup Enhancements - Parameterize script to allow for additional flexibility
2 participants