错误401从Cloud Endpoint调用托管在Cloud Storage上的静态HTML

问题描述 投票:0回答:1

调用托管在Cloud Storage存储桶中的静态HTML页面时,我收到401错误。

云存储桶被配置为公共。

该呼叫是从我的Cloud Endpoint完成的,如下所示:

/my-web-page:
      get:
        summary: call my web page
        operationId: my-web-page
        x-google-allow: all
        x-google-backend:
          address: https://storage.googleapis.com/MY-PROJECT/[MY-BUCKET]/[MY-OBJECT]
        responses:
          '200':
            description: A successful response
            schema:
              type: string 

云运行日志:

XX.XXX.XXX.XXX - "GET https://[MY-CLOUD-ENDPOINT-SERVICE].a.run.app/my-web-page" **401** 804 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"
Expand all | Collapse all{
 httpRequest: {
  latency: "2.377394394s"   
  protocol: "HTTP/1.1"   
  remoteIp: "XXXXX"   
  requestMethod: "GET"   
  requestSize: "693"   
  requestUrl: "https://[MY-CLOUD-ENDPOINT-SERVICE].a.run.app/storage"   
  responseSize: "804"   
  serverIp: "XXXXXXX"   
  status: 401   
  userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763"   
 }
 insertId: "5ddef2f900077a8473972018"  
 labels: {…}  
 logName: "projects/[MY-GCP-PROJECT]/logs/run.googleapis.com%2Frequests"  
 receiveTimestamp: "2019-11-27T22:04:41.498296805Z"  
 resource: {
  labels: {
   configuration_name: "XXXXX"    
   location: "us-central1"    
   project_id: "XXXXX"    
   revision_name: "XXXX"    
   service_name: "XXXX"    
  }
  type: "cloud_run_revision"   
 }
 severity: "WARNING"  
 timestamp: "2019-11-27T22:04:41.490116Z"  
 trace: "projects/XXXXXX/traces/aed367cb2b64bf00c215f8b19dff446b"  
}

有什么想法吗?

google-cloud-platform google-cloud-storage google-cloud-endpoints google-cloud-run terraform-provider-gcp
1个回答
0
投票

[您正在使用端点的使用向Cloud Storage API发出请求时,我相信您应该改用以下地址:

https://storage.googleapis.com/storage/v1/[PATH_TO_RESOURCE]

由于端点很可能向API发出JSON请求,因此文档中的此link对您有用。

编辑:

我终于设法通过以下端点配置使其与您的相同设置一起使用:

/hello:
  get:
    summary: hello
    operationId: GetImage
    x-google-backend:
      #address: https://storage.googleapis.com/[MY-BUCKET]/[MY-OBJECT]
      address: https://storage.cloud.google.com/[MY-BUCKET]/[MY-OBJECT]
    responses:
      '200':
        description: hello
        schema:
          type: object

具有此设置的事情是,该文件将改为从storage.cloud.google.com提供,因此用户将被重定向到apidata.googleusercontent.com。我认为它不能与googleapis.com一起使用,因为Endpoints并不意味着要调用其他API,然后可以调用storage.google.com URL。

© www.soinside.com 2019 - 2024. All rights reserved.