Get the URL of a given v2 cloud function. Params: name: the function's name location: the function's location Returns: The URL of the function
(name: str, location: str = options.SupportedRegion.US_CENTRAL1)
| 125 | |
| 126 | |
| 127 | def get_function_url(name: str, location: str = options.SupportedRegion.US_CENTRAL1) -> str: |
| 128 | """Get the URL of a given v2 cloud function. |
| 129 | |
| 130 | Params: |
| 131 | name: the function's name |
| 132 | location: the function's location |
| 133 | |
| 134 | Returns: |
| 135 | The URL of the function |
| 136 | """ |
| 137 | credentials, project_id = google.auth.default( |
| 138 | scopes=["https://www.googleapis.com/auth/cloud-platform"] |
| 139 | ) |
| 140 | authed_session = google.auth.transport.requests.AuthorizedSession(credentials) |
| 141 | url = ( |
| 142 | "https://cloudfunctions.googleapis.com/v2beta/" |
| 143 | + f"projects/{project_id}/locations/{location}/functions/{name}" |
| 144 | ) |
| 145 | response = authed_session.get(url) |
| 146 | data = response.json() |
| 147 | function_url = data["serviceConfig"]["uri"] |
| 148 | return function_url |