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

refactor(cli): fixup + test aws-install SSH user #1009

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

nschmeller
Copy link
Contributor

This commit refactors and adds unit tests for the SSH username
assignment logic in the aws-install CLI subcommand.

Specifically, this commit:

  • Breaks down the AMI image name fetch and the lookup table code into
    helper functions
  • Adds unit tests for these helper functions
  • Enforces using the username passed as the --ssh_username CLI arg

Fixes RAIN-42812

Signed-off-by: nschmeller [email protected]

How did you test this change?

Added unit tests, ran integration tests from the agent repo

Issue

https://lacework.atlassian.net/browse/RAIN-42812

This commit refactors and adds unit tests for the SSH username
assignment logic in the `aws-install` CLI subcommand.

Specifically, this commit:
* Breaks down the AMI image name fetch and the lookup table code into
  helper functions
* Adds unit tests for these helper functions
* Enforces using the username passed as the `--ssh_username` CLI arg

Fixes RAIN-42812

Signed-off-by: nschmeller <[email protected]>
@nschmeller nschmeller self-assigned this Nov 8, 2022
// `LW_SSH_USER` in the shell environment.
func getSSHUsernameLookupTable() []func(string) (bool, string) {
return []func(string) (bool, string){
func(_ string) (bool, string) { return os.Getenv("LW_SSH_USER") != "", os.Getenv("LW_SSH_USER") }, // THIS ROW MUST BE FIRST IN THE TABLE
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be tempted to move the LW_SSH_USER check between lines 153 and 154. Otherwise it could be really easy to introduce a regression by reordering the elements in this array and/or adding a new AMI type before the LW_SSH_USER check.

Copy link
Contributor Author

@nschmeller nschmeller Nov 9, 2022

Choose a reason for hiding this comment

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

I'd agree, but we test those cases in a unit test. So I'd like to keep everything all neatly packaged up if possible

@nschmeller nschmeller merged commit d216771 into main Nov 9, 2022
@nschmeller nschmeller deleted the nick/refactor-aws-ssh-username-lookup branch November 9, 2022 21:55
@lacework-releng lacework-releng mentioned this pull request Nov 11, 2022
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.

2 participants