-
Notifications
You must be signed in to change notification settings - Fork 111
CloudTrayMenu: Allow dev tokens #3459
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
CloudTrayMenu: Allow dev tokens #3459
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refactors CloudTrayMenu token management by separating bag versus file token cleanup, preserves file-based dev tokens on validation failure, ensures legacy bag tokens are always cleared, pre-cleans the file token before updates, and adds proper awaiting for filebrowser HTTP operations. Sequence diagram for updated MajorTom token validation and cleanupsequenceDiagram
participant CloudTrayMenu
participant Bag
participant Filebrowser
CloudTrayMenu->>Bag: getData('major_tom')
CloudTrayMenu->>CloudTrayMenu: isMajorTomTokenValid(tokenToUse, true)
alt Token invalid
CloudTrayMenu->>CloudTrayMenu: Do not remove file token (preserve dev token)
CloudTrayMenu->>CloudTrayMenu: Set tokenToUse = undefined
else Token valid and differs from file token
CloudTrayMenu->>CloudTrayMenu: updateMajorTomToken(tokenToUse)
CloudTrayMenu->>Filebrowser: cleanMajorTomFileToken()
CloudTrayMenu->>Filebrowser: createFile(MAJOR_TOM_CLOUD_TOKEN_FILE.path, true)
CloudTrayMenu->>Filebrowser: writeToFile(MAJOR_TOM_CLOUD_TOKEN_FILE.path, token)
end
CloudTrayMenu->>Bag: cleanMajorTomBagToken() (always)
CloudTrayMenu->>Bag: setData('major_tom', { ...data })
CloudTrayMenu->>CloudTrayMenu: Set local_token
Class diagram for updated CloudTrayMenu token management methodsclassDiagram
class CloudTrayMenu {
+async cleanMajorTomBagToken(): Promise<void>
+async cleanMajorTomFileToken(): Promise<void>
+async fetchMajorTomData(): Promise<InstalledExtensionData>
+async updateMajorTomToken(token: string): Promise<void>
}
class Filebrowser {
+async createFile(folder_path: string, override: Boolean = false): Promise<void>
+async writeToFile(file: string, content: string): Promise<void>
+async deleteFile(file: FilebrowserFile): Promise<void>
}
CloudTrayMenu --> Filebrowser : uses
Flow diagram for MajorTom token update processflowchart TD
A[Start token update] --> B{Is token valid?}
B -- No --> C[Preserve file token]
C --> D[Remove bag token]
D --> E[Set local_token to empty]
B -- Yes --> F{Does token differ from file token?}
F -- Yes --> G[Clean file token]
G --> H[Create file token]
H --> I[Write new token]
I --> D
F -- No --> D
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
ff6ec0c
to
49947eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider logging errors in the catch block around cleanMajorTomFileToken so you can track file delete failures instead of silently swallowing them.
- It would be safer to add explicit error handling or response status checks in your Filebrowser methods (createFile/writeToFile/deleteFile) to avoid unhandled axios failures.
- You could refactor the bag and file token cleanup into a shared utility to reduce duplication between cleanMajorTomBagToken and cleanMajorTomFileToken.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider logging errors in the catch block around cleanMajorTomFileToken so you can track file delete failures instead of silently swallowing them.
- It would be safer to add explicit error handling or response status checks in your Filebrowser methods (createFile/writeToFile/deleteFile) to avoid unhandled axios failures.
- You could refactor the bag and file token cleanup into a shared utility to reduce duplication between cleanMajorTomBagToken and cleanMajorTomFileToken.
## Individual Comments
### Comment 1
<location> `core/frontend/src/components/cloud/CloudTrayMenu.vue:289` </location>
<code_context>
this.operation_error_message = String(error)
},
- async cleanMajorTomToken(): Promise<void> {
+ async cleanMajorTomBagToken(): Promise<void> {
const data = await bag.getData('major_tom')
if (data && data.token) {
</code_context>
<issue_to_address>
Consider handling the case where bag.getData('major_tom') returns null or undefined.
Spreading a null value into setData may cause runtime errors; ensure data is always an object before spreading.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
const data = await bag.getData('major_tom')
if (data && data.token) {
delete data.token
}
await bag.setData('major_tom', { ...data })
=======
const data = await bag.getData('major_tom') || {}
if (data.token) {
delete data.token
}
await bag.setData('major_tom', { ...data })
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `core/frontend/src/components/cloud/CloudTrayMenu.vue:336` </location>
<code_context>
this.local_token = tokenToUse ?? ''
},
async updateMajorTomToken(token: string): Promise<void> {
+ try {
+ await this.cleanMajorTomFileToken()
+ } catch {
+ /** Do nothing */
+ }
</code_context>
<issue_to_address>
Catching all errors without logging may obscure underlying issues.
Consider logging the exception or adding a comment to clarify why silent failure is appropriate in this context.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
async updateMajorTomToken(token: string): Promise<void> {
+ try {
+ await this.cleanMajorTomFileToken()
+ } catch {
+ /** Do nothing */
+ }
=======
async updateMajorTomToken(token: string): Promise<void> {
try {
await this.cleanMajorTomFileToken()
} catch (err) {
// Log the error to help diagnose issues with token cleanup.
// Silent failure is appropriate here because token cleanup is non-critical.
console.error('Failed to clean Major Tom file token:', err)
}
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
9f3fc71
to
1b176ee
Compare
I cant connect to cloud either on master or in this PR... are we not supporting outdated major tom versions? I'm on 2025-04-10 |
Good point, @joaomariolago maybe we should preserve the token in the bag and let majortom remove it when he finds a token in the filesystem. |
I think this was the original behavior of the PR, we decided on other discussions to remove the token from bag always, but if we think is better I can revert to keep in both bag and file system |
I think it's a valid behavior, older versions of major tom should still be able to use from the bag, and once majortom get updated it can remove the token from the bag and consume from the filesystem. |
* Do not remove a file token if it is invalid to allow other services that may use dev tokens to keep working * make sure token is always available at bag and file system so backend service can decide where to fetch and clean from bag if it supports new file system token approach
* Fix CRUD operations declared as asynced but not awaited correctly creating sync issues in other codes that uses these operations
1b176ee
to
4b0d513
Compare
@Williangalvani can you re-check this PR after last changes to check if it is working for you now |
Summary by Sourcery
Improve CloudTrayMenu token management by separating bag and file token cleanup, preserving developer tokens stored in files, always clearing legacy bag tokens, and ensuring filebrowser operations are properly awaited
Bug Fixes:
Enhancements: