@@ -19,6 +19,10 @@ import { Configuration, PolicyResponse } from "./interfaces";
19
19
import { fetchPolicy , mergeConfigs } from "./policy-utils" ;
20
20
import * as cache from "@actions/cache" ;
21
21
import { getCacheEntry } from "@actions/cache/lib/internal/cacheHttpClient" ;
22
+ import * as cacheTwirpClient from "@actions/cache/lib/internal/shared/cacheTwirpClient" ;
23
+ import { GetCacheEntryDownloadURLRequest } from "@actions/cache/lib/generated/results/api/v1/cache" ;
24
+ import { getCacheServiceVersion } from "@actions/cache/lib/internal/config" ;
25
+
22
26
import * as utils from "@actions/cache/lib/internal/cacheUtils" ;
23
27
import { isArcRunner , sendAllowedEndpoints } from "./arc-runner" ;
24
28
import { STEPSECURITY_API_URL , STEPSECURITY_WEB_URL } from "./configs" ;
@@ -114,28 +118,78 @@ interface MonitorResponse {
114
118
} catch ( exception ) {
115
119
console . log ( exception ) ;
116
120
}
117
- try {
118
- const compressionMethod : CompressionMethod =
119
- await utils . getCompressionMethod ( ) ;
120
- const cacheFilePath = path . join ( __dirname , "cache.txt" ) ;
121
- core . info ( `cacheFilePath ${ cacheFilePath } ` ) ;
122
- const cacheEntry : ArtifactCacheEntry = await getCacheEntry (
123
- [ cacheKey ] ,
124
- [ cacheFilePath ] ,
125
- {
126
- compressionMethod : compressionMethod ,
121
+
122
+ const cacheServiceVersion : string = getCacheServiceVersion ( ) ;
123
+
124
+ switch ( cacheServiceVersion ) {
125
+ case "v2" :
126
+ core . info ( `cache version: v2` ) ;
127
+ try {
128
+ const cacheFilePath = path . join ( __dirname , "cache.txt" ) ;
129
+ core . info ( `cacheFilePath ${ cacheFilePath } ` ) ;
130
+
131
+ const twirpClient = cacheTwirpClient . internalCacheTwirpClient ( ) ;
132
+ const compressionMethod = await utils . getCompressionMethod ( ) ;
133
+
134
+ const request : GetCacheEntryDownloadURLRequest = {
135
+ key : cacheKey ,
136
+ restoreKeys : [ ] ,
137
+ version : utils . getCacheVersion (
138
+ [ cacheFilePath ] ,
139
+ compressionMethod ,
140
+ false
141
+ ) ,
142
+ } ;
143
+
144
+ const response = await twirpClient . GetCacheEntryDownloadURL (
145
+ request
146
+ ) ;
147
+
148
+ const url = new URL ( response . signedDownloadUrl ) ;
149
+ core . info (
150
+ `Adding cacheHost: ${ url . hostname } :443 to allowed-endpoints`
151
+ ) ;
152
+
153
+ confg . allowed_endpoints += ` ${ url . hostname } :443` ;
154
+ } catch ( e ) {
155
+ core . info ( `Unable to fetch cacheURL ${ e } ` ) ;
156
+ if ( confg . egress_policy === "block" ) {
157
+ core . info ( "Switching egress-policy to audit mode" ) ;
158
+ confg . egress_policy = "audit" ;
159
+ }
160
+ }
161
+ break ;
162
+
163
+ case "v1" :
164
+ core . info ( `cache version: v1` ) ;
165
+
166
+ try {
167
+ const compressionMethod : CompressionMethod =
168
+ await utils . getCompressionMethod ( ) ;
169
+ const cacheFilePath = path . join ( __dirname , "cache.txt" ) ;
170
+ core . info ( `cacheFilePath ${ cacheFilePath } ` ) ;
171
+
172
+ const cacheEntry : ArtifactCacheEntry = await getCacheEntry (
173
+ [ cacheKey ] ,
174
+ [ cacheFilePath ] ,
175
+ {
176
+ compressionMethod : compressionMethod ,
177
+ }
178
+ ) ;
179
+ const url = new URL ( cacheEntry . archiveLocation ) ;
180
+ core . info (
181
+ `Adding cacheHost: ${ url . hostname } :443 to allowed-endpoints`
182
+ ) ;
183
+
184
+ confg . allowed_endpoints += ` ${ url . hostname } :443` ;
185
+ } catch ( exception ) {
186
+ // some exception has occurred.
187
+ core . info ( `Unable to fetch cacheURL ${ exception } ` ) ;
188
+ if ( confg . egress_policy === "block" ) {
189
+ core . info ( "Switching egress-policy to audit mode" ) ;
190
+ confg . egress_policy = "audit" ;
191
+ }
127
192
}
128
- ) ;
129
- const url = new URL ( cacheEntry . archiveLocation ) ;
130
- core . info ( `Adding cacheHost: ${ url . hostname } :443 to allowed-endpoints` ) ;
131
- confg . allowed_endpoints += ` ${ url . hostname } :443` ;
132
- } catch ( exception ) {
133
- // some exception has occurred.
134
- core . info ( `Unable to fetch cacheURL` ) ;
135
- if ( confg . egress_policy === "block" ) {
136
- core . info ( "Switching egress-policy to audit mode" ) ;
137
- confg . egress_policy = "audit" ;
138
- }
139
193
}
140
194
}
141
195
0 commit comments