support sudo setups, support apiKey with TrueNAS

This commit is contained in:
Travis Glenn Hansen
2020-11-21 17:15:22 -07:00
parent 52741d3e24
commit 61a4adc6d1
8 changed files with 104 additions and 27 deletions
+13 -6
View File
@@ -260,14 +260,21 @@ delete ${iscsiName}
const sshClient = this.getSshClient();
data = data.trim();
let command = "sh";
let args = ["-c"];
let command = [];
command.push(`echo "${data}"`.trim());
command.push("|");
command.push("targetcli");
let taregetCliCommand = [];
taregetCliCommand.push(`echo "${data}"`.trim());
taregetCliCommand.push("|");
taregetCliCommand.push("targetcli");
args.push("'" + command.join(" ") + "'");
return sshClient.exec(sshClient.buildCommand("sh", args));
if (this.options.iscsi.shareStragetyTargetCli.sudoEnabled) {
command = "sudo";
args.unshift("sh");
}
args.push("'" + taregetCliCommand.join(" ") + "'");
return sshClient.exec(sshClient.buildCommand(command, args));
}
}
+27
View File
@@ -135,9 +135,24 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver {
options.paths = this.options.zfs.cli.paths;
}
if (
this.options.zfs.hasOwnProperty("cli") &&
this.options.zfs.cli.hasOwnProperty("sudoEnabled")
) {
options.sudo = this.getSudoEnabled();
}
return new Zetabyte(options);
}
getSudoEnabled() {
return this.options.zfs.cli.sudoEnabled === true;
}
getSudoPath() {
return this.options.zfs.cli.paths.sudo || "/usr/bin/sudo";
}
getDatasetParentName() {
let datasetParentName = this.options.zfs.datasetParentName;
datasetParentName = datasetParentName.replace(/\/$/, "");
@@ -671,6 +686,10 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver {
this.options.zfs.datasetPermissionsMode,
properties.mountpoint.value,
]);
if (this.getSudoEnabled()) {
command = this.getSudoPath() + " " + command;
}
driver.ctx.logger.verbose("set permission command: %s", command);
response = await sshClient.exec(command);
}
@@ -690,6 +709,10 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver {
: ""),
properties.mountpoint.value,
]);
if (this.getSudoEnabled()) {
command = this.getSudoPath() + " " + command;
}
driver.ctx.logger.verbose("set ownership command: %s", command);
response = await sshClient.exec(command);
}
@@ -703,6 +726,10 @@ class ControllerZfsSshBaseDriver extends CsiBaseDriver {
acl,
properties.mountpoint.value,
]);
if (this.getSudoEnabled()) {
command = this.getSudoPath() + " " + command;
}
driver.ctx.logger.verbose("set acl command: %s", command);
response = await sshClient.exec(command);
}
+41 -21
View File
@@ -19,7 +19,7 @@ class Client {
host: server.host,
port: server.port,
//userinfo: server.username + ":" + server.password,
path: server.apiVersion == 1 ? "/api/v1.0" : "/api/v2.0"
path: server.apiVersion == 1 ? "/api/v1.0" : "/api/v2.0",
};
return URI.serialize(options);
}
@@ -55,22 +55,27 @@ class Client {
headers: {
Accept: "application/json",
"User-Agent": USER_AGENT,
"Content-Type": "application/json"
"Content-Type": "application/json",
},
json: true,
qs: data,
agentOptions: {
rejectUnauthorized: !!!client.options.allowInsecure
}
rejectUnauthorized: !!!client.options.allowInsecure,
},
};
request(options, function(err, res, body) {
request(options, function (err, res, body) {
client.log_repsonse(...arguments, options);
if (err) {
reject(err);
}
resolve(res);
}).auth(client.options.username, client.options.password);
}).auth(
client.options.username,
client.options.password,
true,
client.options.apiKey
);
});
}
@@ -87,22 +92,27 @@ class Client {
headers: {
Accept: "application/json",
"User-Agent": USER_AGENT,
"Content-Type": "application/json"
"Content-Type": "application/json",
},
json: true,
body: data,
agentOptions: {
rejectUnauthorized: !!!client.options.allowInsecure
}
rejectUnauthorized: !!!client.options.allowInsecure,
},
};
request(options, function(err, res, body) {
request(options, function (err, res, body) {
client.log_repsonse(...arguments, options);
if (err) {
reject(err);
}
resolve(res);
}).auth(client.options.username, client.options.password);
}).auth(
client.options.username,
client.options.password,
true,
client.options.apiKey
);
});
}
@@ -119,22 +129,27 @@ class Client {
headers: {
Accept: "application/json",
"User-Agent": USER_AGENT,
"Content-Type": "application/json"
"Content-Type": "application/json",
},
json: true,
body: data,
agentOptions: {
rejectUnauthorized: !!!client.options.allowInsecure
}
rejectUnauthorized: !!!client.options.allowInsecure,
},
};
request(options, function(err, res, body) {
request(options, function (err, res, body) {
client.log_repsonse(...arguments, options);
if (err) {
reject(err);
}
resolve(res);
}).auth(client.options.username, client.options.password);
}).auth(
client.options.username,
client.options.password,
true,
client.options.apiKey
);
});
}
@@ -151,22 +166,27 @@ class Client {
headers: {
Accept: "application/json",
"User-Agent": USER_AGENT,
"Content-Type": "application/json"
"Content-Type": "application/json",
},
json: true,
body: data,
agentOptions: {
rejectUnauthorized: !!!client.options.allowInsecure
}
rejectUnauthorized: !!!client.options.allowInsecure,
},
};
request(options, function(err, res, body) {
request(options, function (err, res, body) {
client.log_repsonse(...arguments, options);
if (err) {
reject(err);
}
resolve(res);
}).auth(client.options.username, client.options.password);
}).auth(
client.options.username,
client.options.password,
true,
client.options.apiKey
);
});
}
}