Skip to content

[INS-1805] Add Auth Header for WebSocket - Part 1 #5108

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

Closed
wants to merge 6 commits into from

Conversation

marckong
Copy link
Contributor

@marckong marckong commented Aug 23, 2022

Part 1
This part only includes the UI and adding the authentication to the request model only. The Part 2 would include disabling and enabling the auth fields based on connection status.

  • Added authentication property to the WebSocketRequest
  • Refactored existing components to accommodate WebSocketRequest model (it was tailored to Request model)
  • Added AuthSettingsContext to allow passing properties depending on consumers

Design Decisions:
Ideally it may be beneficial to separate "WrapperDebug" into different pages for debug activity type; gRPC, GraphQL, HTTP, WebSocket or any kind we may want to support in the future.

Currently, WrapperDebug alters what to render by checking boolean, but it would be great if we utilize router for this with params. We have had to have isRequest, isWebSocketRequest, isGrpcRequest methods because we were not separating them in each own component tree. Consequently we are calling db operation in the subset components not in the container component.

The separation of db operation per kind should ideally happen in the container level, not in the sub component level (if they are to be reused). The introduction of Context/Provider pattern was to provide that abstraction to allow resuability of Auth component set without calling the db operation in them but calling them from their container level.

In this design, it is a step forward to attempt the following state demonstrated in the attached screenshot. Note that unlike this PR changes, the screenshot uses AuthSettingsContext only within the tab panel, not in the tab list with the dropdown. This PR did not introduce that as it hit some limitations with the current approach.

image

Limitations:

  • Unit tests may not exist for all cases, and this may be vulnerable to regressions. Therefore, we probably need to run smoke tests on the all auth flows
  • Disabling fields during a WebSocket connection is not implemented as it will be in a follow up PR (this will be done in Part 2 PR)
Screenshot Description
image AuthDropdown
image Basic Auth
image Digest Auth
image Bearer Auth
image Switching from one auth to another

update(activeRequest, { authentication:newAuthentication });
}, [activeRequest]);
const isCurrent = useCallback((type: string) => {
if (!activeRequest) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this was needed. It made sense to remove it since with this change, it does not refer to a request directly inside any more.

const onClick = useCallback(async (type: string) => {
if (!activeRequest) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this was needed. It made sense to remove it since with this change, it does not refer to a request directly inside any more.

<AuthItem type={AUTH_NETRC} {...itemProps} />
<DropdownDivider>Other</DropdownDivider>
<AuthItem type={AUTH_NONE} nameOverride="No Authentication" {...itemProps} />
{authTypes.reduce<ReactElement[]>((acc: ReactElement[], authType: AuthType) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was needed as we wanted to support only three auth types for the initial websocket support; basic, digest, and bearer.

@marckong marckong changed the title [INS-1805] (WIP) Add Auth Header for WebSocket [INS-1805] Add Auth Header for WebSocket - Part 1 Aug 24, 2022
@marckong
Copy link
Contributor Author

Still need to fix unit tests that are wired up with redux, but I will request a review for early review.

@marckong marckong requested a review from a team August 24, 2022 17:25
Comment on lines +156 to +159
<AuthSettingsProvider
authentication={request.authentication}
onAuthUpdate={handleAuthUpdate}
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you describe a bit your thinking around using context provider here. Since the useActiveRequest hook was just wrapping redux I can see why you chose it, but it would be nice to have a record of your rationale.

Copy link
Contributor Author

@marckong marckong Aug 25, 2022

Choose a reason for hiding this comment

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

useActiveRequest was selecting activeRequest model but then it was eventually calling models.request.update(). Please refer to this below line. This gets called throughout the component tree under AuthWrapper or AuthDropdown. Now with WebSocketRequest model, we would have to alternate models.webSocketRequest.update() / models.requestupdate().

I put the context to allow us to pass the request/webSocketRequest update method to be passed depending on the usage.

const patchAuth = useCallback((patch: Partial<Request['authentication']>) => updateAuth({ ...authentication, ...patch }), [authentication, updateAuth]);

@marckong marckong marked this pull request as ready for review August 25, 2022 19:09
@marckong marckong requested a review from a team August 25, 2022 19:10
* Ensure the request.authentication.type property is added
* @param request
*/
function migrateAuthType(request: WebSocketRequest) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed to remove this

@marckong
Copy link
Contributor Author

Closing as it is implemented with the current approach as we discussed - #5115

@marckong marckong closed this Aug 26, 2022
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