I got this psydo code
switch ([System.Environment]::OSVersion.Platform) {
'Unix' {
$BaseUrl='http://<myhomeserver>:8282/masking/api/'
$RulesXMLFile='E:/Delphix/Masking/Rules.xml'
$UserName=<MyHomeUser>
$Password=<MyHomePassWord>
} default {
$BaseUrl='http://<company server>:8282/masking/api'
$RulesXMLFile='//Volumes/home/PowerShell/Delphix/Masking/Rules.xml'
$UserName=<MyCompanyUser>
$Password=<MyCompanyPassWord>
}
}
$Header = @{
“Accept”=“application/json”
“connectapitoken”=“97fe6ab5b1a640909551e36a071ce9ed”
“Content-Type”=“application/json”
}
Function New-Login {
$Authorization=Invoke-WebRequest-Uri “$($BaseURL)/login”-Method POST -Headers $Header-Body $Jason
$Header.Add(“Authorization”, ($Authorization|Select-Object-ExpandProperty Content |ConvertFrom-Json).Authorization)
Write-Output ($Authorization|Select-Object-ExpandProperty Content |ConvertFrom-Json).Authorization
}
Function Get-Environments {
Param (
[parameter(Mandatory = $False,
ValueFromPipeline=$true,
ValueFromPipelineBypropertyName=$true)]
[String]$EnvironmentID
)
Begin {}
process {
$url=“$($BaseURL)/environments”
$res=Invoke-RestMethod-Uri $url-Method GET -Headers $header
Write-Output$res
}
End {}
}
Function Get-FileRuleSet {
Param(
[parameter(Mandatory = $True,
ValueFromPipeline=$true,
ValueFromPipelineBypropertyName=$true)]
[Int]$EnvironmentID
)
Begin {}
Process {
$url=“$($Script:BaseURL)/file-rulesets?environment_id=$($EnvironmentID)”
Invoke-RestMethod-Uri $url-Method GET -Headers $Header|ForEach-Object {
$.responseList | ForEach-Object {
$properties=@{
FileRulesetId= $.fileRulesetId
rulesetName= $.rulesetName
fileConnectorId= $.fileConnectorId
}
$Obj=New-Object-TypeName PSObject -Property $properties
Write-Output$obj
}
}
}
End {}
}
if (New-Login) {
Get-Environments|Get-FileRuleSet
}
I have some var there is shared between the functions (and the next 15-20 functions),
is there a smarter or more beautiful way to do it?
Or do I do it the right and only way?
You can say, that normally a function has some input, and some output (an object),
nothing comes into the function from the sides, but you can say, in this case it does (its not defined as input parameter)
If i save this as a module, then i will have a module with some functions, and some global variables,
would you do it the same way?