Created
April 19, 2014 02:38
-
-
Save robinkraft/11072182 to your computer and use it in GitHub Desktop.
Simple authentication script for Earth Engine API, including a test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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