Skip to content

Commit

Permalink
Initialize cloud instance metadata model
Browse files Browse the repository at this point in the history
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
  • Loading branch information
gnanakeethan committed Oct 10, 2023
1 parent 8d8bb20 commit cc59c16
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const CONFIG = {
TEADS_AWS: 'teads.cloud.sci',
TEADS_CURVE: 'teads.curve',
WATT_TIME: 'org.wattime.grid',
CLOUD_INSTANCE_METADATA: 'org.gsf.cloud-instance-metadata',
},
RIMPL: {
ARGS: {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/cloud-instance-metadata/index.test.ts
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);
});
});
48 changes: 48 additions & 0 deletions src/lib/cloud-instance-metadata/index.ts
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;
}
}

0 comments on commit cc59c16

Please sign in to comment.