Skip to content

Commit

Permalink
Merge branch 'bugfix/ZKUI-413' into tmp/octopus/w/2.2/bugfix/ZKUI-413
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Nov 15, 2023
2 parents 27f01c8 + babba74 commit f01fda3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/react/DataServiceRoleProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
useS3ConfigFromAssumeRoleResult,
} from './next-architecture/ui/S3ClientProvider';
import Loader from './ui-elements/Loader';
import { useAuth } from './next-architecture/ui/AuthProvider';
import { PromiseResult } from 'aws-sdk/lib/request';
import { AWSError, STS } from 'aws-sdk';

export const _DataServiceRoleContext = createContext<null | {
role: { roleArn: string };
Expand Down Expand Up @@ -74,10 +77,17 @@ const DataServiceRoleProvider = ({ children }: { children: JSX.Element }) => {
const accountName = match?.params.accountName;

const { getQuery } = useAssumeRoleQuery();
const [assumedRole, setAssumedRole] =
useState<PromiseResult<STS.AssumeRoleWithWebIdentityResponse, AWSError>>();
const assumeRoleMutation = useMutation({
mutationFn: (roleArn: string) => getQuery(roleArn).queryFn(),
onSuccess: (data) => {
setAssumedRole(data);
},
});

const { userData } = useAuth();

// invalide the stored ARN if it's not in the list accountsWithRoles
useMemo(() => {
const storedRole = getRoleArnStored();
Expand All @@ -103,7 +113,7 @@ const DataServiceRoleProvider = ({ children }: { children: JSX.Element }) => {
if (role.roleArn) {
assumeRoleMutation.mutate(role.roleArn);
}
}, [role.roleArn, JSON.stringify(accounts)]);
}, [role.roleArn, JSON.stringify(accounts), userData?.token]);

const { getS3Config } = useS3ConfigFromAssumeRoleResult();

Expand All @@ -115,12 +125,12 @@ const DataServiceRoleProvider = ({ children }: { children: JSX.Element }) => {
}
};

if (role.roleArn && !assumeRoleMutation.data) {
if (role.roleArn && !assumedRole) {
return <Loader>Loading...</Loader>;
}

return (
<S3ClientProvider configuration={getS3Config(assumeRoleMutation.data)}>
<S3ClientProvider configuration={getS3Config(assumedRole)}>
<_DataServiceRoleContext.Provider
value={{
role,
Expand Down

0 comments on commit f01fda3

Please sign in to comment.