Bases: Block
Block used to manage authentication with NASA Earthdata.
To obtain an account, please refer to the
Earthdata Login docs.
Authentication is handled via the earthaccess
module.
Refer to the earthaccess docs
for more info about the possible credential configurations.
Parameters:
Name |
Type |
Description |
Default |
earthdata_username |
str
|
The Earthdata username of a specific account.
|
required
|
earthdata_password |
str
|
The Earthdata password of a specific account.
|
required
|
Example
Load stored Earthdata credentials:
from prefect_earthdata import EarthdataCredentials
ed_credentials_block = EarthdataCredentials.load("BLOCK_NAME")
Source code in prefect_earthdata/credentials.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 | class EarthdataCredentials(Block):
"""
Block used to manage authentication with NASA Earthdata.
To obtain an account, please refer to the
[Earthdata Login docs](https://www.earthdata.nasa.gov/eosdis/science-system-description/eosdis-components/earthdata-login).
Authentication is handled via the `earthaccess` module.
Refer to the [earthaccess docs](https://nsidc.github.io/earthaccess/)
for more info about the possible credential configurations.
Args:
earthdata_username (str): The Earthdata username of a specific account.
earthdata_password (str): The Earthdata password of a specific account.
Example:
Load stored Earthdata credentials:
```python
from prefect_earthdata import EarthdataCredentials
ed_credentials_block = EarthdataCredentials.load("BLOCK_NAME")
```
""" # noqa E501
_logo_url = "https://yt3.googleusercontent.com/ytc/AGIKgqPjIUeAw3_hrkHWZgixdwD5jc-hTWweoCA6bJMhUg=s176-c-k-c0x00ffffff-no-rj" # noqa
_block_type_name = "NASA Earthdata Credentials"
_documentation_url = "https://giorgiobasile.github.io/prefect-earthdata/credentials/#prefect_earthdata.credentials.EarthdataCredentials" # noqa
earthdata_username: str = Field(
default=...,
description="The Earthdata username of a specific account.",
title="Earthdata username",
)
earthdata_password: SecretStr = Field(
default=...,
description="The Earthdata password of a specific account.",
title="Earthdata password",
)
def login(self) -> earthaccess.Auth:
"""
Returns an authenticated session with NASA Earthdata using
the [`earthaccess.login()`](https://nsidc.github.io/earthaccess/user-reference/api/api/#earthaccess.api.login) function
Example:
Authenticates with NASA Earthdata using the credentials.
```python
from prefect_earthdata import EarthdataCredentials
earthdata_credentials_block = EarthdataCredentials(
earthdata_username = "username",
earthdata_password = "password"
)
earthdata_auth = earthdata_credentials_block.login()
```
""" # noqa E501
os.environ["EARTHDATA_USERNAME"] = self.earthdata_username
os.environ["EARTHDATA_PASSWORD"] = self.earthdata_password.get_secret_value()
return earthaccess.login(strategy="environment")
|
Functions
login
Returns an authenticated session with NASA Earthdata using
the earthaccess.login()
function
Example
Authenticates with NASA Earthdata using the credentials.
from prefect_earthdata import EarthdataCredentials
earthdata_credentials_block = EarthdataCredentials(
earthdata_username = "username",
earthdata_password = "password"
)
earthdata_auth = earthdata_credentials_block.login()
Source code in prefect_earthdata/credentials.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 | def login(self) -> earthaccess.Auth:
"""
Returns an authenticated session with NASA Earthdata using
the [`earthaccess.login()`](https://nsidc.github.io/earthaccess/user-reference/api/api/#earthaccess.api.login) function
Example:
Authenticates with NASA Earthdata using the credentials.
```python
from prefect_earthdata import EarthdataCredentials
earthdata_credentials_block = EarthdataCredentials(
earthdata_username = "username",
earthdata_password = "password"
)
earthdata_auth = earthdata_credentials_block.login()
```
""" # noqa E501
os.environ["EARTHDATA_USERNAME"] = self.earthdata_username
os.environ["EARTHDATA_PASSWORD"] = self.earthdata_password.get_secret_value()
return earthaccess.login(strategy="environment")
|