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

Allow overriding environment variable scope #15

Merged
merged 8 commits into from
Jul 13, 2018

Conversation

JeremySkinner
Copy link
Collaborator

Allows changing the environment variable scope from Process to User/Machine. Also updated Stop-SshAgent and Get-SshAgent to work with win32 openssh.

Copy link
Owner

@dahlbyk dahlbyk left a comment

Choose a reason for hiding this comment

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

I assume this is still WIP, since $Scope isn't actually used yet.

Changes so far look great!

@JeremySkinner
Copy link
Collaborator Author

Yes, I did commit the follow up but looks like I forgot to push it. Will do so when I'm back at my pc.

src/Agent.ps1 Outdated
[Parameter()]
[ValidateSet("Machine", "Process", "User")]
[string]
$Scope = "Process"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this parameter being used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is now! :) I forgot to commit the change

@JeremySkinner
Copy link
Collaborator Author

@dahlbyk @rkeithhill I've pushed up the missing change.

This doesn't change the environment variable scope for the calls to Get-TempEnv in the main module file, I don't think this is a big deal, but do we want to introduce a global variable to control this? My inclination would be no

@dahlbyk
Copy link
Owner

dahlbyk commented Jul 12, 2018

setenv doesn't understand your third parameter:

function setenv($key, $value) {
[void][Environment]::SetEnvironmentVariable($key, $value)
Set-TempEnv $key $value
}

This doesn't change the environment variable scope for the calls to Get-TempEnv in the main module file, I don't think this is a big deal, but do we want to introduce a global variable to control this? My inclination would be no

Get-TempEnv is already explicitly user-scoped rather than process-scoped, and it doesn't make sense for it to be machine-scoped, so I think this is fine. In fact, it doesn't seem useful or correct to allow Start-SshAgent -Scope Machine either, as this could leak the current user's credentials to another user. Am I missing a legitimate scenario for that?

@JeremySkinner
Copy link
Collaborator Author

@dahlbyk Good point, I'll remove the option for machine scope and leave just process/user.

Not sure why my change to setenv isn't showing up in the PR, it shows in my local repo. I'll force push it up.

@JeremySkinner JeremySkinner force-pushed the feature/environment-variable-scope branch from 6ca11cf to fa9df5f Compare July 12, 2018 13:51
@JeremySkinner JeremySkinner force-pushed the feature/environment-variable-scope branch from fa9df5f to 3c07600 Compare July 12, 2018 13:51
@JeremySkinner
Copy link
Collaborator Author

@dahlbyk force push seems to have done it, the changes are showing now and I've removed machine scope from the options list.

src/Utils.ps1 Outdated
$Scope = "Process"
)

$type = [System.EnvironmentVariableTarget]::Process
Copy link
Owner

Choose a reason for hiding this comment

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

I'm reasonably certain you can just pass $Scope directly to SetEnvironmentVariable() and PS will automatically cast for you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dahlbyk You're right. I've removed the conversion.

@dahlbyk dahlbyk merged commit 8a97b01 into master Jul 13, 2018
@dahlbyk dahlbyk deleted the feature/environment-variable-scope branch July 13, 2018 19:07
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