最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google cloud platform - How to get access to service account private key for PreSigned URLS? - Stack Overflow

programmeradmin1浏览0评论

Keep getting "An error occurred: you need a private key to sign credentials.the credentials you are currently using <class 'google.authpute_engine.credentials.Credentials'> just contains a token"

I'm Trying to get Presigned URL so that it can be downloaded by app(for user profile) It works fine in my local since I have key path to the service account json key.

In cloud run I've tried secret manager but it didn't work, since instead of file it shows the value of the key itself.

bucket_name = os.environ.get("BUCKET_NAME")
service_account = os.environ.get("SERVICE_ACCOUNT")
credentials = compute_engine.Credentials()
project_id = os.environ.get("PROJECT_ID")

def get_bucket(bucket_name):
    client = storage.Client(credentials=credentials, project=project_id)
    bucket = client.get_bucket(bucket_name)
    return bucket

def generate_presigned_url_for_profile(blob_name, expiration=3600):
    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(f"userProfile/{blob_name}")
    url = blob.generate_signed_url(version="v4", expiration=datetime.timedelta(seconds=expiration), method='GET', service_account_email=service_account)
    return url

I've tried using compute.engine.Credentials() and it didn't work

发布评论

评论列表(0)

  1. 暂无评论