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

Connect-AtwsWebAPI - Intermittent errors when running in Azure Function (using secret ENV: variables) #118

Closed
TwiggyDev opened this issue Oct 26, 2022 · 2 comments

Comments

@TwiggyDev
Copy link

I found that Connect-AtwsWebAPI.ps1 had a nice little secret logic flow that looks for Environment Variables of interest when running in an Azure Function; something that I have been leveraging with a serverless automation system I've been developing for my workplace.

However, I have intermittently been running into an issue, where it seems that the AutoTask connection needs to be re-established, so "Get-ATWSData" (or an equivalent CMDlet) calls Connect-AtwsWebAPI without any parameters; this seems to follow the DefaultParameterSet of 'ConfigurationFile'

The error is thrown as a result of the $ProfilePath using the 'Join-Path' CMDlet, with the generic error: "Path" cannot be bound because it is null

[Parameter( ParameterSetName = 'ConfigurationFile' )] [ArgumentCompleter( { param($Cmd, $Param, $Word, $Ast, $FakeBound) $(Get-ChildItem -Path $Global:AtwsModuleConfigurationPath -Filter "*.clixml").FullName })] [ValidateScript( { Test-Path $_ })] [Alias('Path')] [IO.FileInfo] # The path to an alternate clixml file with connection profiles $ProfilePath = $(Join-Path -Path $Global:AtwsModuleConfigurationPath -ChildPath AtwsConfig.clixml)

I have been able to get around this issue by editing the DefaultParameterSet to one I defined, which doesn't actually take any relevant variables - allowing the command to go through, reach the "$ENV:FUNCTIONS_WORKER_RUNTIME" clause, and then obtain the Environment variables I set from there.

Is it possible to get a new Parameter Set that is targeted for official Azure Function use? Otherwise, could the assignment of $profilePath occur in the $PSCmdlet.ParameterSetName clause for 'ConfigurationFile' instead? Either solution should work.

@klemmestad
Copy link
Member

Hi @TwiggyDev, this seems to be faulty logic at my part. Also, I am being unecessarily "clever" by setting the default value of ProfilePath in the parameter definition when there exist cases where the configuration path will not be set. So in the update I intend to post today I have moved the join-path command to the section where the code has established that it will indeed use a saved profile to connect, hopefully solving this issue permanently.

klemmestad pushed a commit that referenced this issue Feb 10, 2023
klemmestad pushed a commit that referenced this issue Feb 10, 2023
…hen running in Azure Function (using secret ENV: variables) #118
@klemmestad
Copy link
Member

Module have been updated with a fix for this and updated to API version 1.6.11.

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

No branches or pull requests

2 participants