in aws-core-ui/src/App/Components/Type/AccessKey/RotateKeysComponent.tsx [29:72]
export default function RotateKeysComponent() {
const { config, setConfig } = useApplicationContext();
const [isLoading, setLoading] = useState(false);
const [rotationStatus, setRotationStatus] = useState({} as RotationStatus);
const updateConfig = (key: string, secret: string) => {
const newConfig = { ...config, accessKeyId: key, secretAccessKey: secret };
setConfig(newConfig);
};
const rotateKeys = () => {
setLoading(true);
requestKeyRotation(config)
.then((res) => {
if (res.errorMessage) {
setRotationStatus({
success: false,
message: res.errorMessage,
});
} else {
updateConfig(res.key, res.secret);
setRotationStatus({
success: true,
message: 'Keys have been rotated',
});
}
})
.catch((e) =>
console.error('An unexpected key rotation process exception: ', e)
)
.finally(() => setLoading(false));
};
return (
<div className={styles.rowStyle}>
<Button loader={isLoading} onClick={rotateKeys}>
{'Rotate keys'}
</Button>
<div className={styles.rotateKeyMessage}>
{' '}
<RotationStatusMessage status={rotationStatus} />{' '}
</div>
</div>
);
}