diff --git a/backend/app/app/routers/api_v2/endpoints/farms.py b/backend/app/app/routers/api_v2/endpoints/farms.py index ec53060..8c07d5e 100644 --- a/backend/app/app/routers/api_v2/endpoints/farms.py +++ b/backend/app/app/routers/api_v2/endpoints/farms.py @@ -55,10 +55,8 @@ def get_all_farm_info( data[farm.id] = farm.info else: - # Determine the correct version - version = 2 if len(farm.token.access_token) > 60 else 1 try: - farm_client = get_farm_client(db=db, farm=farm, version=version) + farm_client = get_farm_client(db=db, farm=farm) except ClientError as e: data[farm.id] = str(e) diff --git a/backend/app/app/routers/api_v2/endpoints/utils.py b/backend/app/app/routers/api_v2/endpoints/utils.py index 915141d..8a6b259 100644 --- a/backend/app/app/routers/api_v2/endpoints/utils.py +++ b/backend/app/app/routers/api_v2/endpoints/utils.py @@ -219,8 +219,7 @@ def authorize_farm( # Reconnect to the farmOS server and update farm info. try: - version = 2 if len(new_token.access_token) > 60 else 1 - farm_client = get_farm_client(db=db, farm=farm, version=version) + farm_client = get_farm_client(db=db, farm=farm) response = farm_client.info() # Set the info depending on v1 or v2. diff --git a/backend/app/app/routers/utils/farms.py b/backend/app/app/routers/utils/farms.py index 2e001fe..b0c15e7 100644 --- a/backend/app/app/routers/utils/farms.py +++ b/backend/app/app/routers/utils/farms.py @@ -222,7 +222,7 @@ def handle_ping_farms(db: Session, settings): # Create a farmOS.py client. -def get_farm_client(db, farm, version=2): +def get_farm_client(db, farm): client_id = settings.AGGREGATOR_OAUTH_CLIENT_ID client_secret = settings.AGGREGATOR_OAUTH_CLIENT_SECRET @@ -251,15 +251,6 @@ def get_farm_client(db, farm, version=2): # Use the saved scope. scope = farm.scope - # Raise an error if the API endpoint doesn't match the server version. - # The length of the access tokens differs between 1.x and 2.x - if len(token.access_token) < 60 and version == 2: - error = "Server is running farmOS 1.x. Use the /api/v1/farms endpoint." - raise ClientError(error) - elif len(token.access_token) > 60 and version == 1: - error = "Server is running farmOS 2.x. Use the /api/v2/farms endpoint." - raise ClientError(error) - token_updater = partial(_save_token, db=db, farm=farm) # Allow OAuth over http @@ -294,7 +285,6 @@ def get_farm_client(db, farm, version=2): scope=scope, token=token.dict(), token_updater=token_updater, - version=version, ) # Make an authenticated request to trigger automatic refresh. diff --git a/backend/app/app/tests/utils/farm.py b/backend/app/app/tests/utils/farm.py index 892d37c..ca03d6e 100644 --- a/backend/app/app/tests/utils/farm.py +++ b/backend/app/app/tests/utils/farm.py @@ -23,7 +23,6 @@ def get_test_farm_instance(db: Session): hostname=settings.TEST_FARM_URL, client_id="farm", scope="farm_manager", - version=2, ) token = farm_client.authorize( username=settings.TEST_FARM_USERNAME, password=settings.TEST_FARM_PASSWORD