@configurator/ravendb
Version:
RavenDB client for Node.js
82 lines • 2.92 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateClientCertificateOperation = void 0;
const Exceptions_1 = require("../../../Exceptions");
const HttpUtil_1 = require("../../../Utility/HttpUtil");
const StreamUtil_1 = require("../../../Utility/StreamUtil");
const RavenCommand_1 = require("../../../Http/RavenCommand");
const RaftIdGenerator_1 = require("../../../Utility/RaftIdGenerator");
class CreateClientCertificateOperation {
constructor(name, permissions, clearance, password) {
if (!name) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Name cannot be null.");
}
if (!permissions) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Permissions cannot be null.");
}
this._name = name;
this._permissions = permissions;
this._clearance = clearance;
this._password = password;
}
get resultType() {
return "CommandResult";
}
getCommand(conventions) {
return new CreateClientCertificateCommand(this._name, this._permissions, this._clearance, this._password);
}
}
exports.CreateClientCertificateOperation = CreateClientCertificateOperation;
class CreateClientCertificateCommand extends RavenCommand_1.RavenCommand {
constructor(name, permissions, clearance, password) {
super();
if (!name) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Name cannot be null.");
}
if (!permissions) {
(0, Exceptions_1.throwError)("InvalidArgumentException", "Permissions cannot be null.");
}
this._name = name;
this._permissions = permissions;
this._clearance = clearance;
this._password = password;
this._responseType = "Raw";
}
get isReadRequest() {
return false;
}
createRequest(node) {
const uri = node.url + "/admin/certificates";
const body = this._serializer
.serialize({
Name: this._name,
SecurityClearance: this._clearance,
Password: this._password || undefined,
Permissions: this._permissions,
});
return {
method: "POST",
uri,
headers: (0, HttpUtil_1.getHeaders)()
.typeAppJson()
.build(),
body
};
}
setResponseRaw(response, body) {
super.setResponseRaw(response, body);
}
async setResponseAsync(bodyStream, fromCache) {
if (!bodyStream) {
this._throwInvalidResponse();
}
this.result = {
rawData: await (0, StreamUtil_1.readToBuffer)(bodyStream)
};
return null;
}
getRaftUniqueRequestId() {
return RaftIdGenerator_1.RaftIdGenerator.newId();
}
}
//# sourceMappingURL=CreateClientCertificateOperation.js.map