From fbd2cd6a38cb1f9bc98c21a295e01d4abdcda4c8 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 9 Apr 2024 16:26:39 -0400 Subject: [PATCH 1/6] Update actions to use non-deprecated version of node.js --- .github/workflows/pull_request.yml | 6 +++--- .github/workflows/stale.yml | 2 +- .github/workflows/tag_release.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8bee9661a..34cdafb17 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -16,14 +16,14 @@ jobs: node-version: [18] steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Cache node modules id: cache-npm - uses: actions/cache@v3 + uses: actions/cache@v4 env: cache-name: cache-node-modules with: diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 5c5908ae1..c51527727 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -12,7 +12,7 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v9 with: days-before-issue-close: 14 days-before-issue-stale: 30 diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index d1bcac7d6..c2db0bd13 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -7,7 +7,7 @@ jobs: tag_release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: prod-stable - run: | From 7deeabcd0d1ba85a1311f5bdb9d04df8af6ef4c4 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 9 Apr 2024 12:43:33 -0400 Subject: [PATCH 2/6] Update CI workflow - Add codecov action - Update test command to use jest command line options --- .github/workflows/pull_request.yml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8bee9661a..9a7e19503 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,9 +1,13 @@ -# Run this workflow for PRs only. Travis is required to push via insights-frontend-builder-common scripts - name: Pull request on: pull_request: - branches: [ main, master, prod-beta, prod-stable, stage-beta, stage-stable ] + branches: + - main + - master + - prod-beta + - prod-stable + - stage-beta + - stage-stable env: BRANCH: ${{ github.base_ref }} @@ -17,10 +21,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + - name: Setup Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} + - name: Cache node modules id: cache-npm uses: actions/cache@v3 @@ -34,13 +40,28 @@ jobs: ${{ runner.os }}-build-${{ env.cache-name }}- ${{ runner.os }}-build- ${{ runner.os }}- + - name: Install dependencies run: npm install + - name: Build run: npm run build + - name: Lint if: ${{ success() }} run: npm run lint + - name: Test if: ${{ success() }} - run: npm test --coverage --maxWorkers=4 + run: npm test -- --collect-coverage --max-workers=4 + + - name: Upload coverage report + if: ${{ success() }} + uses: codecov/codecov-action@v4.2.0 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + fail_ci_if_error: true + directory: coverage + plugin: pycoverage # Only run one plugin so that all do not run. There is no way to disable plugins entirely. + From d0fccecf3e37ee92df65a7658dad31a74f68da2d Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Tue, 9 Apr 2024 16:21:31 -0400 Subject: [PATCH 3/6] Update README --- README.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a28e74122..ea663f30e 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,22 @@ # Koku UI -[![AGPLv3][license-badge]][license] -[![Build Status][build-badge]][build] +[![Apache 2.0][license-badge]](https://github.com/project-koku/koku-ui/blob/main/LICENSE) +[![CI Status][build-badge]](https://github.com/project-koku/koku-ui/actions/workflows/tag_release.yml) +[![codecov][codecov-badge]](https://codecov.io/gh/project-koku/koku-ui) React.js app for Cost Management. -User interface is based on Patternfly [![Patternfly][pf-logo]][patternfly] +User interface is based on [Patternfly]. -To submit an issue, please visit https://issues.redhat.com/projects/COST/ +Submit issues in [Jira]. ## Requirements * [NodeJS v18.15+][nodejs] * [npm v9.5+][npm] -## Setup /etc/hosts entries (do this once) +## Setup `hosts` entries (do this once) -Edit the /etc/hosts file and add the following entries +Edit the `/etc/hosts` file and add the following entries ``` 127.0.0.1 prod.foo.redhat.com 127.0.0.1 stage.foo.redhat.com @@ -28,7 +29,7 @@ sudo bash scripts/patch-etc-hosts.sh ## Getting Started 1. Install requirements listed above. -2. Setup /etc/hosts entries listed above. +2. Setup `/etc/hosts` entries listed above. 3. Clone the repository, and open a terminal in the base of this project. 4. Run the command `npm install` to install all the dependencies. @@ -109,7 +110,7 @@ npm start:static npm start:csb:mfe ``` -## Running local instances of Koku UI & Koku API +## Running local instances of Koku UI and Koku API #### Koku UI 1. Start development server (Answer `yes` to run against local APIs) @@ -193,14 +194,14 @@ http://localhost:1337/beta/settings/applications/cost-management This [RELEASE][release-doc] doc describes how to release Koku UI to each staging environment. -[build]: https://travis-ci.com/project-koku/UI' -[build-badge]: https://img.shields.io/travis/project-koku/koku-ui.svg?style=for-the-badge +[build-badge]: https://github.com/project-koku/koku-ui/actions/workflows/tag_release.yml/badge.svg +[license-badge]: https://img.shields.io/github/license/project-koku/koku-ui.svg?longCache=true +[codecov-badge]: https://codecov.io/gh/project-koku/koku-ui/graph/badge.svg?token=1hjFIy1cRe + [koku-readme]: https://github.com/project-koku/koku#readme -[license-badge]: https://img.shields.io/github/license/project-koku/koku-ui.svg?longCache=true&style=for-the-badge -[license]: https://github.com/project-koku/koku-ui/blob/main/LICENSE [nodejs]: https://nodejs.org/en/ [patch-etc-hosts]: https://github.com/RedHatInsights/insights-proxy/blob/master/scripts/patch-etc-hosts.sh -[pf-logo]: https://www.patternfly.org/v4/images/logo.4189e7eb1a0741ea2b3b51b80d33c4cb.svg -[patternfly]: https://www.patternfly.org/ +[Patternfly]: https://www.patternfly.org/ [release-doc]: https://github.com/project-koku/koku-ui/blob/main/RELEASE.md -[npm]: https://https://www.npmjs.com/ +[npm]: https://www.npmjs.com/ +[Jira]: https://issues.redhat.com/projects/COST/ From 10bf572da0fb1438695118c9d10c5359943d6390 Mon Sep 17 00:00:00 2001 From: Dan Labrecque Date: Wed, 10 Apr 2024 11:27:53 -0400 Subject: [PATCH 4/6] Optimizations requires Axios to be a shared federated module https://issues.redhat.com/browse/COST-4890 --- fec.config.js | 1 - src/api/accountSettings.ts | 6 +++--- src/api/api.ts | 23 ++++++++++++++++++----- src/api/costModels.test.ts | 12 ++++++------ src/api/costModels.ts | 12 ++++++------ src/api/export/awsExport.ts | 4 ++-- src/api/export/awsOcpExport.ts | 4 ++-- src/api/export/azureExport.ts | 4 ++-- src/api/export/azureOcpExport.ts | 4 ++-- src/api/export/gcpExport.ts | 4 ++-- src/api/export/gcpOcpExport.ts | 4 ++-- src/api/export/ibmExport.ts | 4 ++-- src/api/export/ociExport.ts | 4 ++-- src/api/export/ocpCloudExport.ts | 4 ++-- src/api/export/ocpExport.ts | 4 ++-- src/api/export/rhelExport.ts | 4 ++-- src/api/forecasts/awsForecast.ts | 4 ++-- src/api/forecasts/awsOcpForecast.ts | 4 ++-- src/api/forecasts/azureForecast.ts | 4 ++-- src/api/forecasts/azureOcpForecast.ts | 4 ++-- src/api/forecasts/gcpForecast.ts | 4 ++-- src/api/forecasts/gcpOcpForecast.ts | 4 ++-- src/api/forecasts/ibmForecast.ts | 4 ++-- src/api/forecasts/ociForecast.ts | 4 ++-- src/api/forecasts/ocpCloudForecast.ts | 4 ++-- src/api/forecasts/ocpForecast.ts | 4 ++-- src/api/forecasts/rhelForecast.ts | 4 ++-- src/api/index.ts | 2 +- src/api/metrics.test.ts | 6 +++--- src/api/metrics.ts | 4 ++-- src/api/orgs/awsOrgs.test.ts | 4 ++-- src/api/orgs/awsOrgs.ts | 4 ++-- src/api/providers.test.ts | 6 +++--- src/api/providers.ts | 4 ++-- src/api/rates.test.ts | 6 +++--- src/api/rates.ts | 4 ++-- src/api/reports/awsOcpReports.test.ts | 4 ++-- src/api/reports/awsOcpReports.ts | 4 ++-- src/api/reports/awsReports.test.ts | 4 ++-- src/api/reports/awsReports.ts | 4 ++-- src/api/reports/azureOcpReports.test.ts | 4 ++-- src/api/reports/azureOcpReports.ts | 4 ++-- src/api/reports/azureReports.test.ts | 4 ++-- src/api/reports/azureReports.ts | 4 ++-- src/api/reports/gcpOcpReports.test.ts | 4 ++-- src/api/reports/gcpOcpReports.ts | 4 ++-- src/api/reports/gcpReports.test.ts | 4 ++-- src/api/reports/gcpReports.ts | 4 ++-- src/api/reports/ibmReports.test.ts | 4 ++-- src/api/reports/ibmReports.ts | 4 ++-- src/api/reports/ociReports.test.ts | 4 ++-- src/api/reports/ociReports.ts | 4 ++-- src/api/reports/ocpCloudReports.test.ts | 4 ++-- src/api/reports/ocpCloudReports.ts | 4 ++-- src/api/reports/ocpReports.test.ts | 4 ++-- src/api/reports/ocpReports.ts | 4 ++-- src/api/reports/rhelReports.test.ts | 4 ++-- src/api/reports/rhelReports.ts | 4 ++-- src/api/resources/awsOcpResource.ts | 4 ++-- src/api/resources/awsResource.ts | 4 ++-- src/api/resources/azureOcpResource.ts | 4 ++-- src/api/resources/azureResource.ts | 4 ++-- src/api/resources/gcpOcpResource.ts | 4 ++-- src/api/resources/gcpResource.ts | 4 ++-- src/api/resources/ibmResource.ts | 4 ++-- src/api/resources/ociResource.ts | 4 ++-- src/api/resources/ocpResource.ts | 4 ++-- src/api/resources/rhelResource.ts | 4 ++-- src/api/settings.ts | 6 +++--- src/api/tags/awsOcpTags.ts | 4 ++-- src/api/tags/awsTags.test.ts | 4 ++-- src/api/tags/awsTags.ts | 4 ++-- src/api/tags/azureOcpTags.ts | 4 ++-- src/api/tags/azureTags.test.ts | 4 ++-- src/api/tags/azureTags.ts | 4 ++-- src/api/tags/gcpOcpTags.test.ts | 4 ++-- src/api/tags/gcpOcpTags.ts | 4 ++-- src/api/tags/gcpTags.test.ts | 4 ++-- src/api/tags/gcpTags.ts | 4 ++-- src/api/tags/ibmTags.test.ts | 4 ++-- src/api/tags/ibmTags.ts | 4 ++-- src/api/tags/ociTags.test.ts | 4 ++-- src/api/tags/ociTags.ts | 4 ++-- src/api/tags/ocpCloudTags.ts | 4 ++-- src/api/tags/ocpTags.test.ts | 4 ++-- src/api/tags/ocpTags.ts | 4 ++-- src/api/tags/rhelTags.ts | 4 ++-- src/api/userAccess.test.ts | 6 +++--- src/api/userAccess.ts | 4 ++-- src/appEntry.tsx | 6 ------ src/store/store.ts | 4 ++-- 91 files changed, 207 insertions(+), 201 deletions(-) diff --git a/fec.config.js b/fec.config.js index 4d163d5e2..e36a70737 100644 --- a/fec.config.js +++ b/fec.config.js @@ -59,7 +59,6 @@ module.exports = { * Package can be re-enabled for sharing once chrome starts providing global routing package to all applications */ // exclude: ['react-router-dom'], - exclude: ['axios'], // Setting the base URL affects Cost Management APIs in OCM, when navigating between apps exposes: { './RootApp': path.resolve(__dirname, './src/appEntry.tsx'), }, diff --git a/src/api/accountSettings.ts b/src/api/accountSettings.ts index e3db80114..59405dca3 100644 --- a/src/api/accountSettings.ts +++ b/src/api/accountSettings.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedLinks, PagedMetaData } from './api'; @@ -38,10 +38,10 @@ export const AccountSettingsTypePaths: Partial(`${path}`); + return axiosInstance.get(`${path}`); } export function updateAccountSettings(settingsType: AccountSettingsType, payload: AccountSettingsPayload) { const path = AccountSettingsTypePaths[settingsType]; - return axios.put(`${path}`, payload); + return axiosInstance.put(`${path}`, payload); } diff --git a/src/api/api.ts b/src/api/api.ts index 6db48f3a3..bb5bf77a2 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,4 +1,4 @@ -import type { AxiosRequestConfig } from 'axios'; +import type { AxiosInstance, AxiosRequestConfig } from 'axios'; import axios from 'axios'; export interface PagedMetaData { @@ -18,10 +18,10 @@ export interface PagedResponse { data: D[]; } -export function initApi({ version }: { version: string }) { - axios.defaults.baseURL = `/api/cost-management/${version}/`; - axios.interceptors.request.use(authInterceptor); -} +// export function initApi({ version }: { version: string }) { +// axios.defaults.baseURL = `/api/cost-management/${version}/`; +// axios.interceptors.request.use(authInterceptor); +// } export function authInterceptor(reqConfig: AxiosRequestConfig) { return { @@ -31,3 +31,16 @@ export function authInterceptor(reqConfig: AxiosRequestConfig) { } as any, }; } + +// Create an instance instead of setting global defaults +// Setting global values affects Cost Management APIs in OCM and HCS, when navigating between apps +// +// See https://issues.redhat.com/browse/RHCLOUD-25573 +const axiosInstance: AxiosInstance = axios.create({ + baseURL: '/api/cost-management/v1/', + headers: { 'X-Custom-Header': 'foobar' }, +}); + +axiosInstance.interceptors.request.use(authInterceptor); + +export default axiosInstance; diff --git a/src/api/costModels.test.ts b/src/api/costModels.test.ts index 78b597787..79b82db71 100644 --- a/src/api/costModels.test.ts +++ b/src/api/costModels.test.ts @@ -1,17 +1,17 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { CostModelRequest } from './costModels'; import { addCostModel, deleteCostModel, fetchCostModels, updateCostModel } from './costModels'; test('api get cost models calls axios to costmodels', () => { fetchCostModels(); - expect(axios.get).toBeCalledWith('cost-models/'); + expect(axiosInstance.get).toBeCalledWith('cost-models/'); }); test('api get cost models calls axios to costmodels with query', () => { const query = 'limit=20&offset=10'; fetchCostModels(query); - expect(axios.get).toBeCalledWith(`cost-models/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`cost-models/?${query}`); }); test('add cost model calls axios post', () => { @@ -33,7 +33,7 @@ test('add cost model calls axios post', () => { ], }; addCostModel(request); - expect(axios.post).toBeCalledWith('cost-models/', request); + expect(axiosInstance.post).toBeCalledWith('cost-models/', request); }); test('update cost model calls axios put', () => { @@ -55,10 +55,10 @@ test('update cost model calls axios put', () => { ], }; updateCostModel('123abc456def', request); - expect(axios.put).toBeCalledWith('cost-models/123abc456def/', request); + expect(axiosInstance.put).toBeCalledWith('cost-models/123abc456def/', request); }); test('delete cost model calls axios delete', () => { deleteCostModel('123abc456def'); - expect(axios.delete).toBeCalledWith('cost-models/123abc456def/'); + expect(axiosInstance.delete).toBeCalledWith('cost-models/123abc456def/'); }); diff --git a/src/api/costModels.ts b/src/api/costModels.ts index 2a0c3a178..3687b4951 100644 --- a/src/api/costModels.ts +++ b/src/api/costModels.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedResponse } from './api'; import type { Rate, RateRequest } from './rates'; @@ -45,21 +45,21 @@ export interface CostModelRequest { export type CostModels = PagedResponse; export function fetchCostModels(query = '') { - return axios.get(`cost-models/${query && '?'}${query}`); + return axiosInstance.get(`cost-models/${query && '?'}${query}`); } export function fetchCostModel(uuid: string) { - return axios.get(`cost-models/${uuid}/`); + return axiosInstance.get(`cost-models/${uuid}/`); } export function addCostModel(request: CostModelRequest) { - return axios.post(`cost-models/`, request); + return axiosInstance.post(`cost-models/`, request); } export function updateCostModel(uuid: string, request: CostModelRequest) { - return axios.put(`cost-models/${uuid}/`, request); + return axiosInstance.put(`cost-models/${uuid}/`, request); } export function deleteCostModel(uuid: string) { - return axios.delete(`cost-models/${uuid}/`); + return axiosInstance.delete(`cost-models/${uuid}/`); } diff --git a/src/api/export/awsExport.ts b/src/api/export/awsExport.ts index e6be010f5..6574b7d4c 100644 --- a/src/api/export/awsExport.ts +++ b/src/api/export/awsExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/awsReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/awsOcpExport.ts b/src/api/export/awsOcpExport.ts index d9477d722..cff397c06 100644 --- a/src/api/export/awsOcpExport.ts +++ b/src/api/export/awsOcpExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/awsOcpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/azureExport.ts b/src/api/export/azureExport.ts index db7f29443..9d8292c8d 100644 --- a/src/api/export/azureExport.ts +++ b/src/api/export/azureExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/azureReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/azureOcpExport.ts b/src/api/export/azureOcpExport.ts index 6c71025ba..590d8e8db 100644 --- a/src/api/export/azureOcpExport.ts +++ b/src/api/export/azureOcpExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/azureOcpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/gcpExport.ts b/src/api/export/gcpExport.ts index 681905dc5..43b773a86 100644 --- a/src/api/export/gcpExport.ts +++ b/src/api/export/gcpExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/gcpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/gcpOcpExport.ts b/src/api/export/gcpOcpExport.ts index afeaf9179..530ea7d7d 100644 --- a/src/api/export/gcpOcpExport.ts +++ b/src/api/export/gcpOcpExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/gcpOcpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/ibmExport.ts b/src/api/export/ibmExport.ts index 3b2fd25c7..206f83a11 100644 --- a/src/api/export/ibmExport.ts +++ b/src/api/export/ibmExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/ibmReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/ociExport.ts b/src/api/export/ociExport.ts index 807d447ae..a499b0d13 100644 --- a/src/api/export/ociExport.ts +++ b/src/api/export/ociExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/ociReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/ocpCloudExport.ts b/src/api/export/ocpCloudExport.ts index 35b5b193d..44cb64fc0 100644 --- a/src/api/export/ocpCloudExport.ts +++ b/src/api/export/ocpCloudExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/ocpCloudReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/ocpExport.ts b/src/api/export/ocpExport.ts index 8037d8d1d..968a825af 100644 --- a/src/api/export/ocpExport.ts +++ b/src/api/export/ocpExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/ocpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/export/rhelExport.ts b/src/api/export/rhelExport.ts index 8037d8d1d..968a825af 100644 --- a/src/api/export/rhelExport.ts +++ b/src/api/export/rhelExport.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportTypePaths } from 'api/reports/ocpReports'; import type { ReportType } from 'api/reports/report'; -import axios from 'axios'; export function runExport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`, { + return axiosInstance.get(`${path}?${query}`, { headers: { Accept: 'text/csv', }, diff --git a/src/api/forecasts/awsForecast.ts b/src/api/forecasts/awsForecast.ts index 6c0a5b2a5..4b5d5429a 100644 --- a/src/api/forecasts/awsForecast.ts +++ b/src/api/forecasts/awsForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/awsOcpForecast.ts b/src/api/forecasts/awsOcpForecast.ts index 0c85cdac6..17aa5da6c 100644 --- a/src/api/forecasts/awsOcpForecast.ts +++ b/src/api/forecasts/awsOcpForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/azureForecast.ts b/src/api/forecasts/azureForecast.ts index a4493d6eb..5686424d5 100644 --- a/src/api/forecasts/azureForecast.ts +++ b/src/api/forecasts/azureForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/azureOcpForecast.ts b/src/api/forecasts/azureOcpForecast.ts index 8887594de..d58bb1676 100644 --- a/src/api/forecasts/azureOcpForecast.ts +++ b/src/api/forecasts/azureOcpForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/gcpForecast.ts b/src/api/forecasts/gcpForecast.ts index 9eb6900d1..336bcbcb2 100644 --- a/src/api/forecasts/gcpForecast.ts +++ b/src/api/forecasts/gcpForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/gcpOcpForecast.ts b/src/api/forecasts/gcpOcpForecast.ts index 1670d7517..cdf1af36e 100644 --- a/src/api/forecasts/gcpOcpForecast.ts +++ b/src/api/forecasts/gcpOcpForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/ibmForecast.ts b/src/api/forecasts/ibmForecast.ts index cfaf92f49..f102eff4e 100644 --- a/src/api/forecasts/ibmForecast.ts +++ b/src/api/forecasts/ibmForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/ociForecast.ts b/src/api/forecasts/ociForecast.ts index 1c1c235e5..3c4961b5a 100644 --- a/src/api/forecasts/ociForecast.ts +++ b/src/api/forecasts/ociForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/ocpCloudForecast.ts b/src/api/forecasts/ocpCloudForecast.ts index 09fa519de..51e2ac4f5 100644 --- a/src/api/forecasts/ocpCloudForecast.ts +++ b/src/api/forecasts/ocpCloudForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -9,5 +9,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/ocpForecast.ts b/src/api/forecasts/ocpForecast.ts index 57bbf1fd4..f0a5e65ef 100644 --- a/src/api/forecasts/ocpForecast.ts +++ b/src/api/forecasts/ocpForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -11,5 +11,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/forecasts/rhelForecast.ts b/src/api/forecasts/rhelForecast.ts index 57bbf1fd4..f0a5e65ef 100644 --- a/src/api/forecasts/rhelForecast.ts +++ b/src/api/forecasts/rhelForecast.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Forecast } from './forecast'; import { ForecastType } from './forecast'; @@ -11,5 +11,5 @@ export const ForecastTypePaths: Partial> = { export function runForecast(forecastType: ForecastType, query: string) { const path = ForecastTypePaths[forecastType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/index.ts b/src/api/index.ts index 42a45fae3..058268066 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1 +1 @@ -export { initApi } from './api'; +export { default as axiosInstance } from './api'; diff --git a/src/api/metrics.test.ts b/src/api/metrics.test.ts index db3fec740..143e87099 100644 --- a/src/api/metrics.test.ts +++ b/src/api/metrics.test.ts @@ -1,13 +1,13 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { fetchRateMetrics } from './metrics'; test('api get OpenShift metrics', () => { fetchRateMetrics('OCP'); - expect(axios.get).toBeCalledWith('metrics/?limit=20&source_type=OCP'); + expect(axiosInstance.get).toBeCalledWith('metrics/?limit=20&source_type=OCP'); }); test('api get all metrics', () => { fetchRateMetrics(); - expect(axios.get).toBeCalledWith('metrics/?limit=20'); + expect(axiosInstance.get).toBeCalledWith('metrics/?limit=20'); }); diff --git a/src/api/metrics.ts b/src/api/metrics.ts index c56e8af0b..e01463732 100644 --- a/src/api/metrics.ts +++ b/src/api/metrics.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedResponse } from './api'; @@ -20,5 +20,5 @@ export type Metrics = PagedResponse; export function fetchRateMetrics(source_type = '') { const query = source_type ? `&source_type=${source_type}` : ''; - return axios.get(`metrics/?limit=20${query}`); + return axiosInstance.get(`metrics/?limit=20${query}`); } diff --git a/src/api/orgs/awsOrgs.test.ts b/src/api/orgs/awsOrgs.test.ts index 54abdee8f..9ddf3b940 100644 --- a/src/api/orgs/awsOrgs.test.ts +++ b/src/api/orgs/awsOrgs.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runOrg } from './awsOrgs'; import { OrgType } from './org'; @@ -6,5 +6,5 @@ import { OrgType } from './org'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runOrg(OrgType.org, query); - expect(axios.get).toBeCalledWith(`organizations/aws/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`organizations/aws/?${query}`); }); diff --git a/src/api/orgs/awsOrgs.ts b/src/api/orgs/awsOrgs.ts index ab871d9c4..75d8ca143 100644 --- a/src/api/orgs/awsOrgs.ts +++ b/src/api/orgs/awsOrgs.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Org } from './org'; import { OrgType } from './org'; @@ -11,5 +11,5 @@ export const OrgTypePaths: Partial> = { export function runOrg(orgType: OrgType, query: string) { const path = OrgTypePaths[orgType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/providers.test.ts b/src/api/providers.test.ts index 9d42a4653..91931775a 100644 --- a/src/api/providers.test.ts +++ b/src/api/providers.test.ts @@ -1,11 +1,11 @@ +import { axiosInstance } from 'api'; import { getProvidersQuery } from 'api/queries/providersQuery'; -import axios from 'axios'; import { awsProvidersQuery } from 'store/providers/providersCommon'; import { fetchProviders } from './providers'; -test('api get provider calls axios.get', () => { +test('api get provider calls axiosInstance.get', () => { const query = getProvidersQuery(awsProvidersQuery); fetchProviders(query); - expect(axios.get).toBeCalledWith('sources/?limit=100&type=AWS'); + expect(axiosInstance.get).toBeCalledWith('sources/?limit=100&type=AWS'); }); diff --git a/src/api/providers.ts b/src/api/providers.ts index 249db649c..e10b7bf2f 100644 --- a/src/api/providers.ts +++ b/src/api/providers.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedMetaData, PagedResponse } from './api'; @@ -109,5 +109,5 @@ export const enum ProviderType { export function fetchProviders(query: string, reportType: ProviderType = undefined) { const separator = reportType === ProviderType.uuid ? '' : '?'; const queryString = query ? `${separator}${query}` : ''; - return axios.get(`sources/${queryString}`); + return axiosInstance.get(`sources/${queryString}`); } diff --git a/src/api/rates.test.ts b/src/api/rates.test.ts index c5bf074c8..60185c01b 100644 --- a/src/api/rates.test.ts +++ b/src/api/rates.test.ts @@ -1,8 +1,8 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { fetchRate } from './rates'; -test('api get provider calls axios.get', () => { +test('api get provider calls axiosInstance.get', () => { fetchRate(); - expect(axios.get).toBeCalledWith('cost-models/'); + expect(axiosInstance.get).toBeCalledWith('cost-models/'); }); diff --git a/src/api/rates.ts b/src/api/rates.ts index 6458ef7ce..3eb92e71c 100644 --- a/src/api/rates.ts +++ b/src/api/rates.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedResponse } from './api'; import type { Metric } from './metrics'; @@ -47,5 +47,5 @@ export type Rates = PagedResponse; export function fetchRate(uuid = null) { const query = uuid ? `?source_uuid=${uuid}` : ''; - return axios.get(`cost-models/${query}`); + return axiosInstance.get(`cost-models/${query}`); } diff --git a/src/api/reports/awsOcpReports.test.ts b/src/api/reports/awsOcpReports.test.ts index 8b67d4a66..de2aed7ff 100644 --- a/src/api/reports/awsOcpReports.test.ts +++ b/src/api/reports/awsOcpReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './awsOcpReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/infrastructures/aws/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/infrastructures/aws/costs/?${query}`); }); diff --git a/src/api/reports/awsOcpReports.ts b/src/api/reports/awsOcpReports.ts index dec91de52..6235708da 100644 --- a/src/api/reports/awsOcpReports.ts +++ b/src/api/reports/awsOcpReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -52,5 +52,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/awsReports.test.ts b/src/api/reports/awsReports.test.ts index b9dc733a5..b8f2742ad 100644 --- a/src/api/reports/awsReports.test.ts +++ b/src/api/reports/awsReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './awsReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.storage, query); - expect(axios.get).toBeCalledWith(`reports/aws/storage/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/aws/storage/?${query}`); }); diff --git a/src/api/reports/awsReports.ts b/src/api/reports/awsReports.ts index f3c506844..989f4391e 100644 --- a/src/api/reports/awsReports.ts +++ b/src/api/reports/awsReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -54,5 +54,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/azureOcpReports.test.ts b/src/api/reports/azureOcpReports.test.ts index eb25e070b..faeef9802 100644 --- a/src/api/reports/azureOcpReports.test.ts +++ b/src/api/reports/azureOcpReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './azureOcpReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/infrastructures/azure/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/infrastructures/azure/costs/?${query}`); }); diff --git a/src/api/reports/azureOcpReports.ts b/src/api/reports/azureOcpReports.ts index 5fe18ce67..9a6ea022e 100644 --- a/src/api/reports/azureOcpReports.ts +++ b/src/api/reports/azureOcpReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -51,5 +51,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/azureReports.test.ts b/src/api/reports/azureReports.test.ts index c48cb9a47..45d80539f 100644 --- a/src/api/reports/azureReports.test.ts +++ b/src/api/reports/azureReports.test.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportType } from 'api/reports/report'; -import axios from 'axios'; import { runReport } from './azureReports'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/azure/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/azure/costs/?${query}`); }); diff --git a/src/api/reports/azureReports.ts b/src/api/reports/azureReports.ts index 0c11910fd..25b88fe9a 100644 --- a/src/api/reports/azureReports.ts +++ b/src/api/reports/azureReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -52,5 +52,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/gcpOcpReports.test.ts b/src/api/reports/gcpOcpReports.test.ts index 8460c5ffb..c250be7b5 100644 --- a/src/api/reports/gcpOcpReports.test.ts +++ b/src/api/reports/gcpOcpReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './gcpOcpReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/infrastructures/gcp/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/infrastructures/gcp/costs/?${query}`); }); diff --git a/src/api/reports/gcpOcpReports.ts b/src/api/reports/gcpOcpReports.ts index 0672cf4d3..d5968333d 100644 --- a/src/api/reports/gcpOcpReports.ts +++ b/src/api/reports/gcpOcpReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -57,5 +57,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/gcpReports.test.ts b/src/api/reports/gcpReports.test.ts index 26d1b8390..b90498bde 100644 --- a/src/api/reports/gcpReports.test.ts +++ b/src/api/reports/gcpReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './gcpReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/gcp/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/gcp/costs/?${query}`); }); diff --git a/src/api/reports/gcpReports.ts b/src/api/reports/gcpReports.ts index dafe6fb71..9aaa366f1 100644 --- a/src/api/reports/gcpReports.ts +++ b/src/api/reports/gcpReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -58,5 +58,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/ibmReports.test.ts b/src/api/reports/ibmReports.test.ts index 9800b8122..3cda81898 100644 --- a/src/api/reports/ibmReports.test.ts +++ b/src/api/reports/ibmReports.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runReport } from './ibmReports'; import { ReportType } from './report'; @@ -6,5 +6,5 @@ import { ReportType } from './report'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/gcp/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/gcp/costs/?${query}`); }); diff --git a/src/api/reports/ibmReports.ts b/src/api/reports/ibmReports.ts index 65784773a..c3780d004 100644 --- a/src/api/reports/ibmReports.ts +++ b/src/api/reports/ibmReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -58,5 +58,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/ociReports.test.ts b/src/api/reports/ociReports.test.ts index fadd33649..b0bcd3416 100644 --- a/src/api/reports/ociReports.test.ts +++ b/src/api/reports/ociReports.test.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportType } from 'api/reports/report'; -import axios from 'axios'; import { runReport } from './ociReports'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/oci/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/oci/costs/?${query}`); }); diff --git a/src/api/reports/ociReports.ts b/src/api/reports/ociReports.ts index cae71bde8..9e414af3a 100644 --- a/src/api/reports/ociReports.ts +++ b/src/api/reports/ociReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -52,5 +52,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/ocpCloudReports.test.ts b/src/api/reports/ocpCloudReports.test.ts index a2b91e9b8..fc9daafe5 100644 --- a/src/api/reports/ocpCloudReports.test.ts +++ b/src/api/reports/ocpCloudReports.test.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportType } from 'api/reports/report'; -import axios from 'axios'; import { runReport } from './ocpCloudReports'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/infrastructures/all/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/infrastructures/all/costs/?${query}`); }); diff --git a/src/api/reports/ocpCloudReports.ts b/src/api/reports/ocpCloudReports.ts index 2670cdf94..542083848 100644 --- a/src/api/reports/ocpCloudReports.ts +++ b/src/api/reports/ocpCloudReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -81,5 +81,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/ocpReports.test.ts b/src/api/reports/ocpReports.test.ts index 99a97871d..e3ca9c29f 100644 --- a/src/api/reports/ocpReports.test.ts +++ b/src/api/reports/ocpReports.test.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportType } from 'api/reports/report'; -import axios from 'axios'; import { runReport } from './ocpReports'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/costs/?${query}`); }); diff --git a/src/api/reports/ocpReports.ts b/src/api/reports/ocpReports.ts index b81ad3f1a..c7eafab80 100644 --- a/src/api/reports/ocpReports.ts +++ b/src/api/reports/ocpReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -66,5 +66,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/reports/rhelReports.test.ts b/src/api/reports/rhelReports.test.ts index 99a97871d..e3ca9c29f 100644 --- a/src/api/reports/rhelReports.test.ts +++ b/src/api/reports/rhelReports.test.ts @@ -1,10 +1,10 @@ +import { axiosInstance } from 'api'; import { ReportType } from 'api/reports/report'; -import axios from 'axios'; import { runReport } from './ocpReports'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runReport(ReportType.cost, query); - expect(axios.get).toBeCalledWith(`reports/openshift/costs/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`reports/openshift/costs/?${query}`); }); diff --git a/src/api/reports/rhelReports.ts b/src/api/reports/rhelReports.ts index 509b082d2..b4c15ec31 100644 --- a/src/api/reports/rhelReports.ts +++ b/src/api/reports/rhelReports.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Report, ReportData, ReportItem, ReportItemValue, ReportMeta, ReportValue } from './report'; import { ReportType } from './report'; @@ -57,5 +57,5 @@ export const ReportTypePaths: Partial> = { export function runReport(reportType: ReportType, query: string) { const path = ReportTypePaths[reportType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/awsOcpResource.ts b/src/api/resources/awsOcpResource.ts index 3b693b31e..695da2c94 100644 --- a/src/api/resources/awsOcpResource.ts +++ b/src/api/resources/awsOcpResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -13,5 +13,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; const queryString = query ? `?${query}` : ''; - return axios.get(`${path}/${queryString}`); + return axiosInstance.get(`${path}/${queryString}`); } diff --git a/src/api/resources/awsResource.ts b/src/api/resources/awsResource.ts index 3b693b31e..695da2c94 100644 --- a/src/api/resources/awsResource.ts +++ b/src/api/resources/awsResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -13,5 +13,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; const queryString = query ? `?${query}` : ''; - return axios.get(`${path}/${queryString}`); + return axiosInstance.get(`${path}/${queryString}`); } diff --git a/src/api/resources/azureOcpResource.ts b/src/api/resources/azureOcpResource.ts index 75181e862..9128d77e8 100644 --- a/src/api/resources/azureOcpResource.ts +++ b/src/api/resources/azureOcpResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -11,5 +11,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/azureResource.ts b/src/api/resources/azureResource.ts index 75181e862..9128d77e8 100644 --- a/src/api/resources/azureResource.ts +++ b/src/api/resources/azureResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -11,5 +11,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/gcpOcpResource.ts b/src/api/resources/gcpOcpResource.ts index 05e082ac5..f1ab0824b 100644 --- a/src/api/resources/gcpOcpResource.ts +++ b/src/api/resources/gcpOcpResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -12,5 +12,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/gcpResource.ts b/src/api/resources/gcpResource.ts index 05e082ac5..f1ab0824b 100644 --- a/src/api/resources/gcpResource.ts +++ b/src/api/resources/gcpResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -12,5 +12,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/ibmResource.ts b/src/api/resources/ibmResource.ts index 887a98a00..f092dd1a4 100644 --- a/src/api/resources/ibmResource.ts +++ b/src/api/resources/ibmResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -12,5 +12,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/ociResource.ts b/src/api/resources/ociResource.ts index 5a024ad03..4be4d81e9 100644 --- a/src/api/resources/ociResource.ts +++ b/src/api/resources/ociResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -11,5 +11,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/ocpResource.ts b/src/api/resources/ocpResource.ts index 923a4d791..b65f20f91 100644 --- a/src/api/resources/ocpResource.ts +++ b/src/api/resources/ocpResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -11,5 +11,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/resources/rhelResource.ts b/src/api/resources/rhelResource.ts index 923a4d791..b65f20f91 100644 --- a/src/api/resources/rhelResource.ts +++ b/src/api/resources/rhelResource.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Resource } from './resource'; import { ResourceType } from './resource'; @@ -11,5 +11,5 @@ export const ResourceTypePaths: Partial> = { export function runResource(resourceType: ResourceType, query: string) { const path = ResourceTypePaths[resourceType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/settings.ts b/src/api/settings.ts index 4ca8508cc..edaf1fb62 100644 --- a/src/api/settings.ts +++ b/src/api/settings.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedLinks, PagedMetaData } from './api'; @@ -71,10 +71,10 @@ export const SettingsTypePaths: Partial> = { export function fetchSettings(settingsType: SettingsType, query: string) { const path = SettingsTypePaths[settingsType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } export function updateSettings(settingsType: SettingsType, payload: SettingsPayload) { const path = SettingsTypePaths[settingsType]; - return axios.put(`${path}`, payload); + return axiosInstance.put(`${path}`, payload); } diff --git a/src/api/tags/awsOcpTags.ts b/src/api/tags/awsOcpTags.ts index 230517403..7b466cc1f 100644 --- a/src/api/tags/awsOcpTags.ts +++ b/src/api/tags/awsOcpTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/awsTags.test.ts b/src/api/tags/awsTags.test.ts index 23a77c743..f122a96df 100644 --- a/src/api/tags/awsTags.test.ts +++ b/src/api/tags/awsTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './awsTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/aws/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/aws/?${query}`); }); diff --git a/src/api/tags/awsTags.ts b/src/api/tags/awsTags.ts index 1a08a94ac..bed3c0eec 100644 --- a/src/api/tags/awsTags.ts +++ b/src/api/tags/awsTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/azureOcpTags.ts b/src/api/tags/azureOcpTags.ts index ad612d300..0d81334b7 100644 --- a/src/api/tags/azureOcpTags.ts +++ b/src/api/tags/azureOcpTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/azureTags.test.ts b/src/api/tags/azureTags.test.ts index dce045ded..6378fddc5 100644 --- a/src/api/tags/azureTags.test.ts +++ b/src/api/tags/azureTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './azureTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/azure/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/azure/?${query}`); }); diff --git a/src/api/tags/azureTags.ts b/src/api/tags/azureTags.ts index e340daa90..392ab9a3d 100644 --- a/src/api/tags/azureTags.ts +++ b/src/api/tags/azureTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/gcpOcpTags.test.ts b/src/api/tags/gcpOcpTags.test.ts index 95a0b2df7..0dacade3a 100644 --- a/src/api/tags/gcpOcpTags.test.ts +++ b/src/api/tags/gcpOcpTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './gcpOcpTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/openshift/infrastructures/gcp/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/openshift/infrastructures/gcp/?${query}`); }); diff --git a/src/api/tags/gcpOcpTags.ts b/src/api/tags/gcpOcpTags.ts index 6d6d747e1..11e200012 100644 --- a/src/api/tags/gcpOcpTags.ts +++ b/src/api/tags/gcpOcpTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/gcpTags.test.ts b/src/api/tags/gcpTags.test.ts index d07aa3e3d..d2430dfac 100644 --- a/src/api/tags/gcpTags.test.ts +++ b/src/api/tags/gcpTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './gcpTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/gcp/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/gcp/?${query}`); }); diff --git a/src/api/tags/gcpTags.ts b/src/api/tags/gcpTags.ts index a91499bec..9bf15cf25 100644 --- a/src/api/tags/gcpTags.ts +++ b/src/api/tags/gcpTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/ibmTags.test.ts b/src/api/tags/ibmTags.test.ts index 27bc55765..9b4e4424b 100644 --- a/src/api/tags/ibmTags.test.ts +++ b/src/api/tags/ibmTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './ibmTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/gcp/?${query}`); // Todo: Update when APIs are available + expect(axiosInstance.get).toBeCalledWith(`tags/gcp/?${query}`); // Todo: Update when APIs are available }); diff --git a/src/api/tags/ibmTags.ts b/src/api/tags/ibmTags.ts index acfb520b9..34747d601 100644 --- a/src/api/tags/ibmTags.ts +++ b/src/api/tags/ibmTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/ociTags.test.ts b/src/api/tags/ociTags.test.ts index 54aef2235..4177a12d1 100644 --- a/src/api/tags/ociTags.test.ts +++ b/src/api/tags/ociTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './ociTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/oci/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/oci/?${query}`); }); diff --git a/src/api/tags/ociTags.ts b/src/api/tags/ociTags.ts index a9d9fe903..14b23b9fb 100644 --- a/src/api/tags/ociTags.ts +++ b/src/api/tags/ociTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/ocpCloudTags.ts b/src/api/tags/ocpCloudTags.ts index f3772233e..10b1da9c5 100644 --- a/src/api/tags/ocpCloudTags.ts +++ b/src/api/tags/ocpCloudTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/ocpTags.test.ts b/src/api/tags/ocpTags.test.ts index 13571c764..54888a13e 100644 --- a/src/api/tags/ocpTags.test.ts +++ b/src/api/tags/ocpTags.test.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import { runTag } from './ocpTags'; import { TagType } from './tag'; @@ -6,5 +6,5 @@ import { TagType } from './tag'; test('api run reports calls axios get', () => { const query = 'filter[resolution]=daily'; runTag(TagType.tag, query); - expect(axios.get).toBeCalledWith(`tags/openshift/?${query}`); + expect(axiosInstance.get).toBeCalledWith(`tags/openshift/?${query}`); }); diff --git a/src/api/tags/ocpTags.ts b/src/api/tags/ocpTags.ts index 3a0e32854..2549a0d48 100644 --- a/src/api/tags/ocpTags.ts +++ b/src/api/tags/ocpTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/tags/rhelTags.ts b/src/api/tags/rhelTags.ts index bfebe075a..ed5f1abdf 100644 --- a/src/api/tags/rhelTags.ts +++ b/src/api/tags/rhelTags.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { Tag } from './tag'; import { TagType } from './tag'; @@ -11,5 +11,5 @@ export const TagTypePaths: Partial> = { export function runTag(tagType: TagType, query: string) { const path = TagTypePaths[tagType]; - return axios.get(`${path}?${query}`); + return axiosInstance.get(`${path}?${query}`); } diff --git a/src/api/userAccess.test.ts b/src/api/userAccess.test.ts index f9e5051fd..86e83a9ec 100644 --- a/src/api/userAccess.test.ts +++ b/src/api/userAccess.test.ts @@ -1,11 +1,11 @@ +import { axiosInstance } from 'api'; import { getUserAccessQuery } from 'api/queries/userAccessQuery'; -import axios from 'axios'; import { awsUserAccessQuery } from 'store/userAccess/userAccessCommon'; import { fetchUserAccess } from './userAccess'; -test('api get provider calls axios.get', () => { +test('api get provider calls axiosInstance.get', () => { const query = getUserAccessQuery(awsUserAccessQuery); fetchUserAccess(query); - expect(axios.get).toBeCalledWith('user-access/?type=AWS'); + expect(axiosInstance.get).toBeCalledWith('user-access/?type=AWS'); }); diff --git a/src/api/userAccess.ts b/src/api/userAccess.ts index 20acfc108..8410df19e 100644 --- a/src/api/userAccess.ts +++ b/src/api/userAccess.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { PagedLinks, PagedMetaData } from './api'; @@ -35,5 +35,5 @@ export const enum UserAccessType { // If the user-access API is called without a query parameter, all types are returned in the response export function fetchUserAccess(query: string) { const queryString = query ? `?${query}` : ''; - return axios.get(`user-access/${queryString}`); + return axiosInstance.get(`user-access/${queryString}`); } diff --git a/src/appEntry.tsx b/src/appEntry.tsx index ecb1d2bf7..cc548ecbc 100644 --- a/src/appEntry.tsx +++ b/src/appEntry.tsx @@ -1,7 +1,6 @@ /* eslint-disable no-console */ import NotificationsPortal from '@redhat-cloud-services/frontend-components-notifications/NotificationPortal'; import IntlProvider from '@redhat-cloud-services/frontend-components-translations/Provider'; -import { initApi } from 'api/api'; import { getLocale } from 'components/i18n'; import React from 'react'; import { Provider } from 'react-redux'; @@ -26,11 +25,6 @@ const costStore = configureStore({ const AppEntry = () => { const locale = getLocale(); - // Initialize here https://issues.redhat.com/browse/RHCLOUD-25573 - initApi({ - version: 'v1', - }); - return ( diff --git a/src/store/store.ts b/src/store/store.ts index e8c76948e..a7bdcbf94 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -1,6 +1,6 @@ import { notificationsMiddleware } from '@redhat-cloud-services/frontend-components-notifications/notificationsMiddleware'; import { configureStore as createStore } from '@reduxjs/toolkit'; -import axios from 'axios'; +import { axiosInstance } from 'api'; import type { RootState } from './rootReducer'; import { rootReducer } from './rootReducer'; @@ -22,7 +22,7 @@ export function configureStore(initialState: Partial) { reducer: rootReducer, }); - axios.interceptors.response.use(null, error => { + axiosInstance.interceptors.response.use(null, error => { return Promise.reject(error); }); From e3d9fb65223f37f6e039dd48199c29c3bed99581 Mon Sep 17 00:00:00 2001 From: Dan Labrecque Date: Wed, 10 Apr 2024 12:09:51 -0400 Subject: [PATCH 5/6] Don't fail codecov if run from a fork --- .github/workflows/pull_request.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 19c90d233..8c96d2d2f 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -61,7 +61,6 @@ jobs: env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - fail_ci_if_error: true directory: coverage plugin: pycoverage # Only run one plugin so that all do not run. There is no way to disable plugins entirely. From 4801d375b9dbe78703b9c226cb74feb969511317 Mon Sep 17 00:00:00 2001 From: Dan Labrecque Date: Wed, 10 Apr 2024 12:47:25 -0400 Subject: [PATCH 6/6] Clean up unused custom header --- src/api/api.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index bb5bf77a2..003275c2e 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -32,13 +32,12 @@ export function authInterceptor(reqConfig: AxiosRequestConfig) { }; } -// Create an instance instead of setting global defaults -// Setting global values affects Cost Management APIs in OCM and HCS, when navigating between apps +// Create an Axios instance // +// Note: Setting global defaults may affect the base URL in Cost Management, HCS, and OCM, when navigating between apps // See https://issues.redhat.com/browse/RHCLOUD-25573 const axiosInstance: AxiosInstance = axios.create({ baseURL: '/api/cost-management/v1/', - headers: { 'X-Custom-Header': 'foobar' }, }); axiosInstance.interceptors.request.use(authInterceptor);