33
44import { workspace } from 'vscode' ;
55import { logger } from '../../platform/logging' ;
6- import * as https from 'https' ;
76import fetch from 'node-fetch' ;
87
98/**
@@ -36,34 +35,6 @@ function getApiEndpoint(): string {
3635 return config . get < string > ( 'apiEndpoint' , 'https://api.deepnote.com' ) ;
3736}
3837
39- /**
40- * Checks if SSL verification should be disabled
41- */
42- function shouldDisableSSLVerification ( ) : boolean {
43- const config = workspace . getConfiguration ( 'deepnote' ) ;
44- return config . get < boolean > ( 'disableSSLVerification' , false ) ;
45- }
46-
47- /**
48- * Creates an HTTPS agent with optional SSL verification disabled
49- */
50- function createHttpsAgent ( ) : https . Agent | undefined {
51- if ( shouldDisableSSLVerification ( ) ) {
52- logger . warn ( 'SSL certificate verification is disabled. This should only be used in development.' ) ;
53- // Create agent with options that bypass both certificate and hostname verification
54- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55- const agentOptions : any = {
56- rejectUnauthorized : false ,
57- checkServerIdentity : ( ) => {
58- // Return undefined to indicate the check passed
59- return undefined ;
60- }
61- } ;
62- return new https . Agent ( agentOptions ) ;
63- }
64- return undefined ;
65- }
66-
6738/**
6839 * Initializes an import by requesting a presigned upload URL
6940 *
@@ -76,70 +47,29 @@ export async function initImport(fileName: string, fileSize: number): Promise<In
7647 const apiEndpoint = getApiEndpoint ( ) ;
7748 const url = `${ apiEndpoint } /v1/import/init` ;
7849
79- // Temporarily disable SSL verification at the process level if configured
80- const originalEnvValue = process . env . NODE_TLS_REJECT_UNAUTHORIZED ;
81- if ( shouldDisableSSLVerification ( ) ) {
82- process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
83- logger . debug ( 'Set NODE_TLS_REJECT_UNAUTHORIZED=0' ) ;
84- }
85-
86- try {
87- const agent = createHttpsAgent ( ) ;
88- logger . debug ( `SSL verification disabled: ${ shouldDisableSSLVerification ( ) } ` ) ;
89- logger . debug ( `Agent created: ${ ! ! agent } ` ) ;
90- if ( agent ) {
91- // eslint-disable-next-line @typescript-eslint/no-explicit-any
92- logger . debug ( `Agent rejectUnauthorized: ${ ( agent as any ) . options ?. rejectUnauthorized } ` ) ;
93- }
50+ const response = await fetch ( url , {
51+ method : 'POST' ,
52+ headers : {
53+ 'Content-Type' : 'application/json'
54+ } ,
55+ body : JSON . stringify ( {
56+ fileName,
57+ fileSize
58+ } )
59+ } ) ;
9460
95- interface FetchOptions {
96- method : string ;
97- headers : Record < string , string > ;
98- body : string ;
99- agent ?: https . Agent ;
100- }
61+ if ( ! response . ok ) {
62+ const responseBody = await response . text ( ) ;
63+ logger . error ( `Init import failed - Status: ${ response . status } , URL: ${ url } , Body: ${ responseBody } ` ) ;
10164
102- const options : FetchOptions = {
103- method : 'POST' ,
104- headers : {
105- 'Content-Type' : 'application/json'
106- } ,
107- body : JSON . stringify ( {
108- fileName,
109- fileSize
110- } )
65+ const error : ApiError = {
66+ message : responseBody ,
67+ statusCode : response . status
11168 } ;
112-
113- if ( agent ) {
114- options . agent = agent ;
115- logger . debug ( 'Agent attached to request' ) ;
116- logger . debug ( `Options agent set: ${ ! ! options . agent } ` ) ;
117- }
118-
119- const response = await fetch ( url , options ) ;
120-
121- if ( ! response . ok ) {
122- const responseBody = await response . text ( ) ;
123- logger . error ( `Init import failed - Status: ${ response . status } , URL: ${ url } , Body: ${ responseBody } ` ) ;
124-
125- const error : ApiError = {
126- message : responseBody ,
127- statusCode : response . status
128- } ;
129- throw error ;
130- }
131-
132- return await response . json ( ) ;
133- } finally {
134- // Restore original SSL verification setting
135- if ( shouldDisableSSLVerification ( ) ) {
136- if ( originalEnvValue === undefined ) {
137- delete process . env . NODE_TLS_REJECT_UNAUTHORIZED ;
138- } else {
139- process . env . NODE_TLS_REJECT_UNAUTHORIZED = originalEnvValue ;
140- }
141- }
69+ throw error ;
14270 }
71+
72+ return await response . json ( ) ;
14373}
14474
14575/**
0 commit comments