Skip to content

Commit

Permalink
Merge pull request #8 from CIAT-DAPA/develop
Browse files Browse the repository at this point in the history
geoserver credentials changed to environment variables and pipeline a…
  • Loading branch information
Minotriz02 authored May 28, 2024
2 parents bde2726 + 27d48db commit b03af73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
pip install -r ./requirements.txt
- name: Create credentials file
run: |
echo "GEOSERVER_USER=${{env.GEOSERVER_USERNAME}}" > geo_config.txt
echo "GEOSERVER_PASSWORD=${{env.GEOSERVER_PASSWORD}}" >> geo_config.txt
export GEOSERVER_USER=${{env.GEOSERVER_USERNAME}}
export GEOSERVER_PASSWORD=${{env.GEOSERVER_PASSWORD}}
- name: Run Tests
run: |
python -m unittest discover -s ./src/test/ -p 'test_*.py'
Expand Down
27 changes: 9 additions & 18 deletions src/aclimate_api/geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ def __init__(self, url_root):
self.url_root = url_root

def get_geo_workspaces(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(current_dir, '../../geo_config.txt')

with open(config_file, "r") as f:
credentials = dict(line.strip().split('=') for line in f.readlines())
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

url = f"{self.url_root}/rest/workspaces.json"

response = requests.get(url, auth=(credentials['GEOSERVER_USER'], credentials['GEOSERVER_PASSWORD']))
response = requests.get(url, auth=(user, password))

data = json.loads(response.text)
workspaces_list = data['workspaces']['workspace']
Expand All @@ -31,15 +28,12 @@ def get_geo_workspaces(self):
# print(get_geo_workspaces("https://geo.aclimate.org/geoserver/"))

def get_geo_mosaic_name(self, workspace):
current_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(current_dir, '../../geo_config.txt')

with open(config_file, "r") as f:
credentials = dict(line.strip().split('=') for line in f.readlines())
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

url = f"{self.url_root}/rest/workspaces/{workspace}/coveragestores.json"

response = requests.get(url, auth=(credentials['GEOSERVER_USER'], credentials['GEOSERVER_PASSWORD']))
response = requests.get(url, auth=(user, password))

if response.status_code == 200:
data = json.loads(response.text)
Expand Down Expand Up @@ -77,14 +71,11 @@ def get_geo_mosaics(self, workspace, mosaic_name, year, month=1, day=1):
# print(get_geo_mosaics("https://geo.aclimate.org/geoserver/", "waterpoints_et", "biomass", 2024, 4, 22))

def get_geo_polygon_name(self, workspace):
current_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(current_dir, '../../geo_config.txt')

with open(config_file, "r") as f:
credentials = dict(line.strip().split('=') for line in f.readlines())
user = os.getenv("GEOSERVER_USER")
password = os.getenv("GEOSERVER_PASSWORD")

url = f"{self.url_root}rest/workspaces/{workspace}/datastores.json"
response = requests.get(url, auth=(credentials['GEOSERVER_USER'], credentials['GEOSERVER_PASSWORD']))
response = requests.get(url, auth=(user, password))

if response.status_code == 200:
data = json.loads(response.text)
Expand Down
11 changes: 6 additions & 5 deletions src/aclimate_api/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from geographic import Geographic
from forecast import Forecast
from agronomy import Agronomy
Expand All @@ -6,15 +7,15 @@

def main():
g = Geographic("https://webapi.aclimate.org/api/")
print(g.get_geographic("636c0813e57f2e6ac61394e6"))
# print(g.get_geographic("636c0813e57f2e6ac61394e6"))
f = Forecast("https://webapi.aclimate.org/api/")
print(f.get_forecast_climate(["5a7e422057d7f316c8bc574e"]))
# print(f.get_forecast_climate(["5a7e422057d7f316c8bc574e"]))
a = Agronomy("https://webapi.aclimate.org/api/")
print(a.get_agronomy())
# print(a.get_agronomy())
h = Historical("https://webapi.aclimate.org/api/")
print(h.get_historical_climatology(["5a7e422057d7f316c8bc574e"]))
# print(h.get_historical_climatology(["5a7e422057d7f316c8bc574e"]))
gs = Geoserver("https://geo.aclimate.org/geoserver/")
print(gs.get_geo_workspaces())
# print(gs.get_geo_workspaces())

if __name__ == "__main__":
main()

0 comments on commit b03af73

Please sign in to comment.