-
Notifications
You must be signed in to change notification settings - Fork 331
/
credentials.jsx
89 lines (79 loc) · 3.13 KB
/
credentials.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, {useEffect} from "react";
import { useOutletContext } from "react-router-dom";
import {
ActionGroup,
ActionsBar,
AlertError,
RefreshButton
} from "../../lib/components/controls";
import {ConfirmationButton} from "../../lib/components/modals";
import useUser from "../../lib/hooks/user";
import {auth} from "../../lib/api";
import {useState} from "react";
import {CredentialsShowModal, CredentialsTable} from "../../lib/components/auth/credentials";
import {useRouter} from "../../lib/hooks/router";
const CredentialsContainer = () => {
const router = useRouter();
const { user } = useUser();
const userId = (user) ? user.id : "";
const [refreshToken, setRefreshToken] = useState(false);
const [createError, setCreateError] = useState(null);
const [createdKey, setCreatedKey] = useState(null);
const { after } = router.query;
const createKey = () => {
return auth.createCredentials(user.id)
.catch(err => {
setCreateError(err);
}).then(key => {
setCreateError(null);
setRefreshToken(!refreshToken);
return key;
})
}
return (
<>
<ActionsBar>
<ActionGroup orientation="left">
<ConfirmationButton
variant="success"
modalVariant="success"
msg={<span>Create a new Access Key for user <strong>{userId}</strong>?</span>}
onConfirm={hide => {
createKey()
.then(key => { setCreatedKey(key) })
.finally(hide);
}}>
Create Access Key
</ConfirmationButton>
</ActionGroup>
<ActionGroup orientation="right">
<RefreshButton onClick={() => setRefreshToken(!refreshToken)}/>
</ActionGroup>
</ActionsBar>
<div className="auth-learn-more">
An access key-pair is the set of credentials used to access lakeFS. <a href="https://docs.lakefs.io/reference/authorization.html#authentication" target="_blank" rel="noopener noreferrer">Learn more.</a>
</div>
{(!!createError) && <AlertError error={createError}/>}
<CredentialsShowModal
credentials={createdKey}
show={(!!createdKey)}
onHide={() => { setCreatedKey(null) }}/>
{(!!user) && <CredentialsTable
userId={user.id}
currentAccessKey={user.accessKeyId}
refresh={refreshToken}
after={(after) ? after : ""}
onPaginate={after => router.push({
pathname: '/auth/credentials',
query: {after}
})}
/>}
</>
);
};
const CredentialsPage = () => {
const [setActiveTab] = useOutletContext();
useEffect(() => setActiveTab("credentials"), [setActiveTab]);
return <CredentialsContainer/>;
};
export default CredentialsPage;