Skip to content

feat: check product name file on linux for gce#469

Merged
bshaffer merged 4 commits intomainfrom
check-product-name-file-on-gce
Aug 22, 2023
Merged

feat: check product name file on linux for gce#469
bshaffer merged 4 commits intomainfrom
check-product-name-file-on-gce

Conversation

@bshaffer
Copy link
Copy Markdown
Contributor

@bshaffer bshaffer commented Aug 15, 2023

Copy link
Copy Markdown

@TimurSadykov TimurSadykov left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@bshaffer bshaffer marked this pull request as ready for review August 17, 2023 10:39
@bshaffer bshaffer requested review from a team and noahdietz August 17, 2023 10:39
{
if (file_exists($productNameFile)) {
$productName = trim((string) file_get_contents($productNameFile));
return 0 === strpos($productName, 'Google');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe lowercase is better?

Suggested change
return 0 === strpos($productName, 'Google');
return 0 === strpos($productName, 'google');

Copy link
Copy Markdown
Contributor Author

@bshaffer bshaffer Aug 22, 2023

Choose a reason for hiding this comment

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

The is determined by the Operating system, and the string is uppercase (literally, Google). So making it lowercase would fail the check.

Why do you think lowercase is better?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

My only question is: Should we normalize the contents (e.g. force lowercase) in order to avoid any sort of subtle issues with string matching/discrepancies in this file's contents?

Copy link
Copy Markdown
Contributor Author

@bshaffer bshaffer Aug 22, 2023

Choose a reason for hiding this comment

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

The Product Name is either Google or Google Compute Engine. The lowercase name google is not valid (or at least, there are no known Operating Systems which use that). So there's no reason to add a check for the lowercase value.

To my knowledge, other language implementations have not included such a normalization

{
if (file_exists($productNameFile)) {
$productName = trim((string) file_get_contents($productNameFile));
return 0 === strpos($productName, 'Google');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

My only question is: Should we normalize the contents (e.g. force lowercase) in order to avoid any sort of subtle issues with string matching/discrepancies in this file's contents?

@bshaffer bshaffer merged commit 3c672f9 into main Aug 22, 2023
@bshaffer bshaffer deleted the check-product-name-file-on-gce branch August 22, 2023 17:06
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.

4 participants