Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix | Web UI server-side storage #50

Merged
merged 4 commits into from
Aug 23, 2024
Merged

Conversation

stojkovicv
Copy link
Member

Description

This PR enhances session data storage by moving it from the browser cache to server-side storage. It introduces several auxiliary endpoints and tweaks frontend functionalities to allign with the in-memory writing of the Python classes. Minor styling changes are done, as well.
The changes have been tested from two different devices to confirm consistency.

Related issue: #49

@stojkovicv stojkovicv added bug Something isn't working enhancement New feature or request labels Aug 19, 2024
@dsilhavy dsilhavy added this to the Version 1.1.0 milestone Aug 20, 2024
Copy link
Contributor

@davidjwbbc davidjwbbc left a comment

Choose a reason for hiding this comment

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

There's some changes needed so that these changes respect the class interfaces for M1Session instead of trying to bypass them. Bypassing them could cause misbehaviour in the class as your bypass is not maintaining the internal data integrity maintained by the class itself. It also add the risk that future changes to the internals of the M1Session class break your code when internal data structures are changed.

@app.delete("/remove_all_sessions")
async def remove_all_sessions():
session = await get_session(config)
session._M1Session__provisioning_sessions.clear()
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not be accessing protected members of a class from outside the class, please stick to using M1Session public methods to manipulate the session.

Also clearing the list of known provisioning sessions like this is a bad idea (it won't update the persistent data store for one), if you want to remove provisioning sessions then use session.provisioningSessionDestroy() on each known provisioning session id (session.provisioningSessionIds()).


session_data = session._M1Session__provisioning_sessions.get(provisioning_session_id)
if session_data is not None:
session_data['certificate_id'] = cert_id
Copy link
Contributor

Choose a reason for hiding this comment

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

The certificate Id will already be in the list of certificate Ids in the provisioning session after the call to session.createNewCertificate(), you shouldn't be setting strange dictionary members.

if cert_id is None:
raise HTTPException(status_code=400, detail='Failed to create certificate')

session_data = session._M1Session__provisioning_sessions.get(provisioning_session_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, there are methods to access and manipulate provisioning sessions in M1Session. There is no need to bypass the class and access member variables directly.

Comment on lines 261 to 263
session_data = session._M1Session__provisioning_sessions.get(provisioning_session_id)
if session_data and 'certificate_id' in session_data:
return {"certificate_id": session_data['certificate_id']}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be using session.provisioningSessionCertificateIds(provisioning_session_id) to retrieve a list of certificates, not inventing a single certificate store.

Copy link
Member Author

@stojkovicv stojkovicv Aug 22, 2024

Choose a reason for hiding this comment

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

There's been an unclear issue, where I receive empty list of a certificate Ids when using session.provisioningSessionCertificateIds(provisioning_session_id), even though the Certificate is created.

Another possibility is to fetch this ID directly from the AF response for provisioning session:

    "serverCertificateIds": [
        "f9a4cf16-58dc-41ef-8bfc-d7aaf8f810a4"
    ]

Copy link
Member Author

@stojkovicv stojkovicv Aug 22, 2024

Choose a reason for hiding this comment

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

In other words, session.provisioningSessionCertificateIds might have memory issue at some point along the way, resulting always with the empty list.
Instead I call session.certificateIds()

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a bug that should be fixed then. If something is not working as expected then feel free to raise an issue.

@stojkovicv stojkovicv merged commit 028cb60 into development Aug 23, 2024
@stojkovicv stojkovicv deleted the fix/server-storage branch August 26, 2024 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

3 participants