Skip to content

Commit 8285090

Browse files
committed
Remove unnecessary logic for specifying client version.
1 parent 1bad238 commit 8285090

File tree

4 files changed

+3
-17
lines changed

4 files changed

+3
-17
lines changed

backend/app/app/routers/api_v2/endpoints/farms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ def get_all_farm_info(
5555
data[farm.id] = farm.info
5656
else:
5757

58-
# Determine the correct version
59-
version = 2 if len(farm.token.access_token) > 60 else 1
6058
try:
61-
farm_client = get_farm_client(db=db, farm=farm, version=version)
59+
farm_client = get_farm_client(db=db, farm=farm)
6260
except ClientError as e:
6361
data[farm.id] = str(e)
6462

backend/app/app/routers/api_v2/endpoints/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ def authorize_farm(
219219

220220
# Reconnect to the farmOS server and update farm info.
221221
try:
222-
version = 2 if len(new_token.access_token) > 60 else 1
223-
farm_client = get_farm_client(db=db, farm=farm, version=version)
222+
farm_client = get_farm_client(db=db, farm=farm)
224223

225224
response = farm_client.info()
226225
# Set the info depending on v1 or v2.

backend/app/app/routers/utils/farms.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def handle_ping_farms(db: Session, settings):
222222

223223

224224
# Create a farmOS.py client.
225-
def get_farm_client(db, farm, version=2):
225+
def get_farm_client(db, farm):
226226
client_id = settings.AGGREGATOR_OAUTH_CLIENT_ID
227227
client_secret = settings.AGGREGATOR_OAUTH_CLIENT_SECRET
228228

@@ -251,15 +251,6 @@ def get_farm_client(db, farm, version=2):
251251
# Use the saved scope.
252252
scope = farm.scope
253253

254-
# Raise an error if the API endpoint doesn't match the server version.
255-
# The length of the access tokens differs between 1.x and 2.x
256-
if len(token.access_token) < 60 and version == 2:
257-
error = "Server is running farmOS 1.x. Use the /api/v1/farms endpoint."
258-
raise ClientError(error)
259-
elif len(token.access_token) > 60 and version == 1:
260-
error = "Server is running farmOS 2.x. Use the /api/v2/farms endpoint."
261-
raise ClientError(error)
262-
263254
token_updater = partial(_save_token, db=db, farm=farm)
264255

265256
# Allow OAuth over http
@@ -294,7 +285,6 @@ def get_farm_client(db, farm, version=2):
294285
scope=scope,
295286
token=token.dict(),
296287
token_updater=token_updater,
297-
version=version,
298288
)
299289

300290
# Make an authenticated request to trigger automatic refresh.

backend/app/app/tests/utils/farm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def get_test_farm_instance(db: Session):
2323
hostname=settings.TEST_FARM_URL,
2424
client_id="farm",
2525
scope="farm_manager",
26-
version=2,
2726
)
2827
token = farm_client.authorize(
2928
username=settings.TEST_FARM_USERNAME, password=settings.TEST_FARM_PASSWORD

0 commit comments

Comments
 (0)