(
url: RequestInfo,
init: RequestInit,
timeout: number,
controller: AbortController,
schemes: { bearerAuth?: boolean; adminAPIKeyAuth?: boolean } = {
bearerAuth: true,
adminAPIKeyAuth: true,
},
)
| 966 | } |
| 967 | |
| 968 | protected async fetchWithAuth( |
| 969 | url: RequestInfo, |
| 970 | init: RequestInit, |
| 971 | timeout: number, |
| 972 | controller: AbortController, |
| 973 | schemes: { bearerAuth?: boolean; adminAPIKeyAuth?: boolean } = { |
| 974 | bearerAuth: true, |
| 975 | adminAPIKeyAuth: true, |
| 976 | }, |
| 977 | ): Promise<Response> { |
| 978 | if (this._workloadIdentityAuth && schemes.bearerAuth) { |
| 979 | const headers = init.headers as Headers; |
| 980 | const authHeader = headers.get('Authorization'); |
| 981 | if (!authHeader || authHeader === `Bearer ${WORKLOAD_IDENTITY_API_KEY_PLACEHOLDER}`) { |
| 982 | const token = await this._workloadIdentityAuth.getToken(); |
| 983 | headers.set('Authorization', `Bearer ${token}`); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | const response = await this.fetchWithTimeout(url, init, timeout, controller); |
| 988 | |
| 989 | return response; |
| 990 | } |
| 991 | |
| 992 | async fetchWithTimeout( |
| 993 | url: RequestInfo, |
no test coverage detected