@@ -154,6 +154,11 @@ func (a *ArtifactServer) GetArtifactFile(w http.ResponseWriter, r *http.Request)
154154 return
155155 }
156156
157+ a .getArtifactFromPath (artifact , driver , w , r )
158+
159+ }
160+
161+ func (a * ArtifactServer ) getArtifactFromPath (artifact * wfv1.Artifact , driver common.ArtifactDriver , w http.ResponseWriter , r * http.Request ) {
157162 isDir := strings .HasSuffix (r .URL .Path , "/" )
158163
159164 if ! isDir {
@@ -222,15 +227,13 @@ func (a *ArtifactServer) GetArtifactFile(w http.ResponseWriter, r *http.Request)
222227 } else { // stream the file itself
223228 log .Debugf ("not a directory, artifact: %+v" , artifact )
224229
225- err = a .returnArtifact (w , artifact , driver )
230+ err : = a .returnArtifact (w , artifact , driver )
226231
227232 if err != nil {
228233 a .httpFromError (err , w )
229234 }
230235 }
231-
232236}
233-
234237func (a * ArtifactServer ) getArtifact (w http.ResponseWriter , r * http.Request , isInput bool ) {
235238 requestPath := strings .SplitN (r .URL .Path , "/" , 6 )
236239 if len (requestPath ) != 6 {
@@ -300,24 +303,32 @@ func (a *ArtifactServer) getArtifactByManifest(w http.ResponseWriter, r *http.Re
300303 }
301304
302305 uid := wf .UID
303- path := strings .SplitN (r .URL .Path , "/" , 6 )
304- nodeId := path [2 ]
305- artifactName := path [3 ]
306-
307- log . WithFields (log. Fields { "uid" : uid , "nodeId" : nodeId , "artifactName" : artifactName , "isInput" : isInput }). Info ( "Download artifact by manifest" )
306+ requestPath := strings .SplitN (r .URL .Path , "/" , 6 )
307+ nodeId := requestPath [2 ]
308+ artifactName := requestPath [3 ]
309+ artifactNameIndex := 3
310+ fileNameFirstIndex := 4
308311
309- art , driver , err := a .getArtifactAndDriver (ctx , nodeId , artifactName , isInput , wf , nil )
310- if err != nil {
311- a .serverInternalError (err , w )
312+ var fileName * string
313+ if len (requestPath ) >= fileNameFirstIndex + 1 { // they included a file path in the URL (not just artifact name)
314+ joined := strings .Join (requestPath [fileNameFirstIndex :], "/" )
315+ // sanitize file name
316+ cleanedPath := path .Clean (joined )
317+ fileName = & cleanedPath
318+ } else if len (requestPath ) < artifactNameIndex + 1 {
319+ a .httpBadRequestError (w )
312320 return
313321 }
314322
315- err = a . returnArtifact ( w , art , driver )
323+ log . WithFields (log. Fields { "uid" : uid , "nodeId" : nodeId , "artifactName" : artifactName , "isInput" : isInput }). Info ( "Download artifact by manifest" )
316324
325+ art , driver , err := a .getArtifactAndDriver (ctx , nodeId , artifactName , isInput , wf , fileName )
317326 if err != nil {
318327 a .serverInternalError (err , w )
319328 return
320329 }
330+
331+ a .getArtifactFromPath (art , driver , w , r )
321332}
322333
323334func (a * ArtifactServer ) GetOutputArtifactByUID (w http.ResponseWriter , r * http.Request ) {
0 commit comments