7

appengine API を使用して Google Cloud Storage オブジェクト (またはバケット) の ACL を変更することは可能ですか? これは REST API を使用して実行できることは理解していますが、appengine の Files API ではこれがサポートされていますか? これらは、GSFileObject を使用して新しいオブジェクトを作成するときに設定できますが、既存のオブジェクトを変更できますか??

4

2 に答える 2

9

urlfetch.fetchapp_identity.get_access_tokenを使用して、認証済みのリクエストを REST APIに簡単に送信できます。

パイソン:

from google.appengine.api import app_identity
from google.appengine.api import urlfetch

acl_xml = """
<AccessControlList><Entries>
  <Entry>
    <Scope type="UserByEmail">foo@example.com</Scope>
    <Permission>READ</Permission>
  </Entry>
</Entries></AccessControlList>
"""
scope = 'https://www.googleapis.com/auth/devstorage.full_control'
token = app_identity.get_access_token(scope)
response = urlfetch.fetch(
    'http://storage.googleapis.com/bucket/obj?acl',
    method=urlfetch.PUT,
    payload=acl_xml,
    headers={'Authorization': 'OAuth %s' % token})

ジャワ:

import com.google.appengine.api.appidentity.AppIdentityService;    
import com.google.appengine.api.appidentity.AppIdentityServiceFactory;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public String setAcl() throws Exception {
  // Change foo@example.com to a valid email.
  // Repeat <Entry/> as many times as necessary.
  String xmlString = "";
  xmlString += "<AccessControlList><Entries>";
  xmlString += "  <Entry>";
  xmlString += "    <Scope type=\"UserByEmail\">foo@example.com</Scope>";
  xmlString += "    <Permission>READ</Permission>";
  xmlString += "  </Entry>";
  xmlString += "</Entries></AccessControlList>";

  ArrayList scopes = new ArrayList();
  scopes.add("https://www.googleapis.com/auth/devstorage.full_control");

  AppIdentityService.GetAccessTokenResult accessToken =
      AppIdentityServiceFactory.getAppIdentityService().getAccessToken(scopes);

  // Change bucket and obj to the bucket and object of interest.
  URL url = new URL("https://storage.googleapis.com/bucket/obj?acl");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setDoOutput(true);
  connection.setRequestMethod("PUT");
  connection.addRequestProperty(
      "Authorization", "OAuth " + accessToken.getAccessToken());

  OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
  writer.write(xmlString);
  writer.close();

  if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
    throw new Exception();
  }
}

より詳しい情報:

于 2012-11-29T00:00:16.247 に答える
1

既存のオブジェクトの ACL を変更することは、App Engine の Google Cloud Storage API ではサポートされていませんが、その機能を追加するよう求める機能リクエストを作成しました。

于 2012-11-28T23:58:45.627 に答える