import { generatePath } from 'react-router' ; import { merge } from 'lodash' ; import { AuthProvider , Auth2faType , PreferredMfaType } from 'shared/services' ; const cfg = { isEnterprise : false , isCloud : false , baseUrl : window . location . origin , auth : { localAuthEnabled : true , providers : [ ] as AuthProvider [ ] , second_factor : 'off' as Auth2faType , authType : 'local' , preferredLocalMfa : '' as PreferredMfaType , } , proxyCluster : 'localhost' , loc : { dateTimeFormat : 'YYYY-MM-DD HH:mm:ss' , dateFormat : 'YYYY-MM-DD' , } , routes : { root : '/web' , apps : '/web/cluster/:clusterId/apps' , appLauncher : '/web/launch/:fqdn/:clusterId?/:publicAddr?/:arn?' , support : '/web/support' , settings : '/web/settings' , account : '/web/account' , accountPassword : '/web/account/password' , accountMfaDevices : '/web/account/twofactor' , roles : '/web/roles' , sso : '/web/sso' , cluster : '/web/cluster/:clusterId/' , clusters : '/web/clusters' , trustedClusters : '/web/trust' , audit : '/web/cluster/:clusterId/audit' , nodes : '/web/cluster/:clusterId/nodes' , sessions : '/web/cluster/:clusterId/sessions' , recordings : '/web/cluster/:clusterId/recordings' , databases : '/web/cluster/:clusterId/databases' , desktops : '/web/cluster/:clusterId/desktops' , desktop : '/web/cluster/:clusterId/desktops/:desktopName/:username' , users : '/web/users' , console : '/web/cluster/:clusterId/console' , consoleNodes : '/web/cluster/:clusterId/console/nodes' , consoleConnect : '/web/cluster/:clusterId/console/node/:serverId/:login' , consoleSession : '/web/cluster/:clusterId/console/session/:sid' , player : '/web/cluster/:clusterId/session/:sid' , login : '/web/login' , loginSuccess : '/web/msg/info/login_success' , loginErrorLegacy : '/web/msg/error/login_failed' , loginError : '/web/msg/error/login' , loginErrorCallback : '/web/msg/error/login/callback' , loginErrorUnauthorized : '/web/msg/error/login/auth' , userInvite : '/web/invite/:tokenId' , userInviteContinue : '/web/invite/:tokenId/continue' , userReset : '/web/reset/:tokenId' , userResetContinue : '/web/reset/:tokenId/continue' , kubernetes : '/web/cluster/:clusterId/kubernetes' , oidcHandler : '/v1/webapi/oidc/*' , samlHandler : '/v1/webapi/saml/*' , githubHandler : '/v1/webapi/github/*' , } , api : { appSession : '/v1/webapi/sessions/app' , appFqdnPath : '/v1/webapi/apps/:fqdn/:clusterId?/:publicAddr?' , applicationsPath : '/v1/webapi/sites/:clusterId/apps' , clustersPath : '/v1/webapi/sites' , clusterEventsPath : `/v1/webapi/sites/:clusterId/events/search?from=:start?&to=:end?&limit=:limit?&startKey=:startKey?&include=:include?` , clusterEventsRecordingsPath : `/v1/webapi/sites/:clusterId/events/search/sessions?from=:start?&to=:end?&limit=:limit?&startKey=:startKey?` , scp : '/v1/webapi/sites/:clusterId/nodes/:serverId/:login/scp?location=:location&filename=:filename' , renewTokenPath : '/v1/webapi/sessions/renew' , resetPasswordTokenPath : '/v1/webapi/users/password/token' , sessionPath : '/v1/webapi/sessions' , userContextPath : '/v1/webapi/sites/:clusterId/context' , userStatusPath : '/v1/webapi/user/status' , passwordTokenPath : '/v1/webapi/users/password/token/:tokenId?' , changeUserPasswordPath : '/v1/webapi/users/password' , nodesPath : '/v1/webapi/sites/:clusterId/nodes' , databasesPath : `/v1/webapi/sites/:clusterId/databases` , desktopsPath : `/v1/webapi/sites/:clusterId/desktops` , desktopPath : `/v1/webapi/sites/:clusterId/desktops/:desktopName` , desktopWsAddr : 'wss://:fqdm/v1/webapi/sites/:clusterId/desktops/:desktopName/connect?access_token=:token&username=:username&width=:width&height=:height' , siteSessionPath : '/v1/webapi/sites/:siteId/sessions' , ttyWsAddr : 'wss://:fqdm/v1/webapi/sites/:clusterId/connect?access_token=:token&params=:params' , terminalSessionPath : '/v1/webapi/sites/:clusterId/sessions/:sid?' , kubernetesPath : '/v1/webapi/sites/:clusterId/kubernetes' , usersPath : '/v1/webapi/users' , usersDelete : '/v1/webapi/users/:username' , createPrivilegeTokenPath : '/v1/webapi/users/privilege/token' , rolesPath : '/v1/webapi/roles/:name?' , githubConnectorsPath : '/v1/webapi/github/:name?' , trustedClustersPath : '/v1/webapi/trustedcluster/:name?' , nodeTokenPath : '/v1/enterprise/nodes/token' , nodeScriptPath : '/scripts/:token/install-node.sh' , appNodeScriptPath : '/scripts/:token/install-app.sh?name=:name&uri=:uri' , mfaLoginBegin : '/v1/webapi/mfa/login/begin' , mfaLoginFinish : '/v1/webapi/mfa/login/finishsession' , mfaChangePasswordBegin : '/v1/webapi/mfa/authenticatechallenge/password' , mfaCreateRegistrationChallengePath : '/v1/webapi/mfa/token/:tokenId/registerchallenge' , mfaRegisterChallengeWithTokenPath : '/v1/webapi/mfa/token/:tokenId/registerchallenge' , mfaAuthnChallengePath : '/v1/webapi/mfa/authenticatechallenge' , mfaAuthnChallengeWithTokenPath : '/v1/webapi/mfa/token/:tokenId/authenticatechallenge' , mfaDevicesWithTokenPath : '/v1/webapi/mfa/token/:tokenId/devices' , mfaDevicesPath : '/v1/webapi/mfa/devices' , mfaDevicePath : '/v1/webapi/mfa/token/:tokenId/devices/:deviceName' , } , getAppFqdnUrl ( params ) { return generatePath ( cfg . api . appFqdnPath , { ... params } ) ; } , getClusterEventsUrl ( clusterId , params ) { return generatePath ( cfg . api . clusterEventsPath , { clusterId , ... params , } ) ; } , getClusterEventsRecordingsUrl ( clusterId , params ) { return generatePath ( cfg . api . clusterEventsRecordingsPath , { clusterId , ... params , } ) ; } , getAuthProviders ( ) { return cfg . auth && cfg . auth . providers ? cfg . auth . providers : [ ] ; } , getAuth2faType ( ) { return cfg . auth ? cfg . auth . second_factor : null ; } , getPreferredMfaType ( ) { return cfg . auth ? cfg . auth . preferredLocalMfa : null ; } , getLocalAuthFlag ( ) { return cfg . auth . localAuthEnabled ; } , getAuthType ( ) { return cfg . auth . authType ; } , getSsoUrl ( providerUrl , providerName , redirect ) { return cfg . baseUrl + generatePath ( providerUrl , { redirect , providerName } ) ; } , getAuditRoute ( clusterId ) { return generatePath ( cfg . routes . audit , { clusterId } ) ; } , getNodesRoute ( clusterId ) { return generatePath ( cfg . routes . nodes , { clusterId } ) ; } , getDatabasesRoute ( clusterId ) { return generatePath ( cfg . routes . databases , { clusterId } ) ; } , getDesktopsRoute ( clusterId ) { return generatePath ( cfg . routes . desktops , { clusterId } ) ; } , getNodeJoinTokenUrl ( ) { return cfg . api . nodeTokenPath ; } , getNodeScriptUrl ( token ) { return cfg . baseUrl + generatePath ( cfg . api . nodeScriptPath , { token } ) ; } , getAppNodeScriptUrl ( token , name , uri ) { return ( cfg . baseUrl + generatePath ( cfg . api . appNodeScriptPath , { token , name , uri } ) ) ; } , getUsersRoute ( ) { const clusterId = cfg . proxyCluster ; return generatePath ( cfg . routes . users , { clusterId } ) ; } , getAppsRoute ( clusterId ) { return generatePath ( cfg . routes . apps , { clusterId } ) ; } , getSessionsRoute ( clusterId ) { return generatePath ( cfg . routes . sessions , { clusterId } ) ; } , getRecordingsRoute ( clusterId ) { return generatePath ( cfg . routes . recordings , { clusterId } ) ; } , getConsoleNodesRoute ( clusterId ) { return generatePath ( cfg . routes . consoleNodes , { clusterId , } ) ; } , getSshConnectRoute ( { clusterId , login , serverId } ) { return generatePath ( cfg . routes . consoleConnect , { clusterId , serverId , login , } ) ; } , getDesktopRoute ( { clusterId , username , desktopName } ) { return generatePath ( cfg . routes . desktop , { clusterId , desktopName , username , } ) ; } , getSshSessionRoute ( { clusterId , sid } ) { return generatePath ( cfg . routes . consoleSession , { clusterId , sid } ) ; } , getPasswordTokenUrl ( tokenId ? ) { return generatePath ( cfg . api . passwordTokenPath , { tokenId } ) ; } , getClusterRoute ( clusterId ) { return generatePath ( cfg . routes . cluster , { clusterId } ) ; } , getConsoleRoute ( clusterId ) { return generatePath ( cfg . routes . console , { clusterId } ) ; } , getAppLauncherRoute ( params ) { return generatePath ( cfg . routes . appLauncher , { ... params } ) ; } , getPlayerRoute ( params ) { return generatePath ( cfg . routes . player , { ... params } ) ; } , getUserContextUrl ( ) { const clusterId = cfg . proxyCluster ; return generatePath ( cfg . api . userContextPath , { clusterId } ) ; } , getUserResetTokenRoute ( tokenId = '' , invite = true ) { const route = invite ? cfg . routes . userInvite : cfg . routes . userReset ; return cfg . baseUrl + generatePath ( route , { tokenId } ) ; } , getUserResetTokenContinueRoute ( tokenId = '' ) { return generatePath ( cfg . routes . userResetContinue , { tokenId } ) ; } , getUserInviteTokenRoute ( tokenId = '' ) { return generatePath ( cfg . routes . userInvite , { tokenId } ) ; } , getUserInviteTokenContinueRoute ( tokenId = '' ) { return generatePath ( cfg . routes . userInviteContinue , { tokenId } ) ; } , getKubernetesRoute ( clusterId ) { return generatePath ( cfg . routes . kubernetes , { clusterId } ) ; } , getUsersUrl ( ) { return cfg . api . usersPath ; } , getUsersDeleteUrl ( username = '' ) { return generatePath ( cfg . api . usersDelete , { username } ) ; } , getTerminalSessionUrl ( { clusterId , sid } ) { return generatePath ( cfg . api . terminalSessionPath , { clusterId , sid } ) ; } , getClusterNodesUrl ( clusterId ) { return generatePath ( cfg . api . nodesPath , { clusterId } ) ; } , getDatabasesUrl ( clusterId ) { return generatePath ( cfg . api . databasesPath , { clusterId } ) ; } , getDesktopsUrl ( clusterId ) { return generatePath ( cfg . api . desktopsPath , { clusterId } ) ; } , getDesktopUrl ( clusterId , desktopName ) { return generatePath ( cfg . api . desktopPath , { clusterId , desktopName } ) ; } , getApplicationsUrl ( clusterId ) { return generatePath ( cfg . api . applicationsPath , { clusterId } ) ; } , getScpUrl ( params ) { return generatePath ( cfg . api . scp , { ... params , } ) ; } , getRenewTokenUrl ( ) { return cfg . api . renewTokenPath ; } , getGithubConnectorsUrl ( name ? ) { return generatePath ( cfg . api . githubConnectorsPath , { name } ) ; } , getTrustedClustersUrl ( name ? ) { return generatePath ( cfg . api . trustedClustersPath , { name } ) ; } , getRolesUrl ( name ? ) { return generatePath ( cfg . api . rolesPath , { name } ) ; } , getKubernetesUrl ( clusterId ) { return generatePath ( cfg . api . kubernetesPath , { clusterId } ) ; } , getAuthnChallengeWithTokenUrl ( tokenId ) { return generatePath ( cfg . api . mfaAuthnChallengeWithTokenPath , { tokenId , } ) ; } , getMfaDevicesWithTokenUrl ( tokenId ) { return generatePath ( cfg . api . mfaDevicesWithTokenPath , { tokenId } ) ; } , getMfaDeviceUrl ( tokenId , deviceName ) { return generatePath ( cfg . api . mfaDevicePath , { tokenId , deviceName } ) ; } , getMfaCreateRegistrationChallengeUrl ( tokenId ) { return generatePath ( cfg . api . mfaCreateRegistrationChallengePath , { tokenId , } ) ; } , init ( backendConfig = { } ) { merge ( this , backendConfig ) ; } , } ; export interface UrlParams { clusterId : string ; sid ? : string ; login ? : string ; serverId ? : string ; } export interface UrlAppParams { fqdn : string ; clusterId ? : string ; publicAddr ? : string ; arn ? : string ; } export interface UrlScpParams { clusterId : string ; serverId : string ; login : string ; location : string ; filename : string ; } export interface UrlSshParams { login ? : string ; serverId ? : string ; sid ? : string ; clusterId : string ; } export interface UrlSessionRecordingsParams { start : string ; end : string ; limit ? : number ; startKey ? : string ; } export interface UrlClusterEventsParams { start : string ; end : string ; limit ? : number ; include ? : string ; startKey ? : string ; } export interface UrlLauncherParams { fqdn : string ; clusterId ? : string ; publicAddr ? : string ; arn ? : string ; } export interface UrlPlayerParams { clusterId : string ; sid : string ; } export interface UrlDesktopParams { username ? : string ; desktopName ? : string ; clusterId : string ; } export default cfg ;