Skip to content

Commit

Permalink
add AnalyticsLicenseType
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed May 6, 2024
1 parent f2661aa commit 21b9e39
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions bitmovin-analytics-datasource/src/utils/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,41 @@ import { lastValueFrom } from 'rxjs';
import { getBackendSrv } from '@grafana/runtime';
import { SelectableValue } from '@grafana/data';

type AnalyticsLicense = {
readonly name: string;
readonly id: string;
readonly licenseKey?: string;
};

const licenseEndpoints = [
{
endpoint: '/analytics/licenses',
mapperFunc: (license: any): SelectableValue => ({
mapperFunc: (license: AnalyticsLicense): SelectableValue => ({
value: license.licenseKey,
label: license.name ? license.name : license.licenseKey,
}),
},
{
endpoint: '/analytics/virtual-licenses',
mapperFunc: (license: any): SelectableValue => ({
mapperFunc: (license: AnalyticsLicense): SelectableValue => ({
value: license.id,
label: license.name ? license.name : license.id,
}),
},
{
endpoint: '/analytics/demo-licenses',
mapperFunc: (license: any): SelectableValue => ({
mapperFunc: (license: AnalyticsLicense): SelectableValue => ({
value: license.id,
label: license.name ? license.name : license.id,
}),
},
];

async function fetchLicensesForEndpoint(url: string, apiKey: string, mapperFunc: (license: any) => SelectableValue) {
async function fetchLicensesForEndpoint(
url: string,
apiKey: string,
mapperFunc: (license: AnalyticsLicense) => SelectableValue
) {
const options = {
url: url,
headers: { 'X-Api-Key': apiKey },
Expand All @@ -48,11 +58,11 @@ async function fetchLicensesForEndpoint(url: string, apiKey: string, mapperFunc:
export async function fetchLicenses(apiKey: string, baseUrl: string): Promise<SelectableValue[]> {
const allLicenses: SelectableValue[] = [];

for (const licenseEndpoints1 of licenseEndpoints) {
for (const licenseEndpoint of licenseEndpoints) {
const licenses = await fetchLicensesForEndpoint(
baseUrl + licenseEndpoints1.endpoint,
baseUrl + licenseEndpoint.endpoint,
apiKey,
licenseEndpoints1.mapperFunc
licenseEndpoint.mapperFunc
);
allLicenses.push(...licenses);
}
Expand Down

0 comments on commit 21b9e39

Please sign in to comment.