Closed devblackops closed 6 years ago
Good catch - That works for me!
Great to see others interested in PSCore!
Serialization of SecureStrings (Token
and Uri
in Get-
and Set-PSSlackConfig
) will also need to be addressed to get PSSlack fully working on macOS/Linux, as that functionality/DPAPI isn't currently supported on non-Windows platforms (PowerShell/PowerShell#1654).
Simplest solution would to be store Token
and Uri
in plain text on macOS/Linux, and rely on file permissions to limit access.
As an aside, PowerShell Core Docker image is missing $env:TEMP
/TMPDIR
and $env:USER
/USERNAME
.
PS /> (Get-ChildItem env:).Name
HOME
HOSTNAME
LANG
LC_ALL
PATH
PSModulePath
TERM
It may be worth taking a cue from PSCore here, and use $env:USERPROFILE
(although I feel $env:APPDATA
might be more appropriate) on Windows and $env:HOME
on other platforms.
It may also be worth considering changing the config name to PSSlack.xml
(or the more *nix-y .psslack
) on non-Windows platforms -- without DPAPI preventing decryption of Token
s and Uri
s generated on different hosts or by different users, the <user>-<host>-
prefix doesn't make much sense.
Thoughts?
Hiyo!
Good catch - yeah, I'd agree on the naming convention and using a dot file - if we did serialize secrets to disk, I'd probably prefer to require some sort of ack switch (i.e. not default, make it explicitly clear what is happening), e.g. -SaveSecretsToDisk
that's only applicable on the *nix side (implementation of that might be odd)
So how about these two options to calculate the psslack.xml path?
if (($PSEdition -eq 'Desktop') -or (Test-Path -Path 'Variable:\IsWindows')) {
$_PSSlackXmlpath = Join-Path -Path $env:TEMP -ChildPath "$env:USERNAME-$env:COMPUTERNAME-PSSlack.xml"
} else {
$_PSSlackXmlpath = Join-Path -Path $home -ChildPath '.psslack.xml'
}
or
$_PSSlackXmlpath = Join-Path -Path $home -ChildPath '.psslack.xml'
I would lean towards the former to keep the existing behavior for Windows PowerShell unless you're cool with a breaking change.
I think the first makes most sense to maintain compatibility, but -- as mentioned above -- think $env:APPDATA/psslack.xml
makes a lot more sense.
If someone really needs to the USERNAME-COMPUTERNAME-prefix format because of DPAPI, then that functionality is still available by calling Get-
/Set-PSSlackConfig
explicitly with the old path.
function Test-IsWindows
{
[CmdletBinding()]
[OutputType([bool])]
param()
end
{
!(Test-Path -Path Variable:\IsWindows) -or $IsWindows
}
}
function Get-PSSlackConfigPath
{
[CmdletBinding()]
param()
end
{
if (Test-IsWindows)
{
Join-Path -Path $env:TEMP -ChildPath "$env:USERNAME-$env:COMPUTERNAME-PSSlack.xml"
}
else
{
Join-Path -Path $env:HOME -ChildPath '.psslack' # Leading . and no file extension to be Unixy.
}
}
}
I was contemplating rolling these out as functions for easier testing/mocking/extension/re-use.
Anyway, let me know if you plan on working on this, and I'll be happy to find another issues. Or hit me up in Slack and maybe we can submit a PR together?
It's all yours @kanjibates 😄
FYI, In Jakul's Configuration
module he went with $env:LocalAppData
and $home/.config/
for Windows and Linux/macOS respectively to fix a similar issue in commit https://github.com/PoshCode/Configuration/commit/212e38ef13cab2f151a0517f6f13f2c0deb2a8a2
Greeting Starfighter!
There appear to be a few environment variable related things that prevent PSSlack from working fully on macOS/Linux.
Specifically, these don't exist in PWSH on macOS:
$env:TEMP
,$env:USERNAME
,$env:COMPUTERNAME
Here is what is available on my machine:
I ran into some similar issues with PoshBot when testing on macOS and decided to perform some logic in the PSM1 and come up with my own variables for use by the various functions.
Perhaps PSSlack will need the same and use
$env:TMPDIR
and$env:USER
in place of$env:TEMP
and$env:USERNAME
.$env:COMPUTERNAME
could be replaced with the value from thehostname
command.What do you think?