Make database parameter optional. (#22) (#23)

By making the database optional opens the scenario where we just want
to issue commands on the server (eg: to create a database),

- Fix: If the database name had spaces `mysql` call would fail
- Pass the password as an environment variable instead of command line.
Eliminates warning that password method passing is insecure.
This commit is contained in:
aksm-ms 2020-10-14 15:18:25 +05:30 коммит произвёл GitHub
Родитель 645ae45c12
Коммит ccc25d2410
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 45 добавлений и 9 удалений

Просмотреть файл

@ -29,7 +29,20 @@ class AzureMySqlAction {
return __awaiter(this, void 0, void 0, function* () {
core.debug('Begin executing action...');
let mySqlClientPath = yield AzureMySqlActionHelper_1.default.getMySqlClientPath();
yield exec.exec(`"${mySqlClientPath}" -h ${this._inputs.serverName} -D ${this._inputs.connectionString.database} -u ${this._inputs.connectionString.userId} ${this._inputs.additionalArguments} -e "source ${this._inputs.sqlFile}"`, [`--password=${this._inputs.connectionString.password}`]);
let parameters = [
"-h", this._inputs.serverName,
"-u", this._inputs.connectionString.userId,
"-e", `source ${this._inputs.sqlFile}`,
];
if (this._inputs.connectionString.database) {
parameters.push("-D");
parameters.push(this._inputs.connectionString.database);
}
yield exec.exec(`"${mySqlClientPath}" ${this._inputs.additionalArguments}`, parameters, {
env: {
"MYSQL_PWD": this._inputs.connectionString.password
}
});
console.log('Successfully executed sql file on target database');
});
}

Просмотреть файл

@ -101,8 +101,8 @@ class MySqlConnectionStringBuilder {
}
}
}
if (!parsedConnectionString.server || !parsedConnectionString.userId || !parsedConnectionString.password || !parsedConnectionString.database) {
throw new Error(`Missing required keys in connection string. Please ensure that the keys 'Server', 'User Id', 'Password', 'Database' are provided in the connection string.`);
if (!parsedConnectionString.server || !parsedConnectionString.userId || !parsedConnectionString.password) {
throw new Error(`Missing required keys in connection string. Please ensure that the keys 'Server', 'User Id', 'Password' are provided in the connection string.`);
}
return parsedConnectionString;
}

Просмотреть файл

@ -31,10 +31,13 @@ class MySqlUtils {
try {
core.debug(`Validating if client has access to MySql Server '${serverName}'.`);
core.debug(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`);
yield exec.exec(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`, [`--password=${connectionString.password}`], {
yield exec.exec(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`, [], {
silent: true,
listeners: {
stderr: (data) => mySqlError += data.toString()
},
env: {
"MYSQL_PWD": connectionString.password
}
});
}

Просмотреть файл

@ -17,9 +17,26 @@ export default class AzureMySqlAction {
public async execute() {
core.debug('Begin executing action...');
let mySqlClientPath = await AzureMySqlActionHelper.getMySqlClientPath();
await exec.exec(`"${mySqlClientPath}" -h ${this._inputs.serverName} -D ${this._inputs.connectionString.database} -u ${this._inputs.connectionString.userId} ${this._inputs.additionalArguments} -e "source ${this._inputs.sqlFile}"`, [`--password=${this._inputs.connectionString.password}`]);
let parameters = [
"-h", this._inputs.serverName,
"-u", this._inputs.connectionString.userId,
"-e", `source ${this._inputs.sqlFile}`,
]
if (this._inputs.connectionString.database) {
parameters.push("-D")
parameters.push(this._inputs.connectionString.database)
}
await exec.exec(`"${mySqlClientPath}" ${this._inputs.additionalArguments}`,
parameters, {
env: {
"MYSQL_PWD": this._inputs.connectionString.password
}
});
console.log('Successfully executed sql file on target database');
}

Просмотреть файл

@ -113,8 +113,8 @@ export default class MySqlConnectionStringBuilder {
}
}
if (!parsedConnectionString.server || !parsedConnectionString.userId || !parsedConnectionString.password || !parsedConnectionString.database) {
throw new Error(`Missing required keys in connection string. Please ensure that the keys 'Server', 'User Id', 'Password', 'Database' are provided in the connection string.`);
if (!parsedConnectionString.server || !parsedConnectionString.userId || !parsedConnectionString.password) {
throw new Error(`Missing required keys in connection string. Please ensure that the keys 'Server', 'User Id', 'Password' are provided in the connection string.`);
}
return parsedConnectionString;

Просмотреть файл

@ -11,10 +11,13 @@ export default class MySqlUtils {
try {
core.debug(`Validating if client has access to MySql Server '${serverName}'.`);
core.debug(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`);
await exec.exec(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`, [`--password=${connectionString.password}`], {
await exec.exec(`"${mySqlClientPath}" -h ${serverName} -u "${connectionString.userId}" -e "show databases"`, [], {
silent: true,
listeners: {
stderr: (data: Buffer) => mySqlError += data.toString()
},
env: {
"MYSQL_PWD": connectionString.password
}
});
}