Skip to content

Commit c2f62fd

Browse files
committed
load credentials from .env file
1 parent d9e1ce3 commit c2f62fd

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ env
1616

1717
# Private files
1818
.pypirc
19+
.env

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Geo Engine Python Package
22

3-
43
[![CI](https://github.com/geo-engine/geoengine-python/actions/workflows/ci.yml/badge.svg)](https://github.com/geo-engine/geoengine-python/actions/workflows/ci.yml)
54

65
This package allows easy access to Geo Engine functionality from Python environments.
@@ -101,3 +100,16 @@ print(workflow.get_result_descriptor())
101100

102101
workflow.get_dataframe(ge.Bbox([-60.0, 5.0, 61.0, 6.0], [time, time]))
103102
```
103+
104+
## Authentication
105+
106+
If the Geo Engine server requires authentication, you can set your credentials in the following ways:
107+
108+
1. in the initialize method: `ge.initialize("http://peter.geoengine.io:6060", ("email", "password"))`
109+
2. as environment variables `export GEOENGINE_EMAIL="email"` and `export GEOENGINE_PASSWORD="password"`
110+
3. in a .env file in the current working directory with the content:
111+
112+
```bash
113+
GEOENGINE_EMAIL="email"
114+
GEOENGINE_PASSWORD="password"
115+
```

geoengine/auth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from uuid import UUID
77

88
import os
9+
from dotenv import load_dotenv
910
import requests as req
1011
from requests.auth import AuthBase
1112

@@ -129,8 +130,11 @@ def initialize(server_url: str, credentials: Tuple[str, str] = None) -> None:
129130
130131
optional arugments: (email, password) as tuple
131132
optional environment variables: GEOENGINE_EMAIL, GEOENGINE_PASSWORD
133+
optional .env file defining: GEOENGINE_EMAIL, GEOENGINE_PASSWORD
132134
'''
133135

136+
load_dotenv()
137+
134138
Session.session = Session(server_url, credentials)
135139

136140

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ install_requires =
2525
owslib
2626
pillow
2727
pyepsg # for cartopy
28+
python-dotenv
2829
rasterio
2930
requests
3031
scipy # for cartopy

0 commit comments

Comments
 (0)