def create(self, scopes): # pragma: no cover # This import doesn't work outside appengine, so delay it until it's used. from oauth2client import appengine from google.appengine.api import app_identity logging.info('Initializing with service account %s', app_identity.get_service_account_name()) return appengine.AppAssertionCredentials(scopes)
def create(self, scopes): # pragma: no cover # This import doesn't work outside appengine, so delay it until it's used. try: # pragma: no cover from oauth2client import appengine except ImportError: # pragma: no cover # Try oauth2client 3.0.0 location. from oauth2client.contrib import appengine return appengine.AppAssertionCredentials(scopes)
def HttpFromServiceAccount(scope): """Prepare HTTP authenticated by the application's service account. Args: scope: Desired service API scope. Returns: Authenticated HTTP object. """ credentials = oauth_appengine.AppAssertionCredentials(scope) return credentials.authorize(http=httplib2.Http(memcache))
def get(self): """Make the Cloud Endpoints request from this handler.""" credentials = appengine.AppAssertionCredentials( scope='https://www.googleapis.com/auth/userinfo.email') http = credentials.authorize(httplib2.Http()) (response, content) = http.request( 'https://sheriff-config-dot-chromeperf.appspot.com/configs/update', 'GET') if response.status != '200': return webapp2.Response('FAILED: %r\n%s' % (response, content)) return webapp2.Response('OK')
def _GetBigqueryClient(): """Returns a Bigquery api client for the current project. This method caches the client for reusing. """ if hasattr(_GetBigqueryClient, 'client'): return getattr(_GetBigqueryClient, 'client') credentials = gae_oauth2client.AppAssertionCredentials( scope=_AUTH_ENDPOINT) http_auth = credentials.authorize(http=httplib2.Http(timeout=60)) bigquery_client = discovery.build('bigquery', 'v2', http=http_auth) setattr(_GetBigqueryClient, 'client', bigquery_client) return bigquery_client
def _load_credentials(self, credentials_file_path): if credentials_file_path == GCE_CREDENTIALS: return gce.AppAssertionCredentials(self._SCOPES) if credentials_file_path == APPENGINE_CREDENTIALS: # pragma: no cover # This import doesn't work outside appengine, so delay it until it's used. from oauth2client import appengine return appengine.AppAssertionCredentials(self._SCOPES) with open(credentials_file_path, 'r') as credentials_file: credentials_json = json.load(credentials_file) if credentials_json.get('type', None): credentials = GoogleCredentials.from_stream(credentials_file_path) credentials = credentials.create_scoped(self._SCOPES) return credentials return Storage(credentials_file_path).get()
def __init__( self, handler ): self.url = handler.get_config( 'earth-engine', 'api' ) account = handler.get_config( 'earth-engine', 'ee_account' ) key = handler.get_config( 'earth-engine', 'ee_private_key_file' ) DEBUG_MODE = ('SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev')) if DEBUG_MODE: EE_API_URL = 'https://earthengine.sandbox.google.com' EE_CREDENTIALS = ee.ServiceAccountCredentials(account, key) else: EE_API_URL = 'https://earthengine.googleapis.com' EE_CREDENTIALS = appengine.AppAssertionCredentials(ee.OAUTH2_SCOPE) # Initialize the EE API EE_TILE_SERVER = EE_API_URL + '/map/' ee.data.DEFAULT_DEADLINE = 60 * 20 logging.info('Initializing with ' + EE_API_URL) ee.Initialize(EE_CREDENTIALS, EE_API_URL)
def get_bq(): if Utils.BQ_CLIENT: return Utils.BQ_CLIENT BQ_CREDENTIALS = None # If runing on Google stack, authenticate natively if Utils.isGae(): from oauth2client import appengine BQ_CREDENTIALS = appengine.AppAssertionCredentials(scope='https://www.googleapis.com/auth/bigquery') else: from oauth2client.client import SignedJwtAssertionCredentials KEY = Utils.read_file(config.KEY_FILE) BQ_CREDENTIALS = SignedJwtAssertionCredentials(config.SERVICE_ACCOUNT, KEY, 'https://www.googleapis.com/auth/bigquery') BQ_HTTP = BQ_CREDENTIALS.authorize(httplib2.Http()) Utils.BQ_CLIENT = build('bigquery', 'v2', http=BQ_HTTP) return Utils.BQ_CLIENT
def create(self, scopes): # pragma: no cover # This import doesn't work outside appengine, so delay it until it's used. from oauth2client import appengine return appengine.AppAssertionCredentials(scopes)
from ee.oauthinfo import OAuthInfo from oauth2client import appengine # Auto-set debug mode based on App Engine dev environ DEBUG_MODE = ('SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev')) if DEBUG_MODE: EE_API_URL = 'https://earthengine.sandbox.google.com' EE_CREDENTIALS = ee.ServiceAccountCredentials(EE_ACCOUNT, EE_PRIVATE_KEY_FILE) FT_TABLE = 'imazon_testing.csv' FT_TABLE_ID = '2676501' else: EE_API_URL = 'https://earthengine.googleapis.com' EE_CREDENTIALS = appengine.AppAssertionCredentials(OAuthInfo.SCOPE) app_id = app_identity.get_application_id() if app_id == 'imazon-sad-tool': FT_TABLE = 'areas' FT_TABLE_ID = '1089491' elif app_id == 'imazon-prototype': FT_TABLE = 'imazon_testing.csv' FT_TABLE_ID = '2676501' elif app_id == 'sad-training': FT_TABLE = 'areas_training' FT_TABLE_ID = '1898803' elif app_id == 'sad-ee': FT_TABLE = 'SAD EE Polygons' FT_TABLE_ID = '2949980' # Initialize the EE API.
import json import webapp2 from google.appengine.ext.webapp import template from google.appengine.api import memcache from apiclient.discovery import build from apiclient import errors from oauth2client import appengine from config import * _SCOPE = 'https://www.googleapis.com/auth/bigquery' credentials = appengine.AppAssertionCredentials(scope=_SCOPE) http = credentials.authorize(httplib2.Http()) # [tweets:2015_01_09] FROM_CLAUSE = "[%s.%s]" % (DATASET_ID, TABLE_ID) REMOVE_HTML = re.compile(r'<.*?>') def get_service(): return build('bigquery', 'v2', http=http) class ShowHome(webapp2.RequestHandler): def get(self): template_data = {}