mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 18:08:55 +08:00
API client generation: create a central getAPIBaseURL
function (#99961)
* create a getAPIBaseURL function * use base url in iam api
This commit is contained in:
@ -1,3 +1,13 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const getAPINamespace = () => config.namespace;
|
||||
|
||||
/**
|
||||
* Get a base URL for a k8s API endpoint with parameterised namespace given it's group and version
|
||||
* @param group the k8s group, e.g. dashboard.grafana.app
|
||||
* @param version e.g. v0alpha1
|
||||
* @returns
|
||||
*/
|
||||
export const getAPIBaseURL = (group: string, version: string) => {
|
||||
return `/apis/${group}/${version}/namespaces/${getAPINamespace()}`;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ import templatingReducers from 'app/features/variables/state/keyedVariablesReduc
|
||||
import { alertingApi } from '../../features/alerting/unified/api/alertingApi';
|
||||
import { iamApi } from '../../features/iam/api/api';
|
||||
import { userPreferencesAPI } from '../../features/preferences/api';
|
||||
import { queryLibraryApi } from '../../features/query-library/api/factory';
|
||||
import { queryLibraryApi } from '../../features/query-library/api/api';
|
||||
import { cleanUpAction } from '../actions/cleanUp';
|
||||
|
||||
const rootReducers = {
|
||||
|
@ -5,7 +5,7 @@ import { TabbedContainer, TabConfig } from '@grafana/ui';
|
||||
|
||||
import { t } from '../../../core/internationalization';
|
||||
import { useListQueryTemplateQuery } from '../../query-library';
|
||||
import { QUERY_LIBRARY_GET_LIMIT } from '../../query-library/api/factory';
|
||||
import { QUERY_LIBRARY_GET_LIMIT } from '../../query-library/api/api';
|
||||
import { ExploreDrawer } from '../ExploreDrawer';
|
||||
|
||||
import { QueryLibrary } from './QueryLibrary';
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { createBaseQuery } from '../../../api/createBaseQuery';
|
||||
import { getAPINamespace } from '../../../api/utils';
|
||||
import { getAPIBaseURL } from '../../../api/utils';
|
||||
|
||||
export const API_VERSION = 'iam.grafana.app/v0alpha1';
|
||||
|
||||
export const BASE_URL = `/apis/${API_VERSION}/namespaces/${getAPINamespace()}`;
|
||||
export const BASE_URL = getAPIBaseURL('iam.grafana.app', 'v0alpha1');
|
||||
|
||||
export const iamApi = createApi({
|
||||
baseQuery: createBaseQuery({ baseURL: BASE_URL }),
|
||||
|
@ -1,13 +1,14 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
|
||||
import { createBaseQuery } from '../../../api/createBaseQuery';
|
||||
|
||||
import { BASE_URL } from './query';
|
||||
import { getAPIBaseURL } from '../../../api/utils';
|
||||
|
||||
// Currently, we are loading all query templates
|
||||
// Organizations can have maximum of 1000 query templates
|
||||
export const QUERY_LIBRARY_GET_LIMIT = 1000;
|
||||
|
||||
export const BASE_URL = getAPIBaseURL('peakq.grafana.app', 'v0alpha1');
|
||||
|
||||
export const queryLibraryApi = createApi({
|
||||
baseQuery: createBaseQuery({ baseURL: BASE_URL }),
|
||||
reducerPath: 'queryLibraryAPI',
|
@ -1,4 +1,4 @@
|
||||
import { queryLibraryApi as api } from './factory';
|
||||
import { queryLibraryApi as api } from './api';
|
||||
export const addTagTypes = ['QueryTemplate'] as const;
|
||||
const injectedRtkApi = api
|
||||
.enhanceEndpoints({
|
||||
|
@ -4,7 +4,6 @@ import { AnnoKeyCreatedBy } from '../../apiserver/types';
|
||||
import { AddQueryTemplateCommand, QueryTemplate } from '../types';
|
||||
|
||||
import { ListQueryTemplateApiResponse, QueryTemplate as QT } from './endpoints.gen';
|
||||
import { API_VERSION, QueryTemplateKinds } from './query';
|
||||
|
||||
export const convertDataQueryResponseToQueryTemplates = (result: ListQueryTemplateApiResponse): QueryTemplate[] => {
|
||||
if (!result.items) {
|
||||
@ -30,8 +29,6 @@ export const convertDataQueryResponseToQueryTemplates = (result: ListQueryTempla
|
||||
export const convertAddQueryTemplateCommandToDataQuerySpec = (addQueryTemplateCommand: AddQueryTemplateCommand): QT => {
|
||||
const { title, targets } = addQueryTemplateCommand;
|
||||
return {
|
||||
apiVersion: API_VERSION,
|
||||
kind: QueryTemplateKinds.QueryTemplate,
|
||||
metadata: {
|
||||
/**
|
||||
* Server will append to whatever is passed here, but just to be safe we generate a uuid
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { BASE_URL } from './query';
|
||||
import { BASE_URL } from './api';
|
||||
import { getIdentityDisplayList } from './testdata/identityDisplayList';
|
||||
import { getTestQueryList } from './testdata/testQueryList';
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
import { getAPINamespace } from '../../../api/utils';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export const API_VERSION = 'peakq.grafana.app/v0alpha1';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export enum QueryTemplateKinds {
|
||||
QueryTemplate = 'QueryTemplate',
|
||||
}
|
||||
|
||||
/**
|
||||
* Query Library is an experimental feature. API (including the URL path) will likely change.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const BASE_URL = `/apis/${API_VERSION}/namespaces/${getAPINamespace()}`;
|
@ -9,8 +9,8 @@
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import { QUERY_LIBRARY_GET_LIMIT } from './api/api';
|
||||
import { generatedQueryLibraryApi } from './api/endpoints.gen';
|
||||
import { QUERY_LIBRARY_GET_LIMIT } from './api/factory';
|
||||
import { mockData } from './api/mocks';
|
||||
|
||||
export const {
|
||||
|
@ -12,7 +12,7 @@ import { buildInitialState } from '../core/reducers/navModel';
|
||||
import { addReducer, createRootReducer } from '../core/reducers/root';
|
||||
import { alertingApi } from '../features/alerting/unified/api/alertingApi';
|
||||
import { iamApi } from '../features/iam/api/api';
|
||||
import { queryLibraryApi } from '../features/query-library/api/factory';
|
||||
import { queryLibraryApi } from '../features/query-library/api/api';
|
||||
|
||||
import { setStore } from './store';
|
||||
|
||||
|
Reference in New Issue
Block a user