import moment from 'moment' ; import cfg from 'teleport/config' ; import { NodeToken , BashCommand } from './types' ; export default function makeAppBashCmd ( token , appName = '' , appUri = '' ) { const duration = moment ( new Date ( ) ) . diff ( token . expiry ) ; const expires = moment . duration ( duration ) . humanize ( ) ; const encoded = encodeURIComponent ( appUri ) . replace ( /'/g , '%27' ) ; const bashUrl = cfg . baseUrl + cfg . api . appNodeScriptPath . replace ( ':token' , token . id ) . replace ( ':name' , appName ) . replace ( ':uri' , encoded ) ; const text = `sudo bash -c "$(curl -fsSL '${ bashUrl }')"` ; return { text , expires , } ; }