77} from '@console/dynamic-plugin-sdk/src' ;
88import { RouteModel } from '@console/internal/models' ;
99import { k8sGet } from '@console/internal/module/k8s' ;
10- import { consoleProxyFetchJSON } from '@console/shared/src/utils/proxy' ;
10+ import { consoleProxyFetch , consoleProxyFetchJSON } from '@console/shared/src/utils/proxy' ;
1111import {
1212 DELETED_RESOURCE_IN_K8S_ANNOTATION ,
1313 RESOURCE_LOADED_FROM_RESULTS_ANNOTATION ,
@@ -23,7 +23,7 @@ import { PipelineRunKind, TaskRunKind } from '../../../types';
2323const MINIMUM_PAGE_SIZE = 5 ;
2424const MAXIMUM_PAGE_SIZE = 10000 ;
2525
26- export type Record = {
26+ export type ResultRecord = {
2727 name : string ;
2828 uid : string ;
2929 createTime : string ;
@@ -43,9 +43,18 @@ export type Log = {
4343 } ;
4444} ;
4545
46+ type ProxyRequest = {
47+ allowInsecure ?: boolean ;
48+ method : string ;
49+ url : string ;
50+ headers ?: Record < string , string [ ] > ;
51+ queryparams ?: Record < string , string [ ] > ;
52+ body ?: string ;
53+ } ;
54+
4655export type RecordsList = {
4756 nextPageToken ?: string ;
48- records : Record [ ] ;
57+ records : ResultRecord [ ] ;
4958} ;
5059
5160export type TektonResultsOptions = {
@@ -346,13 +355,28 @@ export const getTaskRuns = (
346355 cacheKey ?: string ,
347356) => getFilteredTaskRuns ( namespace , '' , options , nextPageToken , cacheKey ) ;
348357
358+ const isJSONString = ( str : string ) : boolean => {
359+ try {
360+ JSON . parse ( str ) ;
361+ } catch ( e ) {
362+ return false ;
363+ }
364+ return true ;
365+ } ;
366+
367+ export const consoleProxyFetchLog = < T > ( proxyRequest : ProxyRequest ) : Promise < T > => {
368+ return consoleProxyFetch ( proxyRequest ) . then ( ( response ) => {
369+ return isJSONString ( response . body ) ? JSON . parse ( response . body ) : response . body ;
370+ } ) ;
371+ } ;
372+
349373const getLog = async ( taskRunPath : string ) => {
350374 const tektonResultUrl = await getTRURLHost ( ) ;
351375 const url = `https://${ tektonResultUrl } /apis/results.tekton.dev/v1alpha2/parents/${ taskRunPath . replace (
352376 '/records/' ,
353377 '/logs/' ,
354378 ) } `;
355- return consoleProxyFetchJSON ( { url, method : 'GET' , allowInsecure : true } ) ;
379+ return consoleProxyFetchLog ( { url, method : 'GET' , allowInsecure : true } ) ;
356380} ;
357381
358382export const getTaskRunLog = ( namespace : string , taskRunName : string ) : Promise < string > =>
@@ -364,6 +388,8 @@ export const getTaskRunLog = (namespace: string, taskRunName: string): Promise<s
364388 ) . then ( ( x ) =>
365389 x ?. [ 1 ] ?. records . length > 0
366390 ? // eslint-disable-next-line promise/no-nesting
367- getLog ( x ?. [ 1 ] ?. records [ 0 ] . name ) . then ( ( response : Log ) => decodeValue ( response . result . data ) )
391+ getLog ( x ?. [ 1 ] ?. records [ 0 ] . name ) . then ( ( response : string ) => {
392+ return response ;
393+ } )
368394 : throw404 ( ) ,
369395 ) ;
0 commit comments