-
Notifications
You must be signed in to change notification settings - Fork 2
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
Depreciate data-plane gateway authorization for shard and journal information #1264
Changes from 16 commits
940af97
8b11ec9
bf44b58
1e3309b
c89c7ea
3260fd9
1fd8162
0cf086d
9190abc
a2766cb
97a80d6
5f134dc
b038f59
92a852a
775b573
beffe6e
6d9c124
4caf48d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future change (cause my branch is not done yet) but I'll probably pull this filter into the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import { singleCallSettings } from 'context/SWR'; | ||
import { useUserStore } from 'context/User/useUserContextStore'; | ||
import { JournalClient, JournalSelector } from 'data-plane-gateway'; | ||
import useGatewayAuthToken from 'hooks/gatewayAuthToken/useGatewayAuthToken'; | ||
import { isEmpty } from 'lodash'; | ||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
import { useCounter } from 'react-use'; | ||
import useJournalStore from 'stores/JournalData/Store'; | ||
import useSWR from 'swr'; | ||
import { | ||
dataPlaneFetcher_list, | ||
getJournals, | ||
MAX_DOCUMENT_SIZE, | ||
shouldRefreshToken, | ||
} from 'utils/dataPlane-utils'; | ||
import { useUserStore } from 'context/User/useUserContextStore'; | ||
import { hasLength } from 'utils/misc-utils'; | ||
import { loadDocuments } from './shared'; | ||
import { LoadDocumentsOffsets } from './types'; | ||
|
||
|
@@ -21,54 +23,66 @@ const useJournalsForCollection = (collectionName: string | undefined) => { | |
const [attempts, { inc: incAttempts, reset: resetAttempts }] = | ||
useCounter(0); | ||
|
||
const { data: gatewayConfig, refresh: refreshAuthToken } = | ||
useGatewayAuthToken(collectionName ? [collectionName] : []); | ||
const refreshAuthToken = useJournalStore((state) => state.getAuthToken); | ||
const brokerAddress = useJournalStore( | ||
(state) => state.collectionBrokerAddress | ||
); | ||
const brokerToken = useJournalStore((state) => state.collectionBrokerToken); | ||
|
||
const journalClient = useMemo(() => { | ||
if (gatewayConfig?.gateway_url && gatewayConfig.token) { | ||
const authToken = gatewayConfig.token; | ||
const baseUrl = new URL(gatewayConfig.gateway_url); | ||
if (brokerAddress && brokerToken) { | ||
const baseUrl = new URL(brokerAddress); | ||
|
||
return new JournalClient(baseUrl, authToken); | ||
return new JournalClient(baseUrl, brokerToken); | ||
} else { | ||
return null; | ||
} | ||
}, [gatewayConfig]); | ||
}, [brokerAddress, brokerToken]); | ||
|
||
const fetcher = useCallback( | ||
async (_url: string) => { | ||
if (journalClient && collectionName) { | ||
if ( | ||
journalClient && | ||
collectionName && | ||
brokerAddress && | ||
brokerToken | ||
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really wish typescript was smart enough to not need this. |
||
) { | ||
const journalSelector = new JournalSelector().collection( | ||
collectionName | ||
); | ||
|
||
const dataPlaneListResponse = await dataPlaneFetcher_list( | ||
journalClient, | ||
journalSelector, | ||
'JournalData' | ||
const dataPlaneListResponse = await getJournals( | ||
brokerAddress, | ||
brokerToken, | ||
{ | ||
include: journalSelector.toLabelSet(), | ||
} | ||
); | ||
|
||
if (!Array.isArray(dataPlaneListResponse)) { | ||
if (isEmpty(dataPlaneListResponse)) { | ||
return Promise.reject(dataPlaneListResponse); | ||
} | ||
|
||
return { | ||
journals: | ||
dataPlaneListResponse.length > 0 | ||
? dataPlaneListResponse | ||
dataPlaneListResponse.result.journals && | ||
dataPlaneListResponse.result.journals.length > 0 | ||
? dataPlaneListResponse.result.journals | ||
: [], | ||
Comment on lines
+68
to
71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we know that the |
||
}; | ||
} else { | ||
return null; | ||
} | ||
}, | ||
[collectionName, journalClient] | ||
[brokerAddress, brokerToken, collectionName, journalClient] | ||
); | ||
|
||
const response = useSWR( | ||
collectionName | ||
collectionName && brokerToken | ||
? `journals-${collectionName}-${ | ||
gatewayConfig?.gateway_url ?? '__missing_gateway_url__' | ||
hasLength(brokerAddress) | ||
? brokerAddress | ||
: '__missing_broker_address__' | ||
}` | ||
: null, | ||
fetcher, | ||
|
@@ -81,8 +95,16 @@ const useJournalsForCollection = (collectionName: string | undefined) => { | |
onError: async (error) => { | ||
incAttempts(); | ||
|
||
if (session && shouldRefreshToken(`${error}`)) { | ||
await refreshAuthToken(); | ||
if ( | ||
session && | ||
shouldRefreshToken(`${error}`) && | ||
collectionName | ||
) { | ||
await refreshAuthToken( | ||
session.access_token, | ||
collectionName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine for now... but we probably don't want to use the |
||
true | ||
); | ||
resetAttempts(); | ||
} | ||
|
||
|
@@ -107,28 +129,34 @@ interface UseJournalDataSettings { | |
desiredCount?: number; | ||
maxBytes?: number; | ||
} | ||
|
||
const useJournalData = ( | ||
journalName?: string, | ||
collectionName?: string, | ||
settings?: UseJournalDataSettings | ||
settings?: UseJournalDataSettings, | ||
opsJournalTarget?: boolean | ||
) => { | ||
const failures = useRef(0); | ||
const initialLoadComplete = useRef(false); | ||
|
||
const { data: gatewayConfig } = useGatewayAuthToken( | ||
collectionName ? [collectionName] : null | ||
const brokerAddress = useJournalStore((state) => | ||
opsJournalTarget | ||
? state.taskBrokerAddress | ||
: state.collectionBrokerAddress | ||
); | ||
|
||
const brokerToken = useJournalStore((state) => | ||
opsJournalTarget ? state.taskBrokerToken : state.collectionBrokerToken | ||
); | ||
kiahna-tucker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const journalClient = useMemo(() => { | ||
if (journalName && gatewayConfig?.gateway_url && gatewayConfig.token) { | ||
const authToken = gatewayConfig.token; | ||
const baseUrl = new URL(gatewayConfig.gateway_url); | ||
if (brokerAddress && brokerToken) { | ||
const baseUrl = new URL(brokerAddress); | ||
|
||
return new JournalClient(baseUrl, authToken); | ||
return new JournalClient(baseUrl, brokerToken); | ||
} else { | ||
return undefined; | ||
} | ||
}, [gatewayConfig, journalName]); | ||
}, [brokerAddress, brokerToken]); | ||
|
||
const [data, setData] = | ||
useState<Awaited<ReturnType<typeof loadDocuments>>>(); | ||
|
This file was deleted.
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.
🎉 🎉 🎉 🎉 🎉 🎉