Skip to content

Add session materials: PimpYourPrameters and GitToGallery - MacInally#31

Open
LindnerBrewery wants to merge 1 commit into
devops-collective-inc:mainfrom
LindnerBrewery:main
Open

Add session materials: PimpYourPrameters and GitToGallery - MacInally#31
LindnerBrewery wants to merge 1 commit into
devops-collective-inc:mainfrom
LindnerBrewery:main

Conversation

@LindnerBrewery
Copy link
Copy Markdown

Added session materials

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds new session/demo materials for “Pimp Your Parameter Validation Classes” and “From Git to Gallery with Open Source” to the repository’s session-content structure.

Changes:

  • Added a PowerShell demo script showcasing custom ValidateArgumentsAttribute validators (ticket IDs, semver, safe paths, ports, and a combined completer/transformer/validator example).
  • Added a PowerShell demo script showcasing JSON Schema-based validation patterns (inline schema, schema file, schema URL, and combined “auto source” validator), plus schema file setup.
  • Added a D&D character JSON schema file and a short README pointing to the full external “Git to Gallery” repo.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 7 comments.

File Description
PimpYourParameterValidationClasses-MacInally/demo/validationClassesDemo_JsonSchema.ps1 Adds JSON Schema validation demo classes and example functions, including schema file setup.
PimpYourParameterValidationClasses-MacInally/demo/validationClassesDemo.ps1 Adds custom validation attribute demos (including safe path and port validation).
PimpYourParameterValidationClasses-MacInally/demo/character.schema.json Adds a sample JSON schema used by the demos.
FromGitToGalleryWithOpenSource-MacInally/readme.md Adds a brief readme with a link to the full demo environment repository.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[void] Validate([object]$arguments, [System.Management.Automation.EngineIntrinsics]$engineIntrinsics) {
# If something is wrong: throw an exception
# If everything is fine: do nothing (return void)
if ([datetime]$arguments -is [datetime] -and ([datetime]$arguments).DayOfWeek -eq 'Friday') {
Comment on lines +303 to +304

if (-not $resolvedPath.StartsWith($resolvedRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
Comment on lines +359 to +365
if ($port -lt 0 -or $port -gt 65535) {
throw "Port $port is out of range. Valid ports: 0-65535."
}

if ($port -le 1023 -and -not $this.AllowWellKnown) {
throw "Port $port is a well-known port (0-1023). Use ports 1024-65535 or explicitly allow well-known ports."
}
Comment on lines +387 to +398
function Test-Connection {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Hostname,

[Parameter()]
[ValidatePort($true)] # Allow well-known ports (80, 443, etc.)
[int]$Port = 443
)
"Testing connection to ${Hostname}:${Port}..."
}
Comment on lines +622 to +657
#region ---- Setup: Create Schema Files for File-Based Examples ----

# Run this region first to set up the schema files needed for Examples 3 and 5

$schemasDir = "$PSScriptRoot\schemas"
if (-not (Test-Path $schemasDir)) {
New-Item -Path $schemasDir -ItemType Directory -Force | Out-Null
}

# D&D Character schema (for Example 3)
@'
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "D&D Character",
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 2 },
"class": { "type": "string", "enum": ["Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"] },
"level": { "type": "integer", "minimum": 1, "maximum": 20 },
"race": { "type": "string" },
"stats": {
"type": "object",
"properties": {
"strength": { "type": "integer", "minimum": 1, "maximum": 30 },
"dexterity": { "type": "integer", "minimum": 1, "maximum": 30 },
"constitution": { "type": "integer", "minimum": 1, "maximum": 30 },
"intelligence": { "type": "integer", "minimum": 1, "maximum": 30 },
"wisdom": { "type": "integer", "minimum": 1, "maximum": 30 },
"charisma": { "type": "integer", "minimum": 1, "maximum": 30 }
},
"required": ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"]
}
},
"required": ["name", "class", "level", "race", "stats"]
}
'@ | Set-Content -Path "$schemasDir\character.schema.json" -Force
# It's a file path - read it
$schema = Get-Content -Path $this.SchemaSource -Raw -ErrorAction Stop
}
else {
Comment on lines +341 to +353
try {
$schema = (Invoke-WebRequest -Uri $this.SchemaUri -TimeoutSec $this.TimeoutSec -ErrorAction Stop).Content
}
catch {
throw "Failed to fetch schema from '$($this.SchemaUri)': $($_.Exception.Message)"
}

try {
$json | Test-Json -Schema $schema -ErrorAction Stop | Out-Null
}
catch {
throw "JSON does not match remote schema! $($_.Exception.Message)"
}
@HeyItsGilbert
Copy link
Copy Markdown
Contributor

@LindnerBrewery please update per copilots request and do a whole new session at Summit. Jk lol

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.

3 participants