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

Add platform uuid information. #270

Merged
merged 4 commits into from
Mar 27, 2018
Merged

Add platform uuid information. #270

merged 4 commits into from
Mar 27, 2018

Conversation

jquick
Copy link
Contributor

@jquick jquick commented Mar 16, 2018

This change adds a uuid option for platforms. This is either pulled from a unique identifier already on the box or by creating one. You also have the option of setting a command to run for a unique id during the platform detect block.

Currently how this is written is we will only run the UUID commands on demand when called upstream. This is to reduce the number of calls when detecting a OS.

Fixes #264

Signed-off-by: Jared Quick [email protected]

@jquick jquick requested a review from a team March 16, 2018 20:47
@jquick jquick force-pushed the jq/platform_uuid branch 3 times, most recently from 08aa444 to 1fcfdb0 Compare March 16, 2018 21:01
@jquick
Copy link
Contributor Author

jquick commented Mar 16, 2018

I think I’m going to move the logic to the detect helpers.

return uuid_from_string(result.stdout.chomp) if result.exit_status == 0 && !result.stdout.empty?
end

raise 'Could not fine platform uuid! please set a uuid_command for your platform'
Copy link

@TrevorBramble TrevorBramble Mar 17, 2018

Choose a reason for hiding this comment

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

s/fine/find/ =^)

Addendum: Also, in the second sentence, capitalize "please", please, and punctuate.

end

def azure
# use subscription_id or tenant_id

Choose a reason for hiding this comment

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

Redundant comment, yeah? Also the kind that becomes a lie when the implementation changes.

windows
elsif @platform.name == 'aws'
aws
elsif @platform.name == 'azure'

Choose a reason for hiding this comment

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

Why aren't there predicate methods for aws and azure already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

due to ? only getting created for platform families. I have been thinking about this and I will wrap aws/azure in their own families so we get them.

Choose a reason for hiding this comment

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

Gotcha. Yeah it'd be great to have the uniform api. Then the case statement could be collapsed. =^)

raise "Cannot write uuid to `#{local_uuid_path}\\machine-uuid`" if result.exit_status !=0
end
uuid
end

Choose a reason for hiding this comment

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

I see about 5 methods lurking inside this one. Is that sort of abstraction unconventional in this project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah at this point they should be divided up as sub private methods. Thanks for this, ill grab it when I move them over.

@jquick jquick force-pushed the jq/platform_uuid branch 3 times, most recently from ac9ac65 to b4c06f7 Compare March 19, 2018 15:20
Copy link
Contributor

@jerryaldrichiii jerryaldrichiii left a comment

Choose a reason for hiding this comment

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

Looks great @jquick! I like how you moved the logic around.

I only have a few nitpicks then this will be good to go. Also, I didn't mention it because it's not a big deal, but if you could rewrite your it blocks to read as a sentence that would make me 😄 e.g. it 'returns an account id'

return uuid_from_string(result.stdout.chomp) if result.exit_status == 0 && !result.stdout.empty?
end

raise 'Could not fine platform uuid! please set a uuid_command for your platform'
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we capitalize please

# fallback to user location
warn 'Cannot write uuid to `/etc/machine-uuid`, falling back to ~/.local/etc/machine-uuid instead.'
result = @backend.run_command("mkdir -p #{ENV['HOME']}/.local/etc; echo \"#{uuid}\" > #{ENV['HOME']}/.local/etc/machine-uuid")
raise 'Cannot write uuid to `~/.local/etc/machine-uuid`.' unless result.exit_status.zero?
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we surround /etc/machine-uuid with backticks, can we do the same for ~/.local/etc/machine-uuid as well? Also, can we interpolate this in some way so that the home directory is expanded and shown to the user?

uuid_from_string(result.stdout.chomp) if result.exit_status.zero? && !result.stdout.empty?
end

def uuid_from_string(string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a few comments explaining the conversion here?

unless result.exit_status.zero?
# fallback to user location
local_uuid_path = "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}\\.system\\machine-uuid"
warn "Cannot write uuid to `#{ENV['SYSTEMROOT']}\\machine-uuid`, falling back to #{local_uuid_path} instead."
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we surround #{local_uuid_path} with backticks?

@jquick jquick force-pushed the jq/platform_uuid branch 3 times, most recently from 63f5c0c to 40ac05d Compare March 19, 2018 16:02
@jquick jquick force-pushed the jq/platform_uuid branch from 40ac05d to 3828ed7 Compare March 19, 2018 16:04
Copy link
Contributor

@jerryaldrichiii jerryaldrichiii left a comment

Choose a reason for hiding this comment

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

You did the thing with the it blocks! Day = Made.

Thanks @jquick

@jquick
Copy link
Contributor Author

jquick commented Mar 20, 2018

Do not merge yet, need to add the new https://github.com/chef/chef/pull/7016/files chef_guid

@jquick
Copy link
Contributor Author

jquick commented Mar 21, 2018

Added, should be good to go!

@jquick jquick force-pushed the jq/platform_uuid branch 2 times, most recently from 9f2c5ff to 1c2df9c Compare March 26, 2018 19:53
@jquick jquick force-pushed the jq/platform_uuid branch from 1c2df9c to 1479962 Compare March 26, 2018 20:51
Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @jquick for this great feature. I like that we focus on read-only mechanisms.

@chris-rock chris-rock merged commit 16f70fc into master Mar 27, 2018
@chris-rock chris-rock deleted the jq/platform_uuid branch March 27, 2018 09:51
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.

5 participants