Skip to content

fix federation registration#21

Merged
schandrika merged 2 commits intoeclipse-volttron:developfrom
schandrika:caching
Mar 25, 2026
Merged

fix federation registration#21
schandrika merged 2 commits intoeclipse-volttron:developfrom
schandrika:caching

Conversation

@schandrika
Copy link
Copy Markdown
Contributor

@schandrika schandrika commented Feb 4, 2026

Depends on volttron-core PR 300
Once core is updated and pushed, need to update pyproject.toml dependency

@schandrika schandrika merged commit 9f0e882 into eclipse-volttron:develop Mar 25, 2026
1 of 3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates federation platform registration in VolttronAuthService to align with newer volttron-core federation registration behavior.

Changes:

  • Rename add_federation_platform to register_remote_platform.
  • Persist remote platform public credentials using store_credentials(..., overwrite=True) and switch from boolean return codes to raising exceptions on failure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 193 to +195
platform_identity = f"{platform_id}"
public_creds = PublicCredentials(identity=f"{platform_identity}", publickey=credentials)

self._credentials_store.store_credentials(credentials=public_creds)


_log.info(f"Federation platform registered: {platform_id}")
return True
self._credentials_store.store_credentials(credentials=public_creds, overwrite=True)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using platform_id directly as the credentials identity combined with overwrite=True can overwrite existing/local agent credentials if a remote platform registers with a reserved identity (e.g., AUTH, CONTROL, etc.). Consider namespacing federation identities (e.g., federation.<platform_id>) and/or explicitly rejecting reserved/known identities before storing, and only allowing overwrite when you have verified it's the same remote platform updating its own key.

Copilot uses AI. Check for mistakes.

_log.info(f"Federation platform registered: {platform_id}")
return True
self._credentials_store.store_credentials(credentials=public_creds, overwrite=True)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store_credentials(..., overwrite=True) introduces a hard dependency on a newer volttron-core API. With the current pyproject.toml constraint (volttron-core >=2.0.0rc13), environments may install a core version that doesn't support overwrite, causing a TypeError at runtime. Either bump the minimum volttron-core version in this PR or add a compatibility fallback (call without overwrite when the kwarg isn't supported).

Suggested change
self._credentials_store.store_credentials(credentials=public_creds, overwrite=True)
try:
# Prefer newer API that supports overwriting existing credentials
self._credentials_store.store_credentials(credentials=public_creds, overwrite=True)
except TypeError:
# Fallback for older volttron-core versions that do not accept 'overwrite'
self._credentials_store.store_credentials(credentials=public_creds)

Copilot uses AI. Check for mistakes.
Comment on lines 179 to +198
@@ -193,15 +192,10 @@ def add_federation_platform(self, platform_id: str, credentials: Any) -> bool:

platform_identity = f"{platform_id}"
public_creds = PublicCredentials(identity=f"{platform_identity}", publickey=credentials)

self._credentials_store.store_credentials(credentials=public_creds)


_log.info(f"Federation platform registered: {platform_id}")
return True
self._credentials_store.store_credentials(credentials=public_creds, overwrite=True)
except Exception as e:
_log.error(f"Error registering federation platform {platform_id}: {e}")
return False
raise
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method previously returned bool to indicate success/failure, but now has no return type and always returns None on success while raising on error. If any callers (or an interface/abstract base) still expect a boolean result, this is a breaking API change—consider restoring -> bool with an explicit return value, or annotate -> None and ensure all callers are updated accordingly.

Copilot uses AI. Check for mistakes.
Comment on lines 196 to 197
except Exception as e:
_log.error(f"Error registering federation platform {platform_id}: {e}")
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching Exception and then logging with _log.error(...) loses the traceback context in logs; since the exception is re-raised, consider using _log.exception(...) (or exc_info=True) and avoid double-logging higher up the stack.

Suggested change
except Exception as e:
_log.error(f"Error registering federation platform {platform_id}: {e}")
except Exception:
_log.exception("Error registering federation platform %s", platform_id)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants