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

Pass access_token to namespace getter #1746

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions web_ui/frontend/app/registry/components/PutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const PutPage = ({ update }: NamespaceFormPage) => {
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get('id');
const fromUrl = urlParams.get('fromUrl');
const accessToken = urlParams.get('access_token');

if (id === null) {
dispatch({
Expand Down Expand Up @@ -105,13 +106,11 @@ const PutPage = ({ update }: NamespaceFormPage) => {
},
});
}
}, []);

useEffect(() => {
(async () => {
if (id !== undefined) {
const response = await alertOnError(
async () => await getNamespace(id),
async () => await getNamespace(id, accessToken || undefined),
"Couldn't get namespace",
dispatch
);
Expand All @@ -120,7 +119,7 @@ const PutPage = ({ update }: NamespaceFormPage) => {
}
}
})();
}, [id]);
}, []);

return (
<AuthenticatedContent redirect={true} boxProps={{ width: '100%' }}>
Expand Down
24 changes: 0 additions & 24 deletions web_ui/frontend/app/registry/components/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@ export const deleteKey = (o: any, key: string[]) => {
return o;
};

const handleRequestAlert = async (
url: string,
options: any
): Promise<Alert | undefined> => {
try {
const response = await secureFetch(url, options);

if (!response.ok) {
let errorMessage = await getErrorMessage(response);
return { severity: 'error', message: errorMessage };
}
} catch (e) {
return { severity: 'error', message: `Fetch error: ${e}` };
}
};

const namespaceFormNodeToJSON = (formData: FormData) => {
let data: any = {};
formData.forEach((value: any, name: any) => {
populateKey(data, calculateKeys(name), value);
});
return data;
};

export const namespaceToCache = (data: Namespace) => {
// Build the cache prefix
if (data.prefix.startsWith('/caches/')) {
Expand Down
2 changes: 1 addition & 1 deletion web_ui/frontend/components/layout/AuthenticatedContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const AuthenticatedContent = ({
if (data && checkAuthentication) {
return checkAuthentication(data);
} else {
return data?.authenticated === undefined ? false : data.authenticated;
return !!data?.authenticated;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this fixes another issue that I saw where the previous solution would consider you authenticated even if data.authenticated == false.

}
}, [data, checkAuthentication]);

Expand Down
23 changes: 21 additions & 2 deletions web_ui/frontend/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,19 @@ export const getNamespaces = async (): Promise<Response> => {
/**
* Gets a namespace by ID
* @param id Namespace ID
* @param accessToken Access token
*/
export const getNamespace = async (id: string | number): Promise<Response> => {
export const getNamespace = async (
id: string | number,
accessToken?: string
): Promise<Response> => {
const url = new URL(
`/api/v1.0/registry_ui/namespaces/${id}`,
window.location.origin
);
if (accessToken) {
url.searchParams.append('access_token', accessToken);
}
return await fetchApi(async () => await fetch(url));
};

Expand All @@ -154,8 +161,20 @@ export const postGeneralNamespace = async (
export const putGeneralNamespace = async (
data: Namespace
): Promise<Response> => {
// If an access_token is in the URL, add it to the request
const url = new URL(
`/api/v1.0/registry_ui/namespaces/${data.id}`,
window.location.origin
);
const accessToken = new URLSearchParams(window.location.search).get(
'access_token'
);
if (accessToken) {
url.searchParams.append('access_token', accessToken);
}

return await fetchApi(async () => {
return secureFetch(`/api/v1.0/registry_ui/namespaces/${data.id}`, {
return secureFetch(url.toString(), {
body: JSON.stringify(data),
method: 'PUT',
headers: {
Expand Down
Loading