This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 549
Add ssh public keys on user-profile page #5223
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fc8db98
add ssh public keys
c64fb10
improve ssh layout
963853e
rename sshValue to value
c521801
fix comments
29f3a22
set title is unique key
aa22d17
update
84b9ff2
Merge branch 'master' of https://github.com/Microsoft/pai into dev-ssh
35ce9f5
del notes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
src/webportal/src/app/user/fabric/user-profile/ssh-list-dialog.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isEmpty } from 'lodash'; | ||
import { | ||
DefaultButton, | ||
PrimaryButton, | ||
DialogType, | ||
Dialog, | ||
DialogFooter, | ||
TextField, | ||
} from 'office-ui-fabric-react'; | ||
|
||
import t from '../../../components/tachyons.scss'; | ||
|
||
const SSHListDialog = ({ sshKeys, onDismiss, onAddPublickeys }) => { | ||
const [error, setError] = useState(''); | ||
const [inputTitleError, setInputTitleError] = useState(''); | ||
const [inputValueError, setInputValueError] = useState(''); | ||
const [processing, setProcessing] = useState(false); | ||
const [title, setTitle] = useState(''); | ||
const [value, setValue] = useState(''); | ||
|
||
const onAddAsync = async () => { | ||
let surefireTitle = false; | ||
let surefireValue = false; | ||
|
||
if (title.trim() === '') { | ||
setInputTitleError('Please input title'); | ||
} else if ( | ||
sshKeys !== undefined && | ||
sshKeys.filter(item => item.title === title.trim()).length > 0 | ||
) { | ||
setInputTitleError('This title already exists, please re-input'); | ||
} else { | ||
surefireTitle = true; | ||
} | ||
if ( | ||
value.trim() === '' || | ||
!value.trim().match(/^ssh-rsa AAAA[0-9A-Za-z+/]+[=]{0,3}.*$/) | ||
) { | ||
setInputValueError( | ||
'Please input correct SSH Public key, it should be starting with ssh-rsa.', | ||
); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please validate the You can use this regex: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
surefireValue = true; | ||
} | ||
if (surefireTitle && surefireValue) { | ||
setProcessing(true); | ||
try { | ||
await onAddPublickeys({ | ||
title: title.trim(), | ||
value: value.trim(), | ||
time: new Date().getTime(), | ||
}); | ||
} catch (error) { | ||
setError(error.message); | ||
} finally { | ||
setProcessing(false); | ||
onDismiss(); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Dialog | ||
hidden={false} | ||
onDismiss={onDismiss} | ||
dialogContentProps={{ | ||
type: DialogType.normal, | ||
title: 'Add SSH Public Keys', | ||
}} | ||
modalProps={{ | ||
isBlocking: true, | ||
}} | ||
minWidth={600} | ||
> | ||
<div> | ||
<div className={t.mt1}> | ||
<TextField | ||
label='Title (Please give the SSH key a name):' | ||
required={true} | ||
errorMessage={inputTitleError} | ||
onChange={e => { | ||
setTitle(e.target.value); | ||
setInputTitleError(null); | ||
}} | ||
validateOnFocusOut={true} | ||
/> | ||
</div> | ||
<div className={t.mt1}> | ||
<TextField | ||
label='Value (SSH Public key, starts with ssh-rsa):' | ||
required={true} | ||
errorMessage={inputValueError} | ||
onChange={e => { | ||
setValue(e.target.value); | ||
setInputValueError(null); | ||
}} | ||
multiline | ||
rows={5} | ||
validateOnFocusOut={true} | ||
/> | ||
</div> | ||
</div> | ||
<DialogFooter> | ||
<PrimaryButton | ||
onClick={onAddAsync} | ||
disabled={processing} | ||
text='Add' | ||
/> | ||
<DefaultButton | ||
onClick={onDismiss} | ||
disabled={processing} | ||
text='Cancel' | ||
/> | ||
</DialogFooter> | ||
</Dialog> | ||
<Dialog | ||
hidden={isEmpty(error)} | ||
onDismiss={() => setError('')} | ||
dialogContentProps={{ | ||
type: DialogType.normal, | ||
title: 'Error', | ||
subText: error, | ||
}} | ||
modalProps={{ | ||
isBlocking: true, | ||
}} | ||
> | ||
<DialogFooter> | ||
<DefaultButton onClick={() => setError('')}>OK</DefaultButton> | ||
</DialogFooter> | ||
</Dialog> | ||
</div> | ||
); | ||
}; | ||
|
||
SSHListDialog.propTypes = { | ||
sshKeys: PropTypes.array.isRequired, | ||
onDismiss: PropTypes.func.isRequired, | ||
onAddPublickeys: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default SSHListDialog; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please validate here: the user cannot add ssh keys with duplicate titles. (Title should be unique for one user)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done