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

Export CloudMetadata? #123

Open
simolus3 opened this issue Dec 20, 2020 · 8 comments
Open

Export CloudMetadata? #123

simolus3 opened this issue Dec 20, 2020 · 8 comments
Labels
kind/enhancement New feature or request

Comments

@simolus3
Copy link

I'm trying to access other Google Cloud Services in Cloud Run, so I need to know my project id at runtime. For now I'm just getting it via an environment variable, but since this package can already look it up from the metadata server I wonder if CloudMetadata.projectId() could be exported?

@kevmoo kevmoo added the kind/enhancement New feature or request label Dec 20, 2020
@kevmoo
Copy link
Collaborator

kevmoo commented Dec 20, 2020

Interesting idea! We can look into it!

@simolus3
Copy link
Author

Thank you! I was already using obtainAccessCredentialsViaMetadataServer, seems like I overlooked clientViaMetadataServer.

Do you know if there's a way to extract the project id from the client? I still need to know the id to construct, for instance, a Storage from package:gcloud.

@subfuzion
Copy link
Member

subfuzion commented Dec 20, 2020

@simolus3 We were just discussing / brainstorming approaches to making functions projects cloud project-aware last week, actually, and make it easy to wire up and consume other GC services from the function. Multiple ways to skin the cat, I think, but I've been looking at this from the perspective of having some kind of project config (potentially checking for a gcloud config) at build time to configure the deployment while the framework makes it dead simple to get what's needed for function app from the environment (whether accessed as library calls or supplied via a context argument).

@simolus3
Copy link
Author

This is a bit more than I asked for here, but I had a rather simple idea on how to provide cloud services without much effort: Maybe this package can integrate with package:gcloud and invoke functions in a service scope that provides all the high-level services and an authenticated client for those that are auto-generated.
For me, this includes using a metadata server in the managed runtime and respecting the GOOGLE_APPLICATION_CREDENTIALS environment variable for local testing, as described in the Cloud Run docs on testing.

I think that this would be a pretty neat developer experience where everything "just works" and I don't have to manually pass some context variable around. I'm happy to work on a PR if you think this is a direction worth exploring.

@subfuzion
Copy link
Member

@simolus3 The service scope idea is pretty neat. You're always welcome to prototype ideas and contribute to the project, but I know that @kevmoo has been putting a lot of thought into this, so I'd want for him to weigh in on implementation first (this is a light week for us and he's enjoying some family time). But having your input on the desired developer experience as we all put our heads together on this really helps. Thanks!

@subfuzion
Copy link
Member

Also, since I think my comment wasn't quite so clear, let me clarify that regardless of the metadata that can be consumed from the environment at runtime for use by your function, you still have to specify what cloud project you want to deploy into -- this is where the function project configuration that I'm talking about comes in.

Currently, we require that you install and configure gcloud (see the repo docs). I'm thinking that we could probably hide this step from users, while still respecting the gcloud configuration, if there is one.

@subfuzion
Copy link
Member

subfuzion commented Dec 21, 2020

@simolus3 I'm prototyping a mini-CLI to make working with a Dart Functions Framework project easy. Imagine a deploy command that accepts a --project ID argument, but if not supplied, also checks the active gcloud configuration and possibly a hypothetical project-local configuration, like this:

.function.yaml

project: demo-project
region: us-central1
runtime: gcf  # or cloudrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants