mirror of
https://github.com/democratic-csi/democratic-csi.git
synced 2026-10-21 01:28:24 +02:00
support sudo setups, support apiKey with TrueNAS
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user