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

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

Merged
merged 4 commits into from
Aug 22, 2023

Conversation

bshaffer
Copy link
Contributor

@bshaffer bshaffer commented Aug 15, 2023

Copy link

@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 a review from a team as a code owner August 17, 2023 10:39
@bshaffer bshaffer requested a review from noahdietz August 17, 2023 10:39
{
if (file_exists($productNameFile)) {
$productName = trim((string) file_get_contents($productNameFile));
return 0 === strpos($productName, 'Google');
Copy link
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
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?

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
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

src/Credentials/GCECredentials.php Show resolved Hide resolved
{
if (file_exists($productNameFile)) {
$productName = trim((string) file_get_contents($productNameFile));
return 0 === strpos($productName, 'Google');

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