-
Notifications
You must be signed in to change notification settings - Fork 451
Adding GCE Metadata lib #10
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
Conversation
|
@dwsupplee Please take a look :) |
241b122 to
52b61b3
Compare
|
@dwsupplee Fixed the phpcs errors. |
52b61b3 to
b90c04d
Compare
|
@dwsupplee Sorry I broke the tests and now it passes. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
This looks pretty good at a glance... quick question, are Metadata values always strings? |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Made it an Exception. PTAL |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@bshaffer Thanks for the review! PTAL |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dwsupplee |
|
Awesome, thanks Takashi! I came up with a few questions after spending a little time playing around with these changes and familiarizing myself with compute engine metadata. I'm still a bit new and trying to learn the domain, so please forgive me if my questions are naive! :) Why do we feel this is a good fit for a stream wrapper?Traditionally I have seen stream wrappers used to decorate a request or to create a simple interface to read only specific bytes from a file. When dealing with potentially large files I could see an interface like this being a perfect fit. I immediately think of the storage api. Are there use cases for only needing to read specific portions of a metadata value? Would it make sense to create a device to let the user know this functionality is only supported if you are executing the code in a compute instance?Some of the other APIs in the lib are accessible anywhere and it seems like making the delineation clear would be important. Do we see this as compliment to or a replacement of a non stream wrapper implementation?I only see support for the 'attributes' metadata entry - is this the full scope of the wrapper or do we plan on implementing support for the other entries?Is there a way we could support a user needing to fetch all of their custom keys at once? |
$value = file_get_contents('gce-metadata://project/mykey');However, it can be a function like: $value = ComputeMetadata.get('project/mykey');
// or possibly
$value = ComputeMetadata.get('project/attributes/mykey');
// then we can support metadata other than user-specified
What do you mean by
I don't know there is any implementation.
That's a very good point. See the above example, which can support everything.
I think fetching Thanks for the thoughts. I started to think we can just provide a helper function(s). What do you think? |
|
I do like stream wrappers, but I'm a big fan of the something like the second approach for this use case. I didn't mean anything fancy by device, just some sort of layer that we could put in front of certain APIs to give a user a helpful message to let them know how to proceed using certain functionality. That may be out of the scope of this PR, though :).
You're correct - there isn't yet.
I really like this approach. Building out some friendly to use helper functions could really help wrap up this functionality well for us. I am still learning the compute engine api so the hierarchy/naming here may not make perfect sense, but just as simple example what do you think of a client that looks something like this? |
|
Ah sorry I intended to make the example static methods, but I made a mistake. The ComputeClient will have credentials (and related interfaces) for accessing the Compute Engine API. However, the Metadata is available from any Compute Engine instances, so I'd prefer just having helper functions (static methods), rather than having them in the Compute Engine API Client. How about to have use Google\Cloud\Compute\Metadata;
$val = Metadata::get('/project/attributes/mykey'); |
|
Gotcha, that makes sense! My only argument against using statics here is that it will make unit testing the app code consuming our client more difficult. I actually like one of the first statements you made about the stream wrapper,
I feel like with this approach we are losing part of this by requiring intimate knowledge of the paths in these docs. This approach is flexible, but requires more work for the user. Goal number 1 is a friendly, easy to use API. :) |
|
We can also provide some higher level functions like getProjectMetadata, getInstanceMetadata or something like them.
That's a very important point. Maybe I should make them instance methods? use Google\Cloud\Compute\Metadata;
$metadata = new Metadata();
// get project_id (possibly we can provide getProjectId or something because we can cache them)
$val = $metadata->get('/project/project-id');
// get custom metadata (no need for caching layer because they can be changed anytime)
$val = $metadata->getProjectMetadata('mykey');How does it sound? |
|
👍 very nice. |
8c6773d to
8e37d15
Compare
9be1b62 to
e9cdb95
Compare
e9cdb95 to
065a0ee
Compare
|
@dwsupplee |
src/Compute/Metadata.php
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@dwsupplee |
|
Looking pretty solid. Thanks for all the hard work Takashi 👍 |
|
Alright. I will wait for @bshaffer giving LGTM then I'll merge this. |
src/Compute/Metadata.php
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
1a1b3a9 to
6f807f4
Compare
|
@bshaffer PTAL |
|
The code and everything looks great! Just a few high-level questions:
|
This library will have dependency on google/auth, so users can just call
Alright, will add some comments. |
|
@bshaffer |
|
I see, so LGTM! 🎉 🎈 |
|
Thanks for the review both. Merging |
|
Oh, I don't have a power to merge. @dwsupplee Can you merge this? |
Fixes #8