GoogleCloudPlatform / GoogleCloudPlatform/cloud-sql-python-connector

Make user optional when passing enable_iam_auth

未关闭
#310 2 条评论 2 个 reaction 已指派 1 人 已指派给 @hessjcg 在 GitHub 查看
priority: p2 type: feature request
主要语言
Python
星标
344
派生
89
平均合并
5 小时 33 分钟
30 天内合并 PR
2

描述

## Feature Description

If I'm using this in an environment like cloud run, there really only is one account - the currently active service account. I think the default assumption is that the user that is going to be doing the proxying is also the one that is being logged in, so it's quite redundant to have to get the current service account, and then chop off the `gserviceaccount.com` as required.

A cleaner API would be to simply no longer have user required when enable_iam_auth is passed, and have the connector correctly detect service account emails and appropriately chop them, cleanly abstracting away the internals.

That would take the common use case from
```
account = detect_account()
if account.endswith(".iam.gserviceaccount.com"):
account = account.replace(".gserviceaccount.com", "")
connector.connect(MY_DB_STR, "pg8000", user=account, db=MY_DB, enable_iam_auth=True)
```
to the extremely elegant `connector.connect(MY_DB_STR, "pg8000", db=MY_DB, enable_iam_auth=True)`

## Alternatives Considered
We could continue to keep this redundant, but it's forcing the calling code to still be dealing with GCP internals.

Thank you for your consideration :P

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。