@@ -35,27 +35,25 @@ async function verifyChecksum(filePath: string, expectedChecksum: string): Promi
3535
3636export async function downloadProxy ( version : string , targetPath : string = PATHS . PROXY_EXE ) {
3737 let downloadUrl : string | undefined ;
38- let checksumUrl : string | undefined ;
38+ let expectedChecksum : string | undefined ;
3939
4040 try {
4141 const releaseUrl = `https://api.github.com/repos/${ GITHUB_REPO } /releases/tags/${ version } ` ;
4242 const response = await axios . get ( releaseUrl ) ;
43- const assets = response . data . assets ;
44- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45- const asset = assets . find ( ( a : any ) => a . name === ASSET_NAME ) ;
46- // eslint-disable-next-line @typescript-eslint/no-explicit-any
47- const checksumAsset = assets . find ( ( a : any ) => a . name === CHECKSUM_ASSET_NAME ) ;
48-
49- if ( asset ) {
50- downloadUrl = asset . browser_download_url ;
51- }
5243
53- if ( checksumAsset ) {
54- checksumUrl = checksumAsset . browser_download_url ;
55- }
44+ // Google Cloud SQL Proxy v2 binaries are hosted on GCS
45+ downloadUrl = `https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/${ version } /${ ASSET_NAME } ` ;
46+
47+ // Extract checksum from release body
48+ const body = response . data . body ;
49+ // Regex to match: | [cloud-sql-proxy.x64.exe](...) | <hash> |
50+ const checksumRegex = new RegExp ( `\\| \\[${ ASSET_NAME . replace ( / \. / g, '\\.' ) } \\]\\(.*?\\) \\| ([a-f0-9]{64}) \\|` ) ;
51+ const match = body . match ( checksumRegex ) ;
5652
57- if ( ! downloadUrl ) {
58- throw new Error ( `Could not find asset ${ ASSET_NAME } in release ${ version } ` ) ;
53+ if ( match && match [ 1 ] ) {
54+ expectedChecksum = match [ 1 ] ;
55+ } else {
56+ logger . warn ( `Could not extract checksum for ${ ASSET_NAME } from release notes.` ) ;
5957 }
6058
6159 logger . info ( `Downloading ${ ASSET_NAME } from ${ downloadUrl } ...` ) ;
@@ -79,11 +77,9 @@ export async function downloadProxy(version: string, targetPath: string = PATHS.
7977
8078 logger . info ( 'Download complete.' ) ;
8179
82- if ( checksumUrl ) {
80+ if ( expectedChecksum ) {
8381 logger . info ( 'Verifying checksum...' ) ;
8482 try {
85- const checksumResponse = await axios . get ( checksumUrl ) ;
86- const expectedChecksum = checksumResponse . data . trim ( ) . split ( ' ' ) [ 0 ] ;
8783 const isValid = await verifyChecksum ( targetPath , expectedChecksum ) ;
8884
8985 if ( ! isValid ) {
@@ -96,6 +92,8 @@ export async function downloadProxy(version: string, targetPath: string = PATHS.
9692 await fs . remove ( targetPath ) ;
9793 throw err ;
9894 }
95+ } else {
96+ logger . warn ( 'Skipping checksum verification (checksum not found).' ) ;
9997 }
10098
10199 } catch ( error ) {
0 commit comments