Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api): user consent #458

Merged
merged 4 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions src/amt/ConnectedDevice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { CIRASocket } from '../models/models'
import { CIM } from './cim/CIM'
import { Methods } from './cim/methods'
import { Methods as CIM_Methods, CIM } from './cim/index'
import { HttpHandler } from './HttpHandler'
import { CIRAChannel, CIRAHandler } from './CIRAHandler'
import { logger } from '../utils/logger'
import { AMT } from './AMT'
import { Methods as AMT_Methods, AMT } from './amt/index'
import { Methods as IPS_Methods, IPS } from './ips/index'
import { CIM_AssociatedPowerManagementService, CIM_SoftwareIdentity } from './models/cim_models'
import { AMT_GeneralSettings, AMT_BootCapabilities, AMT_SetupAndConfigurationService } from './models/amt_models'
import { Pull, Response } from './models/common'
import { CancelOptIn_OUTPUT, SendOptInCode_OUTPUT, StartOptIn_OUTPUT } from './models/ips_models'
export class ConnectedDevice {
isConnected: boolean = false
httpHandler: HttpHandler
Expand All @@ -17,25 +18,26 @@ export class ConnectedDevice {
messageId: number = 0
cim: CIM
amt: AMT
ips: IPS

constructor (ciraSocket: CIRASocket, private readonly username: string, private readonly password: string) {
this.cim = new CIM()
this.amt = new AMT()
this.ips = new IPS()
this.ciraSocket = ciraSocket
this.httpHandler = new HttpHandler()
this.ciraHandler = new CIRAHandler(this.httpHandler, username, password)
}

async getPowerState (): Promise<Response<Pull<CIM_AssociatedPowerManagementService>>> {
const cim = new CIM()
let xmlRequestBody = cim.ServiceAvailableToElement(Methods.ENUMERATE, (this.messageId++).toString())
let xmlRequestBody = this.cim.ServiceAvailableToElement(CIM_Methods.ENUMERATE, (this.messageId++).toString())
const result = await this.ciraHandler.Enumerate(this.ciraSocket, xmlRequestBody)
const enumContext: string = result?.Envelope?.Body?.EnumerateResponse?.EnumerationContext
if (enumContext == null) {
logger.error('failed to pull CIM_ServiceAvailableToElement in get power state')
return null
}
xmlRequestBody = cim.ServiceAvailableToElement(Methods.PULL, (this.messageId++).toString(), enumContext)
xmlRequestBody = this.cim.ServiceAvailableToElement(CIM_Methods.PULL, (this.messageId++).toString(), enumContext)
const pullResponse = await this.ciraHandler.Pull<CIM_AssociatedPowerManagementService>(this.ciraSocket, xmlRequestBody)
if (pullResponse == null) {
logger.error('failed to pull CIM_ServiceAvailableToElement in get power state')
Expand All @@ -45,20 +47,20 @@ export class ConnectedDevice {
}

async getVersion (): Promise<any> {
let xmlRequestBody = this.cim.SoftwareIdentity(Methods.ENUMERATE, (this.messageId++).toString())
let xmlRequestBody = this.cim.SoftwareIdentity(CIM_Methods.ENUMERATE, (this.messageId++).toString())
const result = await this.ciraHandler.Enumerate(this.ciraSocket, xmlRequestBody)
const enumContext: string = result?.Envelope.Body?.EnumerateResponse?.EnumerationContext
if (enumContext == null) {
logger.error('failed to pull CIM_SoftwareIdentity in get version')
return null
}
xmlRequestBody = this.cim.SoftwareIdentity(Methods.PULL, (this.messageId++).toString(), enumContext)
xmlRequestBody = this.cim.SoftwareIdentity(CIM_Methods.PULL, (this.messageId++).toString(), enumContext)
const pullResponse = await this.ciraHandler.Pull<CIM_SoftwareIdentity>(this.ciraSocket, xmlRequestBody)
if (pullResponse == null) {
logger.error('failed to pull CIM_SoftwareIdentity in get version')
return null
}
xmlRequestBody = this.amt.amt_SetupAndConfigurationService(Methods.GET, (this.messageId++).toString())
xmlRequestBody = this.amt.SetupAndConfigurationService(AMT_Methods.GET, (this.messageId++).toString())
const getResponse = await this.ciraHandler.Get<AMT_SetupAndConfigurationService>(this.ciraSocket, xmlRequestBody)
if (getResponse == null) {
logger.error('failed to get AMT_SetupAndConfigurationService in get version')
Expand All @@ -83,19 +85,32 @@ export class ConnectedDevice {
}

async getGeneralSettings (): Promise<any> {
const xmlRequestBody = this.amt.amt_GeneralSettings(Methods.GET, (this.messageId++).toString())
const xmlRequestBody = this.amt.GeneralSettings(AMT_Methods.GET, (this.messageId++).toString())
const getResponse = await this.ciraHandler.Get<AMT_GeneralSettings>(this.ciraSocket, xmlRequestBody)
if (getResponse == null) {
logger.error('failed to get AMT_GeneralSettings')
return null
}
return getResponse
}

async getPowerCapabilities (): Promise<Response<AMT_BootCapabilities>> {
const xmlRequestBody = this.amt.amt_BootCapabilities(Methods.GET, (this.messageId++).toString())
const xmlRequestBody = this.amt.BootCapabilities(AMT_Methods.GET, (this.messageId++).toString())
const result = await this.ciraHandler.Get<AMT_BootCapabilities>(this.ciraSocket, xmlRequestBody)
console.log(result)
return result
}

async requestUserConsetCode (): Promise<any> {
const xmlRequestBody = this.ips.OptInService(IPS_Methods.START_OPT_IN, (this.messageId++).toString())
const getResponse = await this.ciraHandler.Get<StartOptIn_OUTPUT>(this.ciraSocket, xmlRequestBody)
return getResponse
}

async cancelUserConsetCode (): Promise<any> {
const xmlRequestBody = this.ips.OptInService(IPS_Methods.CANCEL_OPT_IN, (this.messageId++).toString())
const getResponse = await this.ciraHandler.Get<CancelOptIn_OUTPUT>(this.ciraSocket, xmlRequestBody)
return getResponse
}

async sendUserConsetCode (code: Number): Promise<any> {
const xmlRequestBody = this.ips.OptInService(IPS_Methods.SEND_OPT_IN_CODE, (this.messageId++).toString(), code)
const getResponse = await this.ciraHandler.Get<SendOptInCode_OUTPUT>(this.ciraSocket, xmlRequestBody)
return getResponse
}
}
44 changes: 0 additions & 44 deletions src/amt/IPS.ts

This file was deleted.

Loading