-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize cloud instance metadata model
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
- Loading branch information
1 parent
8d8bb20
commit cc59c16
Showing
3 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {describe, expect, jest, test} from '@jest/globals'; | ||
import {CloudInstanceMetadataModel} from './index'; | ||
jest.setTimeout(30000); | ||
|
||
describe('ccf:configure test', () => { | ||
test('initialize and test', async () => { | ||
const model = await new CloudInstanceMetadataModel().configure('ccf', {}); | ||
expect(model).toBeInstanceOf(CloudInstanceMetadataModel); | ||
}); | ||
}); |
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,48 @@ | ||
import {IImpactModelInterface} from '../interfaces'; | ||
|
||
import {CONFIG} from '../../config'; | ||
|
||
import {KeyValuePair} from '../../types/common'; | ||
|
||
const {MODEL_IDS} = CONFIG; | ||
const {CLOUD_INSTANCE_METADATA} = MODEL_IDS; | ||
|
||
export class CloudInstanceMetadataModel implements IImpactModelInterface { | ||
authParams: object | undefined = undefined; | ||
staticParams: object | undefined; | ||
name: string | undefined; | ||
|
||
authenticate(authParams: object): void { | ||
this.authParams = authParams; | ||
} | ||
|
||
/** | ||
* Each Observation require: | ||
* @param {Object[]} observations | ||
* @param {string} observations[].timestamp RFC3339 timestamp string | ||
*/ | ||
async calculate(observations: object | object[] | undefined): Promise<any[]> { | ||
if (observations === undefined) { | ||
throw new Error('Required Parameters not provided'); | ||
} else if (!Array.isArray(observations)) { | ||
throw new Error('Observations must be an array'); | ||
} | ||
|
||
return observations.map((observation: KeyValuePair) => { | ||
return observation; | ||
}); | ||
} | ||
|
||
async configure( | ||
name: string, | ||
staticParams: object | undefined | ||
): Promise<IImpactModelInterface> { | ||
this.staticParams = staticParams; | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
modelIdentifier(): string { | ||
return CLOUD_INSTANCE_METADATA; | ||
} | ||
} |