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 17, 2020
1 parent 39ff045 commit 0a66791
Showing 1 changed file with 36 additions and 0 deletions.
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,8 @@ 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';

const VMIsDown: React.FC = () => (
<div className="co-m-pane__body">
Expand Down Expand Up @@ -72,8 +75,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 +146,32 @@ const VMConsoles: React.FC<VMConsolesProps> = ({
</Button>
</StackItem>
)}
{cloudInitPassword && (
<StackItem>
<Alert variant="info" isInline title="Guest login credentials">
The following credentials for this operating system were created via{' '}
<strong>Cloud-init</strong>. If unsuccessful cloud-init could be improperly configured.
Please 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(false)}>
Hide password
</Button>
</>
) : (
<Button isSmall isInline variant="link" onClick={() => setShowPassword(true)}>
Show password
</Button>
)}
</p>
</Alert>
</StackItem>
)}
{typeNotSupported && showAlert && (
<StackItem>
<Alert
Expand Down

0 comments on commit 0a66791

Please sign in to comment.