Skip to content

Commit

Permalink
Merge branch 'bugfix/ZKUI-190-assume-role-when-list-buckets' into q/1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Jun 17, 2022
2 parents cce1dfc + 09b596e commit 2635dfa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/js/ZenkoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import ZenkoClientBase from 'zenkoclient';
class ZenkoClient extends S3Client implements ZenkoClientInterface {
endpoint: string;
_xmlClient: ZenkoClientBase;
_isLogin: boolean;

constructor(endpoint) {
super(endpoint);
this.endpoint = endpoint;

this._init();
this._isLogin = false;
}

_init() {
Expand Down Expand Up @@ -91,6 +93,8 @@ class ZenkoClient extends S3Client implements ZenkoClientInterface {
// but seems to work for all the other S3 calls.
// this.client.config.update({
// accessKeyId: accessKey, secretAccessKey: secretKey, sessionToken });

this._isLogin = true;
}

searchBucket(params: SearchParams): Promise<SearchBucketResp> {
Expand Down Expand Up @@ -132,6 +136,10 @@ class ZenkoClient extends S3Client implements ZenkoClientInterface {
};
return this._jsonClient.resumeIngestionSite(params).promise();
}

getIsLogin() {
return this._isLogin;
}
}

export default ZenkoClient;
22 changes: 18 additions & 4 deletions src/react/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import DataServiceRoleProvider, {
import BucketCreate from './databrowser/buckets/BucketCreate';
import makeMgtClient from '../js/managementClient';
import { useQuery } from 'react-query';
import { getClients } from './utils/actions';

export const RemoveTrailingSlash = ({ ...rest }) => {
const location = useLocation();
Expand Down Expand Up @@ -67,7 +68,10 @@ function WithAssumeRole({
}: PropsWithChildren<Record<string, unknown>>) {
const dispatch = useDispatch();
const user = useSelector((state: AppState) => state.oidc.user);
const { zenkoClient } = getClients(useSelector((state: AppState) => state));
const isZenkoClientLogin = zenkoClient.getIsLogin();
const { roleArn } = useDataServiceRole();

useEffect(() => {
const isAuthenticated = !!user && !user.expired;

Expand All @@ -76,7 +80,15 @@ function WithAssumeRole({
}
}, [dispatch, user, roleArn]);

return <>{children}</>;
if (isZenkoClientLogin) {
return <>{children}</>;
} else {
return (
<Loader>
<div>Loading</div>
</Loader>
);
}
}

function PrivateRoutes() {
Expand Down Expand Up @@ -126,9 +138,11 @@ function PrivateRoutes() {
}, [dispatch, isAuthenticated, user, latestConfiguration]);

const oidcLogout = useSelector((state: AppState) => state.auth.oidcLogout);
useMemo(() => {if (!isAuthenticated && oidcLogout) {
oidcLogout(true);
}}, [isAuthenticated, oidcLogout])
useMemo(() => {
if (!isAuthenticated && oidcLogout) {
oidcLogout(true);
}
}, [isAuthenticated, oidcLogout]);

if (!isClientsLoaded) {
return (
Expand Down
1 change: 1 addition & 0 deletions src/types/zenko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export interface ZenkoClient extends S3Client {
KeyMarker: string | undefined;
VersionIdMarker: string | undefined;
}): Promise<SearchBucketVersionsResp>;
getIsLogin(): boolean;
}

0 comments on commit 2635dfa

Please sign in to comment.