Skip to content

Commit

Permalink
Fixes 1879054: UI should display password in cloud-init
Browse files Browse the repository at this point in the history
  • Loading branch information
glekner committed Sep 16, 2020
1 parent 39ff045 commit fe60b49
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.kv--button-label {
cursor: pointer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
asVM,
getIsGraphicsConsoleAttached,
getIsSerialConsoleAttached,
getCloudInitVolume,
} from '../../selectors/vm';
import { isVM, isVMI } from '../../selectors/check-type';
import { VMIKind, VMKind } from '../../types/vm';
Expand All @@ -34,6 +35,9 @@ import { VMTabProps } from './types';
import { VMStatusBundle } from '../../statuses/vm/types';
import { VMStatus } from '../../constants/vm/vm-status';
import { ConsoleType } from '../../constants/vm/console-type';
import { VolumeWrapper } from '../../k8s/wrapper/vm/volume-wrapper';
import { CloudInitDataHelper } from '../../k8s/wrapper/vm/cloud-init-data-helper';
import './vm-console.scss';

const VMIsDown: React.FC = () => (
<div className="co-m-pane__body">
Expand Down Expand Up @@ -72,8 +76,15 @@ const VMConsoles: React.FC<VMConsolesProps> = ({
showOpenInNewWindow = true,
}) => {
const [showAlert, setShowAlert] = React.useState(true);
const [showPassword, setShowPassword] = React.useState(false);
const showVNCOption = getIsGraphicsConsoleAttached(vm) !== false;
const showSerialOption = getIsSerialConsoleAttached(vm) !== false;
const cloudInitVolume = getCloudInitVolume(vm);
const data = new VolumeWrapper(cloudInitVolume).getCloudInitNoCloud();
const cloudInitHelper = new CloudInitDataHelper(data);
const cloudInitUserData = cloudInitHelper.getUserData();
const cloudInitUsername = cloudInitUserData?.match(/(?<=user:\s+).*/);
const cloudInitPassword = cloudInitUserData?.match(/(?<=password:\s+).*/);

if (!isVMIRunning(vmi)) {
if (vmStatusBundle?.status?.isImporting() || vmStatusBundle?.status?.isMigrating()) {
Expand Down Expand Up @@ -136,6 +147,27 @@ const VMConsoles: React.FC<VMConsolesProps> = ({
</Button>
</StackItem>
)}
{cloudInitPassword && (
<StackItem>
<Alert variant="info" isInline title="Guest login credentials">
We have attempted to set a username and password for this operating system via{' '}
<strong>cloud-init</strong>. if this is not successful it is possible that cloud-init is
not properly configured. Contact the image provider for more information.
<p>
<strong>User name: </strong> {cloudInitUsername || cloudInitPassword}
{' '}
<strong>Password: </strong>{' '}
{showPassword ? (
cloudInitPassword
) : (
<Button isSmall isInline variant="link" onClick={() => setShowPassword(true)}>
Show password
</Button>
)}
</p>
</Alert>
</StackItem>
)}
{typeNotSupported && showAlert && (
<StackItem>
<Alert
Expand Down

0 comments on commit fe60b49

Please sign in to comment.