Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
[teleport] Change NodeJoinToken prop expires to expiry (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisa Kim authored Oct 19, 2020
1 parent 6d0b59f commit 3812d12
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
14 changes: 9 additions & 5 deletions packages/teleport/src/Nodes/NodeAdd/ByScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
*/

import React from 'react';
import moment from 'moment';
import { NodeAdd } from './NodeAdd';
import { useTheme } from 'styled-components';
import TextSelectCopy from 'teleport/components/TextSelectCopy';
import { Alert, Text, Indicator, Box, ButtonLink } from 'design';

export default function ByScript(props: Props) {
const monoFont = useTheme().fonts.mono;
const { script, expires, getJoinToken, attempt, ...style } = props;
const { script, expiry, getJoinToken, attempt, ...style } = props;

const duration = moment(new Date()).diff(expiry);
const expiresText = moment.duration(duration).humanize();

if (attempt.status === 'processing') {
return (
Expand All @@ -39,11 +43,11 @@ export default function ByScript(props: Props) {
return (
<>
<Text {...style}>
Use the auto installer script to add a server to your cluster.
Use below script to add a server to your cluster.
<br />
Script will be valid for{' '}
The script will be valid for{' '}
<Text bold as={'span'}>
{expires}.
{expiresText}.
</Text>
</Text>
<TextSelectCopy text={script} style={{ fontFamily: monoFont }} mb={2} />
Expand All @@ -58,7 +62,7 @@ type PropTypes = Parameters<typeof NodeAdd>[0];

type Props = {
script: string;
expires: string;
expiry: PropTypes['expiry'];
getJoinToken: PropTypes['createJoinToken'];
attempt: PropTypes['attempt'];
// handles styles
Expand Down
2 changes: 1 addition & 1 deletion packages/teleport/src/Nodes/NodeAdd/NodeAdd.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const sample = {
isEnterprise: true,
canCreateToken: true,
script: 'some bash script',
expires: '4h0m0s',
expiry: new Date('3000-10-14'),
attempt: {
status: 'success',
statusText: '',
Expand Down
4 changes: 2 additions & 2 deletions packages/teleport/src/Nodes/NodeAdd/NodeAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function NodeAdd(props: ReturnType<typeof useNodeAdd>) {
onClose,
createJoinToken,
script,
expires,
expiry,
attempt,
} = props;

Expand All @@ -46,7 +46,7 @@ export function NodeAdd(props: ReturnType<typeof useNodeAdd>) {
isEnterprise={isEnterprise}
onClose={onClose}
script={script}
expires={expires}
expiry={expiry}
createJoinToken={createJoinToken}
attempt={attempt}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/teleport/src/Nodes/NodeAdd/NodeAddEnterprise.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import NodeAddDefault from './NodeAddOSS';
export default function NodeAddEnterprise({
onClose,
script,
expires,
expiry,
createJoinToken,
canCreateToken,
version,
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function NodeAddEnterprise({
{activeTab.title === 'Automatically' ? (
<NodeAddByScript
script={script}
expires={expires}
expiry={expiry}
getJoinToken={createJoinToken}
attempt={attempt}
mb={3}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,14 @@ exports[`success state 1`] = `
<div
class="c12"
>
Use the auto installer script to add a server to your cluster.
Use below script to add a server to your cluster.
<br />
Script will be valid for
The script will be valid for
<span
class="c13"
>
4h0m0s
980 years
.
</span>
</div>
Expand Down
6 changes: 3 additions & 3 deletions packages/teleport/src/Nodes/NodeAdd/useNodeAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function useNodeAdd(ctx: TeleportContext, onClose: () => void) {
const isEnterprise = cfg.isEnterprise;

const [script, setScript] = useState('');
const [expires, setExpires] = useState('');
const [expiry, setExpiry] = useState<Date>(null);

useEffect(() => {
if (isEnterprise && canCreateToken) {
Expand All @@ -36,7 +36,7 @@ export default function useNodeAdd(ctx: TeleportContext, onClose: () => void) {

function createJoinToken() {
return ctx.nodeService.createNodeJoinToken().then(token => {
setExpires(token.expires);
setExpiry(token.expiry);
setScript(
`sudo bash -c "$(curl -sSL ${cfg.getNodeJoinScriptUrl(token.id)})"`
);
Expand All @@ -50,7 +50,7 @@ export default function useNodeAdd(ctx: TeleportContext, onClose: () => void) {
onClose,
createJoinToken,
script,
expires,
expiry,
attempt,
};
}
4 changes: 2 additions & 2 deletions packages/teleport/src/services/nodes/makeNodeJoinToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { at } from 'lodash';
import { NodeJoinToken } from './types';

export default function makeToken(json): NodeJoinToken {
const [id, expires] = at(json, ['id', 'expires']);
const [id, expiry] = at(json, ['id', 'expiry']);

return {
id,
expires,
expiry: new Date(expiry),
};
}
2 changes: 1 addition & 1 deletion packages/teleport/src/services/nodes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export interface Node {

export interface NodeJoinToken {
id: string;
expires: string;
expiry: Date;
}

0 comments on commit 3812d12

Please sign in to comment.