-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dao): implement /api/v2/ipinterfaces (HELM-188)
- Loading branch information
Benjamin Reed
committed
Aug 17, 2021
1 parent
b879f5e
commit 394afce
Showing
17 changed files
with
1,185 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {AbstractDAO} from './AbstractDAO'; | ||
|
||
import {Filter} from '../api/Filter'; | ||
import {IHasHTTP} from '../api/IHasHTTP'; | ||
import {IOnmsHTTP} from '../api/IOnmsHTTP'; | ||
import {OnmsError} from '../api/OnmsError'; | ||
|
||
import { OnmsIpInterface } from '../model/OnmsIpInterface'; | ||
|
||
/** | ||
* Data access for [[OnmsIpInterface]] objects. | ||
* @category DAO | ||
*/ | ||
export class IpInterfaceDAO extends AbstractDAO<number, OnmsIpInterface> { | ||
constructor(impl: IHasHTTP | IOnmsHTTP) { | ||
super(impl); | ||
} | ||
|
||
/** | ||
* Get an IP interface, given the interface's ID. | ||
* | ||
* @param id - The interface's ID. | ||
*/ | ||
public async get(id: number): Promise<OnmsIpInterface> { | ||
this.assertV2(); | ||
return this.getOptions().then((builder) => { | ||
return this.http.get(this.getRoot() + '/' + id, builder.build()).then((result) => { | ||
const node = OnmsIpInterface.fromData(result.data); | ||
|
||
if (!node) { | ||
throw new OnmsError(`IpInterfaceDAO.get id={id} ReST request succeeded, but did not return a valid node.`); | ||
} | ||
|
||
return node; | ||
}); | ||
}); | ||
} | ||
|
||
/** Search for IP interfaces, given an optional filter. */ | ||
public async find(filter?: Filter): Promise<OnmsIpInterface[]> { | ||
this.assertV2(); | ||
return this.getOptions(filter).then((builder) => { | ||
return this.http.get(this.getRoot(), builder.build()).then((result) => { | ||
let data = result.data; | ||
|
||
if (data !== null && this.getCount(data, result.code) > 0 && data.ipInterface) { | ||
data = data.ipInterface; | ||
} else { | ||
data = []; | ||
} | ||
|
||
if (!Array.isArray(data)) { | ||
if (data.id) { | ||
data = [data]; | ||
} else { | ||
throw new OnmsError('Expected an array of IP interfaces but got "' + (typeof data) + '" instead.'); | ||
} | ||
} | ||
return data.map((ifaceData: any) => { | ||
return OnmsIpInterface.fromData(ifaceData); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* The path to the node search properties endpoint. | ||
*/ | ||
protected searchPropertyPath(): string { | ||
return this.getRoot() + '/properties'; | ||
} | ||
|
||
/** | ||
* The root of the IpInterfaces ReST API. | ||
* @hidden | ||
*/ | ||
private getRoot() { | ||
return 'api/v2/ipinterfaces'; | ||
} | ||
|
||
/** | ||
* Make sure v2 is supported. | ||
* @hidden | ||
*/ | ||
private assertV2() { | ||
if (this.getApiVersion() < 2) { | ||
throw new OnmsError('The IP interface ReST API is only available on v2.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.