Skip to content

Commit

Permalink
Addressed feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ggracechoi committed Aug 11, 2023
1 parent 6bb7c25 commit 1f0a6fb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
19 changes: 2 additions & 17 deletions src/datasources/system/SystemDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import {

import { TestingStatus, getBackendSrv, getTemplateSrv } from '@grafana/runtime';

import { AuthResponse, QueryType, SystemMetadata, SystemQuery, SystemSummary, VariableQuery, Workspace } from './types';
import { QueryType, SystemMetadata, SystemQuery, SystemSummary, VariableQuery } from './types';
import { defaultProjection } from './constants';
import { NetworkUtils } from './network-utils';

export class SystemDataSource extends DataSourceApi<SystemQuery> {
baseUrl: string;
aliasUrl: string;
constructor(private instanceSettings: DataSourceInstanceSettings) {
super(instanceSettings);
this.baseUrl = this.instanceSettings.url + '/nisysmgmt/v1';
this.aliasUrl = this.instanceSettings.url + '/niauth/v1';
}

transformProjection(projections: string[]): string {
Expand All @@ -39,16 +37,6 @@ export class SystemDataSource extends DataSourceApi<SystemQuery> {
return result;
}

findName(workspaces: Workspace[], system: SystemMetadata): string {
for (let i = 0; i < workspaces.length; i++) {
if (workspaces[i].id === system.workspace) {
return workspaces[i].name;
}
}

return system.workspace;
}

private getIpAddress(ip4Interface: Record<string, string[]>, ip6Interface: Record<string, string[]>): string | null {
return NetworkUtils.getIpAddressFromInterfaces(ip4Interface) || NetworkUtils.getIpAddressFromInterfaces(ip6Interface);
}
Expand Down Expand Up @@ -80,8 +68,6 @@ export class SystemDataSource extends DataSourceApi<SystemQuery> {
orderBy: 'createdTimeStamp DESC'
};
let metadataResponse = await getBackendSrv().post<{ data: SystemMetadata[] }>(this.baseUrl + '/query-systems', postBody);
let aliasNameResponse = await getBackendSrv().get< AuthResponse >(this.aliasUrl + '/auth', postBody);
console.log(aliasNameResponse);
return toDataFrame({
fields: [
{ name: 'id', values: metadataResponse.data.map(m => m.id) },
Expand All @@ -93,8 +79,7 @@ export class SystemDataSource extends DataSourceApi<SystemQuery> {
{ name: 'vendor', values: metadataResponse.data.map(m => m.vendor) },
{ name: 'operating system', values: metadataResponse.data.map(m => m.osFullName) },
{ name: 'ip address', values: metadataResponse.data.map(m => this.getIpAddress(m.ip4Interfaces, m.ip6Interfaces)) },
{ name: 'workspace', values: metadataResponse.data.map(m => this.findName(aliasNameResponse.workspaces, m)) }
]
{ name: 'workspace', values: metadataResponse.data.map(m => m.workspace) }, ]
});
}
}));
Expand Down
9 changes: 0 additions & 9 deletions src/datasources/system/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,3 @@ export interface VariableQuery {
id: string,
alias: string
}

export interface AuthResponse {
workspaces: Workspace[]
}

export interface Workspace {
id: string,
name: string
}

0 comments on commit 1f0a6fb

Please sign in to comment.