@device-management-toolkit/wsman-messages 5.15.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WSMan.d.ts +1 -1
- package/WSMan.js +307 -310
- package/WSMan.js.map +1 -1
- package/amt/actions.js +4 -7
- package/amt/actions.js.map +1 -1
- package/amt/classes.js +2 -5
- package/amt/classes.js.map +1 -1
- package/amt/index.d.ts +6 -6
- package/amt/index.js +5 -12
- package/amt/index.js.map +1 -1
- package/amt/messages.d.ts +6 -6
- package/amt/messages.js +722 -806
- package/amt/messages.js.map +1 -1
- package/amt/methods.js +2 -5
- package/amt/methods.js.map +1 -1
- package/amt/models.d.ts +2 -2
- package/amt/models.js +1 -2
- package/amt/models.js.map +1 -1
- package/amt/types.js +1 -2
- package/amt/types.js.map +1 -1
- package/cim/actions.js +2 -5
- package/cim/actions.js.map +1 -1
- package/cim/classes.js +2 -5
- package/cim/classes.js.map +1 -1
- package/cim/index.d.ts +6 -6
- package/cim/index.js +5 -11
- package/cim/index.js.map +1 -1
- package/cim/messages.d.ts +4 -4
- package/cim/messages.js +152 -224
- package/cim/messages.js.map +1 -1
- package/cim/methods.js +2 -5
- package/cim/methods.js.map +1 -1
- package/cim/models.d.ts +2 -2
- package/cim/models.js +1 -2
- package/cim/models.js.map +1 -1
- package/cim/types.js +1 -2
- package/cim/types.js.map +1 -1
- package/dist +12 -11
- package/index.d.ts +4 -4
- package/index.js +5 -44
- package/index.js.map +1 -1
- package/ips/actions.js +2 -5
- package/ips/actions.js.map +1 -1
- package/ips/classes.js +2 -5
- package/ips/classes.js.map +1 -1
- package/ips/index.d.ts +6 -6
- package/ips/index.js +5 -11
- package/ips/index.js.map +1 -1
- package/ips/messages.d.ts +4 -4
- package/ips/messages.js +217 -253
- package/ips/messages.js.map +1 -1
- package/ips/methods.js +2 -5
- package/ips/methods.js.map +1 -1
- package/ips/models.d.ts +2 -2
- package/ips/models.js +1 -2
- package/ips/models.js.map +1 -1
- package/ips/types.js +1 -2
- package/ips/types.js.map +1 -1
- package/models/common.js +45 -2
- package/models/common.js.map +1 -1
- package/models/index.d.ts +1 -1
- package/models/index.js +2 -38
- package/models/index.js.map +1 -1
- package/package.json +12 -11
- package/amt/messages.test.d.ts +0 -5
- package/amt/messages.test.js +0 -1116
- package/amt/messages.test.js.map +0 -1
- package/cim/messages.test.d.ts +0 -5
- package/cim/messages.test.js +0 -442
- package/cim/messages.test.js.map +0 -1
- package/ips/messages.test.d.ts +0 -5
- package/ips/messages.test.js +0 -296
- package/ips/messages.test.js.map +0 -1
- package/wsman.test.d.ts +0 -5
- package/wsman.test.js +0 -479
- package/wsman.test.js.map +0 -1
package/WSMan.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*********************************************************************
|
|
3
2
|
* Copyright (c) Intel Corporation 2021
|
|
4
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
4
|
***********************************************************************/
|
|
6
|
-
|
|
7
|
-
exports.Base = exports.WSManMessageCreator = exports.BaseActions = exports.WSManErrors = void 0;
|
|
8
|
-
var WSManErrors;
|
|
5
|
+
export var WSManErrors;
|
|
9
6
|
(function (WSManErrors) {
|
|
10
7
|
WSManErrors["HEADER"] = "missing header";
|
|
11
8
|
WSManErrors["BODY"] = "missing body";
|
|
@@ -47,8 +44,8 @@ var WSManErrors;
|
|
|
47
44
|
WSManErrors["INSTANCE_ID"] = "missing InstanceID";
|
|
48
45
|
WSManErrors["MISSING_USER_ACL_ENTRY_INFORMATION"] = "Digest username and password or Kerberos SID is required";
|
|
49
46
|
WSManErrors["USERNAME_TOO_LONG"] = "Username is too long";
|
|
50
|
-
})(WSManErrors || (
|
|
51
|
-
var BaseActions;
|
|
47
|
+
})(WSManErrors || (WSManErrors = {}));
|
|
48
|
+
export var BaseActions;
|
|
52
49
|
(function (BaseActions) {
|
|
53
50
|
BaseActions["ENUMERATE"] = "http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate";
|
|
54
51
|
BaseActions["PULL"] = "http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull";
|
|
@@ -56,340 +53,340 @@ var BaseActions;
|
|
|
56
53
|
BaseActions["PUT"] = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Put";
|
|
57
54
|
BaseActions["CREATE"] = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create";
|
|
58
55
|
BaseActions["DELETE"] = "http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete";
|
|
59
|
-
})(BaseActions || (
|
|
60
|
-
class WSManMessageCreator {
|
|
56
|
+
})(BaseActions || (BaseActions = {}));
|
|
57
|
+
export class WSManMessageCreator {
|
|
58
|
+
messageId = 0;
|
|
59
|
+
xmlCommonPrefix = '<?xml version="1.0" encoding="utf-8"?><Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" xmlns="http://www.w3.org/2003/05/soap-envelope">';
|
|
60
|
+
xmlCommonEnd = '</Envelope>';
|
|
61
|
+
anonymousAddress = 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous';
|
|
62
|
+
defaultTimeout = 'PT60S';
|
|
63
|
+
resourceUriBase;
|
|
61
64
|
constructor(resourceUriBase) {
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
this.resourceUriBase = resourceUriBase;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Assembles the xml from the xmlCommonPrefix, header, body, and xmlCommonEnd
|
|
69
|
+
* @param header Partial XML created by createHeader function
|
|
70
|
+
* @param body Partial XML created by createBody or createCommonBody functions
|
|
71
|
+
* @returns string
|
|
72
|
+
*/
|
|
73
|
+
createXml = (header, body) => this.xmlCommonPrefix + header + body + this.xmlCommonEnd;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a partial XML header
|
|
76
|
+
* @param action WSMAN Action value based on DMTF schema
|
|
77
|
+
* @param resourceUri WSMAN ResourceURI value based on DMTF schema
|
|
78
|
+
* @param address WSMAN Address value based on DMTF schema
|
|
79
|
+
* @param timeout WSMAN OperationTimeout value for commands to be executed - PT60S default
|
|
80
|
+
* @param selector WSMAN Selector values for headers that require it
|
|
81
|
+
* @returns string
|
|
82
|
+
*/
|
|
83
|
+
createHeader = (action, wsmanClass, selector = null, address = this.anonymousAddress, timeout = this.defaultTimeout) => {
|
|
84
|
+
let header = '<Header>';
|
|
85
|
+
header += `<a:Action>${action}</a:Action><a:To>/wsman</a:To><w:ResourceURI>${this.resourceUriBase}${wsmanClass}</w:ResourceURI><a:MessageID>${(this.messageId++).toString()}</a:MessageID><a:ReplyTo><a:Address>${address}</a:Address></a:ReplyTo><w:OperationTimeout>${timeout}</w:OperationTimeout>`;
|
|
86
|
+
if (selector != null) {
|
|
87
|
+
header += this.createSelector(selector);
|
|
88
|
+
}
|
|
89
|
+
header += '</Header>';
|
|
90
|
+
return header;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Creates a WSMAN string based on Selector Set information provided. Can be used in header or body
|
|
94
|
+
* @param selectorSet Selector data being passed in. Could take many forms depending on the WSMAN call
|
|
95
|
+
* @returns string
|
|
96
|
+
*/
|
|
97
|
+
createSelector = (selectorSet) => {
|
|
98
|
+
if (selectorSet.name)
|
|
99
|
+
return `<w:SelectorSet><w:Selector Name="${selectorSet.name}">${selectorSet.value}</w:Selector></w:SelectorSet>`;
|
|
100
|
+
let result = '<w:SelectorSet>';
|
|
101
|
+
for (const propName in selectorSet) {
|
|
102
|
+
result += '<w:Selector Name="' + propName + '">';
|
|
103
|
+
if (selectorSet[propName].ReferenceParameters) {
|
|
104
|
+
result += '<a:EndpointReference>';
|
|
105
|
+
result +=
|
|
106
|
+
'<a:Address>' +
|
|
107
|
+
selectorSet[propName].Address +
|
|
108
|
+
'</a:Address><a:ReferenceParameters><w:ResourceURI>' +
|
|
109
|
+
selectorSet[propName].ReferenceParameters.ResourceURI +
|
|
110
|
+
'</w:ResourceURI><w:SelectorSet>';
|
|
111
|
+
const selectorArray = selectorSet[propName].ReferenceParameters.SelectorSet.Selector;
|
|
112
|
+
if (Array.isArray(selectorArray)) {
|
|
113
|
+
// TODO: Enable when selector is an array. No need for now.
|
|
114
|
+
// for (let i = 0; i < selectorArray.length; i++) {
|
|
115
|
+
// result += '<w:Selector Name="${selectorArray[i].$.Name}">${selectorArray[i]._}</w:Selector>'
|
|
116
|
+
// }
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
result += `<w:Selector Name="${selectorArray.$.Name}">${selectorArray._}</w:Selector>`;
|
|
120
|
+
}
|
|
121
|
+
result += '</w:SelectorSet></a:ReferenceParameters></a:EndpointReference>';
|
|
122
|
+
}
|
|
123
|
+
result += '</w:Selector>';
|
|
124
|
+
}
|
|
125
|
+
result += '</w:SelectorSet>';
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
createSelectorObjectForBody = (selector) => {
|
|
129
|
+
const obj = { Selector: [{ _: selector.value, $: { Name: selector.name } }] };
|
|
130
|
+
return obj;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Creates a WSMAN Body for methods listed. For other methods use createBody()
|
|
134
|
+
* @method Pull Methods.PULL
|
|
135
|
+
* @method Enumerate Methods.ENUMERATE
|
|
136
|
+
* @method Get Methods.GET
|
|
137
|
+
* @method Delete Methods.DELETE
|
|
138
|
+
* @method RequestStateChange Methods.REQUEST_STATE_CHANGE
|
|
139
|
+
* @returns string
|
|
140
|
+
*/
|
|
141
|
+
createCommonBody = {
|
|
67
142
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param header Partial XML created by createHeader function
|
|
70
|
-
* @param body Partial XML created by createBody or createCommonBody functions
|
|
143
|
+
* Body used for Delete actions
|
|
71
144
|
* @returns string
|
|
72
145
|
*/
|
|
73
|
-
|
|
146
|
+
Delete: () => '<Body></Body>',
|
|
74
147
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param action WSMAN Action value based on DMTF schema
|
|
77
|
-
* @param resourceUri WSMAN ResourceURI value based on DMTF schema
|
|
78
|
-
* @param address WSMAN Address value based on DMTF schema
|
|
79
|
-
* @param timeout WSMAN OperationTimeout value for commands to be executed - PT60S default
|
|
80
|
-
* @param selector WSMAN Selector values for headers that require it
|
|
148
|
+
* Body used for Enumerate actions
|
|
81
149
|
* @returns string
|
|
82
150
|
*/
|
|
83
|
-
|
|
84
|
-
let header = '<Header>';
|
|
85
|
-
header += `<a:Action>${action}</a:Action><a:To>/wsman</a:To><w:ResourceURI>${this.resourceUriBase}${wsmanClass}</w:ResourceURI><a:MessageID>${(this.messageId++).toString()}</a:MessageID><a:ReplyTo><a:Address>${address}</a:Address></a:ReplyTo><w:OperationTimeout>${timeout}</w:OperationTimeout>`;
|
|
86
|
-
if (selector != null) {
|
|
87
|
-
header += this.createSelector(selector);
|
|
88
|
-
}
|
|
89
|
-
header += '</Header>';
|
|
90
|
-
return header;
|
|
91
|
-
};
|
|
151
|
+
Enumerate: () => '<Body><Enumerate xmlns="http://schemas.xmlsoap.org/ws/2004/09/enumeration" /></Body>',
|
|
92
152
|
/**
|
|
93
|
-
*
|
|
94
|
-
* @param selectorSet Selector data being passed in. Could take many forms depending on the WSMAN call
|
|
153
|
+
* Body used for Get actions
|
|
95
154
|
* @returns string
|
|
96
155
|
*/
|
|
97
|
-
|
|
98
|
-
if (selectorSet.name)
|
|
99
|
-
return `<w:SelectorSet><w:Selector Name="${selectorSet.name}">${selectorSet.value}</w:Selector></w:SelectorSet>`;
|
|
100
|
-
let result = '<w:SelectorSet>';
|
|
101
|
-
for (const propName in selectorSet) {
|
|
102
|
-
result += '<w:Selector Name="' + propName + '">';
|
|
103
|
-
if (selectorSet[propName].ReferenceParameters) {
|
|
104
|
-
result += '<a:EndpointReference>';
|
|
105
|
-
result +=
|
|
106
|
-
'<a:Address>' +
|
|
107
|
-
selectorSet[propName].Address +
|
|
108
|
-
'</a:Address><a:ReferenceParameters><w:ResourceURI>' +
|
|
109
|
-
selectorSet[propName].ReferenceParameters.ResourceURI +
|
|
110
|
-
'</w:ResourceURI><w:SelectorSet>';
|
|
111
|
-
const selectorArray = selectorSet[propName].ReferenceParameters.SelectorSet.Selector;
|
|
112
|
-
if (Array.isArray(selectorArray)) {
|
|
113
|
-
// TODO: Enable when selector is an array. No need for now.
|
|
114
|
-
// for (let i = 0; i < selectorArray.length; i++) {
|
|
115
|
-
// result += '<w:Selector Name="${selectorArray[i].$.Name}">${selectorArray[i]._}</w:Selector>'
|
|
116
|
-
// }
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
result += `<w:Selector Name="${selectorArray.$.Name}">${selectorArray._}</w:Selector>`;
|
|
120
|
-
}
|
|
121
|
-
result += '</w:SelectorSet></a:ReferenceParameters></a:EndpointReference>';
|
|
122
|
-
}
|
|
123
|
-
result += '</w:Selector>';
|
|
124
|
-
}
|
|
125
|
-
result += '</w:SelectorSet>';
|
|
126
|
-
return result;
|
|
127
|
-
};
|
|
128
|
-
this.createSelectorObjectForBody = (selector) => {
|
|
129
|
-
const obj = { Selector: [{ _: selector.value, $: { Name: selector.name } }] };
|
|
130
|
-
return obj;
|
|
131
|
-
};
|
|
156
|
+
Get: () => '<Body></Body>',
|
|
132
157
|
/**
|
|
133
|
-
*
|
|
134
|
-
* @
|
|
135
|
-
* @method Enumerate Methods.ENUMERATE
|
|
136
|
-
* @method Get Methods.GET
|
|
137
|
-
* @method Delete Methods.DELETE
|
|
138
|
-
* @method RequestStateChange Methods.REQUEST_STATE_CHANGE
|
|
158
|
+
* Body used for Pull actions
|
|
159
|
+
* @param enumerationContext string returned from an Enumerate call.
|
|
139
160
|
* @returns string
|
|
140
161
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* Body used for Enumerate actions
|
|
149
|
-
* @returns string
|
|
150
|
-
*/
|
|
151
|
-
Enumerate: () => '<Body><Enumerate xmlns="http://schemas.xmlsoap.org/ws/2004/09/enumeration" /></Body>',
|
|
152
|
-
/**
|
|
153
|
-
* Body used for Get actions
|
|
154
|
-
* @returns string
|
|
155
|
-
*/
|
|
156
|
-
Get: () => '<Body></Body>',
|
|
157
|
-
/**
|
|
158
|
-
* Body used for Pull actions
|
|
159
|
-
* @param enumerationContext string returned from an Enumerate call.
|
|
160
|
-
* @returns string
|
|
161
|
-
*/
|
|
162
|
-
Pull: (enumerationContext, maxElements, maxCharacters) => {
|
|
163
|
-
if (!maxElements)
|
|
164
|
-
maxElements = 999;
|
|
165
|
-
if (!maxCharacters)
|
|
166
|
-
maxCharacters = 99999;
|
|
167
|
-
return `<Body><Pull xmlns="http://schemas.xmlsoap.org/ws/2004/09/enumeration"><EnumerationContext>${enumerationContext}</EnumerationContext><MaxElements>${maxElements}</MaxElements><MaxCharacters>${maxCharacters}</MaxCharacters></Pull></Body>`;
|
|
168
|
-
},
|
|
169
|
-
/**
|
|
170
|
-
* Body used for Create or Put actions
|
|
171
|
-
* @param wsmanClass AMT.Classes, IPS.Classes, or CIM.Classes
|
|
172
|
-
* @param data Object being applied to AMT
|
|
173
|
-
* @returns string
|
|
174
|
-
*/
|
|
175
|
-
CreateOrPut: (wsmanClass, data) => this.createBody(wsmanClass, wsmanClass, [data]),
|
|
176
|
-
/**
|
|
177
|
-
* Body used for RequestStateChange actions
|
|
178
|
-
* @param input namespace of the class being modified
|
|
179
|
-
* @param requestedState state being set
|
|
180
|
-
* @returns string
|
|
181
|
-
*/
|
|
182
|
-
RequestStateChange: (input, requestedState) => `<Body><h:RequestStateChange_INPUT xmlns:h="${input}"><h:RequestedState>${requestedState.toString()}</h:RequestedState></h:RequestStateChange_INPUT></Body>`
|
|
183
|
-
};
|
|
162
|
+
Pull: (enumerationContext, maxElements, maxCharacters) => {
|
|
163
|
+
if (!maxElements)
|
|
164
|
+
maxElements = 999;
|
|
165
|
+
if (!maxCharacters)
|
|
166
|
+
maxCharacters = 99999;
|
|
167
|
+
return `<Body><Pull xmlns="http://schemas.xmlsoap.org/ws/2004/09/enumeration"><EnumerationContext>${enumerationContext}</EnumerationContext><MaxElements>${maxElements}</MaxElements><MaxCharacters>${maxCharacters}</MaxCharacters></Pull></Body>`;
|
|
168
|
+
},
|
|
184
169
|
/**
|
|
185
|
-
*
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
188
|
-
* @param wsmanClass string - name of WSMAN class being used
|
|
189
|
-
* @param data Array or Object being converted into XML format
|
|
170
|
+
* Body used for Create or Put actions
|
|
171
|
+
* @param wsmanClass AMT.Classes, IPS.Classes, or CIM.Classes
|
|
172
|
+
* @param data Object being applied to AMT
|
|
190
173
|
* @returns string
|
|
191
174
|
*/
|
|
192
|
-
this.createBody
|
|
193
|
-
if (!Array.isArray(data)) {
|
|
194
|
-
data = [data];
|
|
195
|
-
}
|
|
196
|
-
data === null || data === void 0 ? void 0 : data.forEach((element) => {
|
|
197
|
-
this.processBody(element);
|
|
198
|
-
});
|
|
199
|
-
let str = '<Body>';
|
|
200
|
-
str += `<h:${method} xmlns:h="${this.resourceUriBase}${wsmanClass}">`;
|
|
201
|
-
if (data) {
|
|
202
|
-
data.forEach((element) => {
|
|
203
|
-
str += this.OBJtoXML(element);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
str += `</h:${method}>`;
|
|
207
|
-
str += '</Body>';
|
|
208
|
-
return str;
|
|
209
|
-
};
|
|
175
|
+
CreateOrPut: (wsmanClass, data) => this.createBody(wsmanClass, wsmanClass, [data]),
|
|
210
176
|
/**
|
|
211
|
-
*
|
|
212
|
-
* @param
|
|
177
|
+
* Body used for RequestStateChange actions
|
|
178
|
+
* @param input namespace of the class being modified
|
|
179
|
+
* @param requestedState state being set
|
|
213
180
|
* @returns string
|
|
214
181
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
182
|
+
RequestStateChange: (input, requestedState) => `<Body><h:RequestStateChange_INPUT xmlns:h="${input}"><h:RequestedState>${requestedState.toString()}</h:RequestedState></h:RequestStateChange_INPUT></Body>`
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Creates a WSMAN Body for custom methods
|
|
186
|
+
* @param method string - methods not covered by createCommonBody()
|
|
187
|
+
* @param resourceUriBase string - URI address of the resource
|
|
188
|
+
* @param wsmanClass string - name of WSMAN class being used
|
|
189
|
+
* @param data Array or Object being converted into XML format
|
|
190
|
+
* @returns string
|
|
191
|
+
*/
|
|
192
|
+
createBody = (method, wsmanClass, data) => {
|
|
193
|
+
if (!Array.isArray(data)) {
|
|
194
|
+
data = [data];
|
|
195
|
+
}
|
|
196
|
+
data?.forEach((element) => {
|
|
197
|
+
this.processBody(element);
|
|
198
|
+
});
|
|
199
|
+
let str = '<Body>';
|
|
200
|
+
str += `<h:${method} xmlns:h="${this.resourceUriBase}${wsmanClass}">`;
|
|
201
|
+
if (data) {
|
|
202
|
+
data.forEach((element) => {
|
|
203
|
+
str += this.OBJtoXML(element);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
str += `</h:${method}>`;
|
|
207
|
+
str += '</Body>';
|
|
208
|
+
return str;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Converts JavaScript object to XML
|
|
212
|
+
* @param data JavaScript object
|
|
213
|
+
* @returns string
|
|
214
|
+
*/
|
|
215
|
+
OBJtoXML = (data) => {
|
|
216
|
+
let xml = '';
|
|
217
|
+
for (const prop in data) {
|
|
218
|
+
if (prop === 'namespace')
|
|
219
|
+
continue;
|
|
220
|
+
if (Array.isArray(data[prop])) {
|
|
221
|
+
xml += '';
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (data[prop] != null) {
|
|
225
|
+
if (data.namespace != null) {
|
|
226
|
+
xml += `<${prop} xmlns:q="${data.namespace}">`;
|
|
231
227
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
for (const arrayIdx in data[prop]) {
|
|
235
|
-
xml += `<${prop}`;
|
|
236
|
-
for (const attr in data[prop][arrayIdx].$) {
|
|
237
|
-
xml += ` ${attr}="${data[prop][arrayIdx].$[attr]}"`;
|
|
238
|
-
}
|
|
239
|
-
xml += '>';
|
|
240
|
-
xml += data[prop][arrayIdx]._ ? data[prop][arrayIdx]._ : data[prop][arrayIdx];
|
|
241
|
-
xml += `</${prop}>`;
|
|
228
|
+
else {
|
|
229
|
+
xml += `<${prop}>`;
|
|
242
230
|
}
|
|
243
231
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
xml += data[prop]
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
xml +=
|
|
253
|
-
|
|
254
|
-
else {
|
|
255
|
-
if (data[prop] != null)
|
|
256
|
-
xml += `</${prop}>`;
|
|
232
|
+
}
|
|
233
|
+
if (Array.isArray(data[prop])) {
|
|
234
|
+
for (const arrayIdx in data[prop]) {
|
|
235
|
+
xml += `<${prop}`;
|
|
236
|
+
for (const attr in data[prop][arrayIdx].$) {
|
|
237
|
+
xml += ` ${attr}="${data[prop][arrayIdx].$[attr]}"`;
|
|
238
|
+
}
|
|
239
|
+
xml += '>';
|
|
240
|
+
xml += data[prop][arrayIdx]._ ? data[prop][arrayIdx]._ : data[prop][arrayIdx];
|
|
241
|
+
xml += `</${prop}>`;
|
|
257
242
|
}
|
|
258
243
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Helper function for createBody() to ensure WSMAN namespaces are formatted correctly
|
|
263
|
-
* @param data JavaScript object
|
|
264
|
-
* @returns any
|
|
265
|
-
*/
|
|
266
|
-
this.processBody = (data, tag = 'h:') => {
|
|
267
|
-
if (Array.isArray(data)) {
|
|
268
|
-
return;
|
|
244
|
+
else if (typeof data[prop] === 'object') {
|
|
245
|
+
xml += this.OBJtoXML(data[prop]);
|
|
269
246
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
case 'ReferenceParameters':
|
|
274
|
-
this.prependObjectKey(data, val, 'a:');
|
|
275
|
-
break;
|
|
276
|
-
case 'SelectorSet':
|
|
277
|
-
case 'Selector':
|
|
278
|
-
case 'ResourceURI':
|
|
279
|
-
this.prependObjectKey(data, val, 'w:');
|
|
280
|
-
break;
|
|
281
|
-
case 'namespace':
|
|
282
|
-
break;
|
|
283
|
-
default:
|
|
284
|
-
this.prependObjectKey(data, val, tag);
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
247
|
+
else {
|
|
248
|
+
if (data[prop] != null)
|
|
249
|
+
xml += data[prop];
|
|
287
250
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
* Helper function for processBody() to assist with formatting
|
|
291
|
-
* @param data JavaScript object
|
|
292
|
-
* @param key string
|
|
293
|
-
* @param prefix string
|
|
294
|
-
* @returns void
|
|
295
|
-
*/
|
|
296
|
-
this.prependObjectKey = (data, key, prefix) => {
|
|
297
|
-
data[prefix + key] = data[key];
|
|
298
|
-
if (typeof data[key] === 'object') {
|
|
299
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
300
|
-
if (data['namespace'] != null) {
|
|
301
|
-
this.processBody(data[key], 'q:');
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this.processBody(data[key]);
|
|
305
|
-
}
|
|
251
|
+
if (Array.isArray(data[prop])) {
|
|
252
|
+
xml += '';
|
|
306
253
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
254
|
+
else {
|
|
255
|
+
if (data[prop] != null)
|
|
256
|
+
xml += `</${prop}>`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return xml;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* Helper function for createBody() to ensure WSMAN namespaces are formatted correctly
|
|
263
|
+
* @param data JavaScript object
|
|
264
|
+
* @returns any
|
|
265
|
+
*/
|
|
266
|
+
processBody = (data, tag = 'h:') => {
|
|
267
|
+
if (Array.isArray(data)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
for (const val in data) {
|
|
271
|
+
switch (val) {
|
|
272
|
+
case 'Address':
|
|
273
|
+
case 'ReferenceParameters':
|
|
274
|
+
this.prependObjectKey(data, val, 'a:');
|
|
275
|
+
break;
|
|
276
|
+
case 'SelectorSet':
|
|
277
|
+
case 'Selector':
|
|
278
|
+
case 'ResourceURI':
|
|
279
|
+
this.prependObjectKey(data, val, 'w:');
|
|
280
|
+
break;
|
|
281
|
+
case 'namespace':
|
|
282
|
+
break;
|
|
283
|
+
default:
|
|
284
|
+
this.prependObjectKey(data, val, tag);
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Helper function for processBody() to assist with formatting
|
|
291
|
+
* @param data JavaScript object
|
|
292
|
+
* @param key string
|
|
293
|
+
* @param prefix string
|
|
294
|
+
* @returns void
|
|
295
|
+
*/
|
|
296
|
+
prependObjectKey = (data, key, prefix) => {
|
|
297
|
+
data[prefix + key] = data[key];
|
|
298
|
+
if (typeof data[key] === 'object') {
|
|
299
|
+
if (data['namespace'] != null) {
|
|
300
|
+
this.processBody(data[key], 'q:');
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
this.processBody(data[key]);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
delete data[key];
|
|
307
|
+
};
|
|
311
308
|
}
|
|
312
|
-
|
|
313
|
-
|
|
309
|
+
export class Base {
|
|
310
|
+
wsmanMessageCreator;
|
|
311
|
+
className;
|
|
314
312
|
constructor(wsmanMessageCreator) {
|
|
315
|
-
/**
|
|
316
|
-
* Enumerates the instances of the class.
|
|
317
|
-
* @returns string
|
|
318
|
-
*/
|
|
319
|
-
this.Enumerate = () => {
|
|
320
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.ENUMERATE, this.className);
|
|
321
|
-
const body = this.wsmanMessageCreator.createCommonBody.Enumerate();
|
|
322
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* Gets the representation of the class.
|
|
326
|
-
* @param selector optional selector object for picking which item to get from an array of items
|
|
327
|
-
* @returns string
|
|
328
|
-
*/
|
|
329
|
-
this.Get = (selector) => {
|
|
330
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.GET, this.className, selector);
|
|
331
|
-
const body = this.wsmanMessageCreator.createCommonBody.Get();
|
|
332
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
333
|
-
};
|
|
334
|
-
/**
|
|
335
|
-
* Pulls an instances of the class, following an Enumerate operation.
|
|
336
|
-
* @param enumerationContext string returned from an Enumerate call.
|
|
337
|
-
* @returns string
|
|
338
|
-
*/
|
|
339
|
-
this.Pull = (enumerationContext) => {
|
|
340
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.PULL, this.className);
|
|
341
|
-
const body = this.wsmanMessageCreator.createCommonBody.Pull(enumerationContext);
|
|
342
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
343
|
-
};
|
|
344
|
-
/**
|
|
345
|
-
* Deletes and instance of the class
|
|
346
|
-
* @param selector Selector object
|
|
347
|
-
* @returns string
|
|
348
|
-
*/
|
|
349
|
-
this.protectedDelete = (selector) => {
|
|
350
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.DELETE, this.className, selector);
|
|
351
|
-
const body = this.wsmanMessageCreator.createCommonBody.Delete();
|
|
352
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
353
|
-
};
|
|
354
|
-
/**
|
|
355
|
-
* Modifies the properties of the class
|
|
356
|
-
* @param data data that will be used to update the class
|
|
357
|
-
* @param useHeaderSelector indicates if the call needs to use a selector in the header
|
|
358
|
-
* @param customSelector allows input of a custom selector
|
|
359
|
-
* @returns string
|
|
360
|
-
*/
|
|
361
|
-
this.protectedPut = (data, useHeaderSelector, customSelector) => {
|
|
362
|
-
if (!customSelector && (data === null || data === void 0 ? void 0 : data.InstanceID)) {
|
|
363
|
-
customSelector = { name: 'InstanceID', value: data.InstanceID };
|
|
364
|
-
}
|
|
365
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.PUT, this.className, useHeaderSelector ? customSelector : null);
|
|
366
|
-
const body = this.wsmanMessageCreator.createCommonBody.CreateOrPut(this.className, data);
|
|
367
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
368
|
-
};
|
|
369
|
-
/**
|
|
370
|
-
* Creates a new instance of the class
|
|
371
|
-
* @param data data that will be used to create the class
|
|
372
|
-
* @param selector Selector object
|
|
373
|
-
* @returns string
|
|
374
|
-
*/
|
|
375
|
-
this.protectedCreate = (data, selector) => {
|
|
376
|
-
const header = this.wsmanMessageCreator.createHeader(BaseActions.CREATE, this.className, selector);
|
|
377
|
-
const body = this.wsmanMessageCreator.createCommonBody.CreateOrPut(this.className, data);
|
|
378
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
379
|
-
};
|
|
380
|
-
/**
|
|
381
|
-
* Requests a change of state in AMT
|
|
382
|
-
* @param actionName resource that will have the state change
|
|
383
|
-
* @param requestedState the new state
|
|
384
|
-
* @returns string
|
|
385
|
-
*/
|
|
386
|
-
this.protectedRequestStateChange = (actionName, requestedState) => {
|
|
387
|
-
const header = this.wsmanMessageCreator.createHeader(actionName, this.className);
|
|
388
|
-
const body = this.wsmanMessageCreator.createCommonBody.RequestStateChange(`${this.wsmanMessageCreator.resourceUriBase}${this.className}`, requestedState);
|
|
389
|
-
return this.wsmanMessageCreator.createXml(header, body);
|
|
390
|
-
};
|
|
391
313
|
this.wsmanMessageCreator = wsmanMessageCreator;
|
|
392
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Enumerates the instances of the class.
|
|
317
|
+
* @returns string
|
|
318
|
+
*/
|
|
319
|
+
Enumerate = () => {
|
|
320
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.ENUMERATE, this.className);
|
|
321
|
+
const body = this.wsmanMessageCreator.createCommonBody.Enumerate();
|
|
322
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Gets the representation of the class.
|
|
326
|
+
* @param selector optional selector object for picking which item to get from an array of items
|
|
327
|
+
* @returns string
|
|
328
|
+
*/
|
|
329
|
+
Get = (selector) => {
|
|
330
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.GET, this.className, selector);
|
|
331
|
+
const body = this.wsmanMessageCreator.createCommonBody.Get();
|
|
332
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Pulls an instances of the class, following an Enumerate operation.
|
|
336
|
+
* @param enumerationContext string returned from an Enumerate call.
|
|
337
|
+
* @returns string
|
|
338
|
+
*/
|
|
339
|
+
Pull = (enumerationContext) => {
|
|
340
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.PULL, this.className);
|
|
341
|
+
const body = this.wsmanMessageCreator.createCommonBody.Pull(enumerationContext);
|
|
342
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Deletes and instance of the class
|
|
346
|
+
* @param selector Selector object
|
|
347
|
+
* @returns string
|
|
348
|
+
*/
|
|
349
|
+
protectedDelete = (selector) => {
|
|
350
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.DELETE, this.className, selector);
|
|
351
|
+
const body = this.wsmanMessageCreator.createCommonBody.Delete();
|
|
352
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Modifies the properties of the class
|
|
356
|
+
* @param data data that will be used to update the class
|
|
357
|
+
* @param useHeaderSelector indicates if the call needs to use a selector in the header
|
|
358
|
+
* @param customSelector allows input of a custom selector
|
|
359
|
+
* @returns string
|
|
360
|
+
*/
|
|
361
|
+
protectedPut = (data, useHeaderSelector, customSelector) => {
|
|
362
|
+
if (!customSelector && data?.InstanceID) {
|
|
363
|
+
customSelector = { name: 'InstanceID', value: data.InstanceID };
|
|
364
|
+
}
|
|
365
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.PUT, this.className, useHeaderSelector ? customSelector : null);
|
|
366
|
+
const body = this.wsmanMessageCreator.createCommonBody.CreateOrPut(this.className, data);
|
|
367
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Creates a new instance of the class
|
|
371
|
+
* @param data data that will be used to create the class
|
|
372
|
+
* @param selector Selector object
|
|
373
|
+
* @returns string
|
|
374
|
+
*/
|
|
375
|
+
protectedCreate = (data, selector) => {
|
|
376
|
+
const header = this.wsmanMessageCreator.createHeader(BaseActions.CREATE, this.className, selector);
|
|
377
|
+
const body = this.wsmanMessageCreator.createCommonBody.CreateOrPut(this.className, data);
|
|
378
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Requests a change of state in AMT
|
|
382
|
+
* @param actionName resource that will have the state change
|
|
383
|
+
* @param requestedState the new state
|
|
384
|
+
* @returns string
|
|
385
|
+
*/
|
|
386
|
+
protectedRequestStateChange = (actionName, requestedState) => {
|
|
387
|
+
const header = this.wsmanMessageCreator.createHeader(actionName, this.className);
|
|
388
|
+
const body = this.wsmanMessageCreator.createCommonBody.RequestStateChange(`${this.wsmanMessageCreator.resourceUriBase}${this.className}`, requestedState);
|
|
389
|
+
return this.wsmanMessageCreator.createXml(header, body);
|
|
390
|
+
};
|
|
393
391
|
}
|
|
394
|
-
exports.Base = Base;
|
|
395
392
|
//# sourceMappingURL=WSMan.js.map
|