Skip to content

Instantly share code, notes, and snippets.

@robinkraft
Created April 19, 2014 02:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinkraft/11072182 to your computer and use it in GitHub Desktop.
Save robinkraft/11072182 to your computer and use it in GitHub Desktop.
Simple authentication script for Earth Engine API, including a test.
import unittest
from eesetup import utils
class Test(unittest.TestCase):
def setUp(self):
pass
def test_geeAuth(self):
result = utils.geeAuth()
expected = True
self.assertEqual(result, expected)
import ee
def geeAuth(key_path=None):
"""Authenticate Earth Engine user. Ensure that the *.p12 key file
is in your ~/.ssh/ directory.
"""
if not key_path:
key_path = os.path.expanduser(os.environ['GOOGLE_PRIVATE_KEY_FILE'])
if os.path.exists(key_path):
acct = os.environ['GOOGLE_SERVICE_ACCOUNT']
ee.Initialize(ee.ServiceAccountCredentials(acct, key_path))
return True
else:
raise Exception('Ensure GEE key file is in ~/.ssh directory')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment