Skip to content

Commit

Permalink
feat(ui): Make it easy to use SSO login with CLI. Resolves #4630 (#4645)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec authored Dec 7, 2020
1 parent 76bcaec commit 7055420
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
62 changes: 62 additions & 0 deletions ui/src/app/userinfo/components/cli-help.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import * as React from 'react';
import {createRef, useState} from 'react';

export const CliHelp = () => {
const argoSecure = document.location.protocol === 'https';
const argoBaseHref = document
.getElementsByTagName('base')[0]
.href.toString()
.replace(document.location.protocol + '//' + document.location.host + '/', '');
const argoToken = decodeURIComponent(document.cookie)
.split(';')
.map(x => x.trim())
.find(x => x.startsWith('authorization='))
.replace('authorization=', '');

const text = `export ARGO_SERVER='${document.location.host}'
export ARGO_HTTP1=true
export ARGO_SECURE=${argoSecure ? 'true' : 'false'}
export ARGO_BASE_HREF=${argoBaseHref}
export ARGO_TOKEN='${argoToken}'
export ARGO_NAMESPACE=argo ;# or whatever your namespace is
export KUBECONFIG=/dev/null ;# recommended
# check it works:
argo list`;

const [copied, setCopied] = useState(false);
const hiddenText = createRef<HTMLTextAreaElement>();
return (
<div className='white-box'>
<h4>Using Your Login With The CLI</h4>
<p>Download the latest CLI before you start.</p>
<div style={{fontFamily: 'monospace', whiteSpace: 'pre', margin: 20}}>{text.replace(argoToken, '[REDACTED]')}</div>
<p>For help with options such as ARGO_INSECURE_SKIP_VERIFY, ARGO_NAMESPACE and ARGO_INSTANCEID, run: `argo --help`.</p>
<div>
<button
className='argo-button argo-button--base-o'
disabled={copied}
onClick={() => {
const x = hiddenText.current;
x.select();
x.setSelectionRange(0, 99999);
document.execCommand('copy');
setCopied(true);
}}>
{copied ? (
<>
<i className='fa fa-check' /> Copied to clipboard
</>
) : (
<>
<i className='fa fa-copy' /> Copy to clipboard
</>
)}
</button>
</div>
<textarea ref={hiddenText} style={{width: 0, height: 0, opacity: 0}}>
{text}
</textarea>
</div>
);
};
2 changes: 2 additions & 0 deletions ui/src/app/userinfo/components/user-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {uiUrl} from '../../shared/base';
import {BasePage} from '../../shared/components/base-page';
import {ErrorNotice} from '../../shared/components/error-notice';
import {services} from '../../shared/services';
import {CliHelp} from './cli-help';

interface State {
error?: Error;
Expand Down Expand Up @@ -45,6 +46,7 @@ export class UserInfo extends BasePage<RouteComponentProps<any>, State> {
<i className='fa fa-shield-alt' /> Login / Logout
</a>
</div>
<CliHelp />
</div>
</Page>
);
Expand Down

0 comments on commit 7055420

Please sign in to comment.