@@ -10,12 +10,13 @@ import {
10
10
import { connectionTarget , terminalWithDocker , currentFile } from "../utils" ;
11
11
import { mainCommandMenu , mainSourceControlMenu } from "./studio" ;
12
12
import { AtelierAPI } from "../api" ;
13
+ import { getCSPToken } from "../utils/getCSPToken" ;
13
14
14
- type ServerAction = { detail : string ; id : string ; label : string } ;
15
+ type ServerAction = { detail : string ; id : string ; label : string ; rawLink ?: string } ;
15
16
export async function serverActions ( ) : Promise < void > {
16
17
const { apiTarget, configName : workspaceFolder } = connectionTarget ( ) ;
17
18
const api = new AtelierAPI ( apiTarget ) ;
18
- const { active, host = "" , ns = "" , https, port = 0 , pathPrefix, username , password , docker } = api . config ;
19
+ const { active, host = "" , ns = "" , https, port = 0 , pathPrefix, docker } = api . config ;
19
20
const explorerCount = ( await explorerProvider . getChildren ( ) ) . length ;
20
21
if ( ! explorerCount && ( ! docker || host === "" ) ) {
21
22
await vscode . commands . executeCommand ( "ObjectScriptExplorer.focus" ) ;
@@ -70,29 +71,24 @@ export async function serverActions(): Promise<void> {
70
71
const file = currentFile ( ) ;
71
72
const classname = file && file . name . toLowerCase ( ) . endsWith ( ".cls" ) ? file . name . slice ( 0 , - 4 ) : "" ;
72
73
const classnameEncoded = encodeURIComponent ( classname ) ;
73
- const connInfo = `${ host } :${ port } [${ nsEncoded } ]` ;
74
+ const connInfo = `${ host } :${ port } ${ pathPrefix } [${ nsEncoded } ]` ;
74
75
const serverUrl = `${ https ? "https" : "http" } ://${ host } :${ port } ${ pathPrefix } ` ;
75
- const portalUrl = `${ serverUrl } /csp/sys/UtilHome.csp?$NAMESPACE=${ nsEncoded } ` ;
76
- const classRef = `${ serverUrl } /csp/documatic/%25CSP.Documatic.cls?LIBRARY=${ nsEncoded } ${
76
+ const portalPath = `/csp/sys/UtilHome.csp?$NAMESPACE=${ nsEncoded } ` ;
77
+ const classRef = `/csp/documatic/%25CSP.Documatic.cls?LIBRARY=${ nsEncoded } ${
77
78
classname ? "&CLASSNAME=" + classnameEncoded : ""
78
79
} `;
79
- const iris = workspaceState . get ( workspaceFolder + ":iris" , false ) ;
80
- const usernameEncoded = encodeURIComponent ( username ) ;
81
- const passwordEncoded = encodeURIComponent ( password ) ;
82
- const auth = iris
83
- ? `&IRISUsername=${ usernameEncoded } &IRISPassword=${ passwordEncoded } `
84
- : `&CacheUserName=${ usernameEncoded } &CachePassword=${ passwordEncoded } ` ;
85
80
let extraLinks = 0 ;
86
81
for ( const title in links ) {
87
- let link = String ( links [ title ] ) ;
88
- if ( classname == "" && ( link . includes ( "${classname}" ) || link . includes ( "${classnameEncoded}" ) ) ) {
82
+ const rawLink = String ( links [ title ] ) ;
83
+ // Skip link if it requires a classname and we don't currently have one
84
+ if ( classname == "" && ( rawLink . includes ( "${classname}" ) || rawLink . includes ( "${classnameEncoded}" ) ) ) {
89
85
continue ;
90
86
}
91
- link = link
87
+ const link = rawLink
92
88
. replace ( "${host}" , host )
93
89
. replace ( "${port}" , port . toString ( ) )
94
90
. replace ( "${serverUrl}" , serverUrl )
95
- . replace ( "${serverAuth}" , auth )
91
+ . replace ( "${serverAuth}" , "" )
96
92
. replace ( "${ns}" , nsEncoded )
97
93
. replace ( "${namespace}" , ns == "%SYS" ? "sys" : nsEncoded . toLowerCase ( ) )
98
94
. replace ( "${classname}" , classname )
@@ -101,6 +97,7 @@ export async function serverActions(): Promise<void> {
101
97
id : "extraLink" + extraLinks ++ ,
102
98
label : title ,
103
99
detail : link ,
100
+ rawLink,
104
101
} ) ;
105
102
}
106
103
if ( workspaceState . get ( workspaceFolder + ":docker" , false ) ) {
@@ -113,12 +110,12 @@ export async function serverActions(): Promise<void> {
113
110
actions . push ( {
114
111
id : "openPortal" ,
115
112
label : "Open Management Portal" ,
116
- detail : portalUrl ,
113
+ detail : serverUrl + portalPath ,
117
114
} ) ;
118
115
actions . push ( {
119
116
id : "openClassReference" ,
120
117
label : "Open Class Reference" + ( classname ? ` for ${ classname } ` : "" ) ,
121
- detail : classRef ,
118
+ detail : serverUrl + classRef ,
122
119
} ) ;
123
120
if (
124
121
! vscode . window . activeTextEditor ||
@@ -141,17 +138,21 @@ export async function serverActions(): Promise<void> {
141
138
placeHolder : `Select action for server: ${ connInfo } ` ,
142
139
} )
143
140
. then ( connectionActionsHandler )
144
- . then ( ( action ) => {
141
+ . then ( async ( action ) => {
145
142
if ( ! action ) {
146
143
return ;
147
144
}
148
145
switch ( action . id ) {
149
146
case "openPortal" : {
150
- vscode . env . openExternal ( vscode . Uri . parse ( portalUrl + auth ) ) ;
147
+ const token = await getCSPToken ( api , portalPath ) ;
148
+ const urlString = `${ serverUrl } ${ portalPath } &CSPCHD=${ token } ` ;
149
+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
151
150
break ;
152
151
}
153
152
case "openClassReference" : {
154
- vscode . env . openExternal ( vscode . Uri . parse ( classRef + auth ) ) ;
153
+ const token = await getCSPToken ( api , classRef ) ;
154
+ const urlString = `${ serverUrl } ${ classRef } &CSPCHD=${ token } ` ;
155
+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
155
156
break ;
156
157
}
157
158
case "openDockerTerminal" : {
@@ -167,7 +168,15 @@ export async function serverActions(): Promise<void> {
167
168
break ;
168
169
}
169
170
default : {
170
- vscode . env . openExternal ( vscode . Uri . parse ( action . detail ) ) ;
171
+ let urlString = action . detail ;
172
+ if ( action . rawLink ?. startsWith ( "${serverUrl}" ) ) {
173
+ const path = vscode . Uri . parse ( urlString ) . path ;
174
+ const token = await getCSPToken ( api , path ) ;
175
+ if ( token . length > 0 ) {
176
+ urlString += `&CSPCHD=${ token } ` ;
177
+ }
178
+ }
179
+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
171
180
}
172
181
}
173
182
} ) ;
0 commit comments