Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile refactoring changes #1889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions classes/CCR/DB/MySQLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,47 @@ public static function databaseExists(
throw new Exception($msg);
}
}
/*
* Checks for existence of user
*/
/**
* @throws Exception
*/
public static function userExists(
$host,
$port,
$dbusername,
$dbpassword,
$userName,
$xdmod_host
) {
$stmt = "SELECT User, Host FROM mysql.user WHERE User = '$userName' AND Host = '$xdmod_host'";
$output = static::staticExecuteStatement(
$host,
$port,
$dbusername,
$dbpassword,
null,
$stmt
);

$output = preg_replace('/\s+/', ' ', $output);
if (!isset($output[0])) {
return false;
}
$output = explode(' ', $output[0]);
if (count($output) == 0 || (count($output) == 1 && $output[0] == '')) {
return false;
} elseif (count($output) == 2 && $output[0] == $userName && $output[1]== $xdmod_host) {
return true;
} else {
$msg = 'Failed to check for existence of user: '
. implode("\n", array_map(function($row) {
return $row[0] . ' ' . $row[1];
}, $output));
throw new Exception($msg);
}
}

/**
* Create a database.
Expand Down Expand Up @@ -415,7 +456,7 @@ public static function grantAllPrivileges(
$port,
$username,
$password,
$localHost,
$xdmodHost,
$dbUsername,
$dbPassword
) {
Expand All @@ -429,8 +470,8 @@ public static function grantAllPrivileges(
. " CREATE ROUTINE, ALTER ROUTINE, EVENT, RELOAD, FILE,"
. " CREATE TABLESPACE, PROCESS, REFERENCES,"
. " LOCK TABLES"
. " ON *.* TO '$dbUsername'@'$localHost'"
. " IDENTIFIED BY '$dbPassword';FLUSH PRIVILEGES;";
. " ON *.* TO '$dbUsername'@'$xdmodHost';"
. " FLUSH PRIVILEGES;";

static::staticExecuteStatement(
$host,
Expand Down Expand Up @@ -460,11 +501,11 @@ public static function grantAllPrivilegesOnDatabase(
$username,
$password,
$dbName,
$localHost,
$xdmodHost,
$dbUsername,
$dbPassword
) {
$stmt = "GRANT ALL ON $dbName.* TO '$dbUsername'@'$localHost'"
$stmt = "GRANT ALL ON $dbName.* TO '$dbUsername'@'$xdmodHost'"
. " IDENTIFIED BY '$dbPassword'";

static::staticExecuteStatement(
Expand Down
5 changes: 4 additions & 1 deletion classes/OpenXdmod/Setup/DatabaseSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public function handle()
'DB Username:',
$settings['database_user']
);

$settings['xdmod_host'] = $this->console->prompt(
'XDMoD Server name:',
$settings['database_host']
);
$settings['db_pass'] = $this->console->silentPrompt(
'DB Password:'
);
Expand Down
49 changes: 37 additions & 12 deletions classes/OpenXdmod/Shared/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OpenXdmod\Shared;

use CCR\DB;
use CCR\DB\MySQLHelper;
use OpenXdmod\Setup\Console;

Expand All @@ -24,6 +25,7 @@ class DatabaseHelper
* @param Console $console (Optional) The console to use to prompt the user.
* If not provided, one will be obtained.
*/

public static function createDatabases(
$username,
$password,
Expand All @@ -35,23 +37,50 @@ public static function createDatabases(
$console = Console::factory();
}

$rows = MySQLHelper::userExists(
$settings['db_host'],
$settings['db_port'],
$username,
$password,
$settings['db_user'],
$settings['xdmod_host']
);
$console->displayMessage(
'Creating User ' . $settings['db_user']
'rows retuned' . $rows
);
// TODO: If db_host is not localhost, need to set $localHost to
// the correct hostname or IP address.
$localHost = $settings['db_host'];

if ($rows == false) {
$console->displayMessage(
'Creating User ' . $settings['db_user']
);
$console->displayMessage(
'Creating User with ' . $settings['db_user'] . ' on host ' . $settings['xdmod_host'] . ' with password ' . $settings['db_pass']
);
MySQLHelper::staticExecuteStatement(
$settings['db_host'],
$settings['db_port'],
$username,
$password,
null,
sprintf(
"CREATE USER '%s'@'%s' IDENTIFIED BY '%s';",
$settings['db_user'],
$settings['xdmod_host'],
$settings['db_pass'],
)
);
$console->displayMessage(
'Created User'
);
}
MySQLHelper::grantAllPrivileges(
$settings['db_host'],
$settings['db_port'],
$username,
$password,
$localHost,
$settings['xdmod_host'],
$settings['db_user'],
$settings['db_pass']
);

foreach ($databases as $database) {
$console->displayBlankLine();

Expand Down Expand Up @@ -97,10 +126,6 @@ public static function createDatabases(
$database
);

// TODO: If db_host is not localhost, need to set $localHost to
// the correct hostname or IP address.
$localHost = $settings['db_host'];

$console->displayMessage(
"Granting privileges on database `$database`."
);
Expand All @@ -110,7 +135,7 @@ public static function createDatabases(
$username,
$password,
$database,
$localHost,
$settings['xdmod_host'],
$settings['db_user'],
$settings['db_pass']
);
Expand Down
1 change: 1 addition & 0 deletions configuration/etl/etl_tables.d/cloud_common/domains.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "domains",
"engine": "InnoDB",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"comment": "Which domains are currently being tracked by the Cloud realm",
"columns": [
{
Expand Down
4 changes: 2 additions & 2 deletions configuration/etl/etl_tables.d/gateways/enduser.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "enduser",
"comment": "Associate local gateway enduser names with the gateway on which they are registered",
"engine": "myisam",
"charset": "utf8mb4",
"collation": "utf8mb4_general_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "int(11)",
Expand Down
4 changes: 2 additions & 2 deletions configuration/etl/etl_tables.d/gateways/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "gateway",
"comment": "Listing of Science Gateways",
"engine": "myisam",
"charset": "utf8mb4",
"collation": "utf8mb4_general_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "int(11)",
Expand Down
4 changes: 2 additions & 2 deletions configuration/etl/etl_tables.d/gateways/job_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "job_metadata",
"comment": "Metadata associated with gateways-submitted jobs",
"engine": "myisam",
"charset": "utf8mb4",
"collation": "utf8mb4_general_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "int(11)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
{
"name": "prefix",
"type": "varchar(191)",
"comment": "generally fqdn with . replaced by - 191 limit due to utf8mb4",
"comment": "generally fqdn with . replaced by - 191 limit due to utf8",
"nullable": true
},
{
"name": "timezone",
"type": "varchar(191)",
"comment": "Timezone of the instance - 191 limit due to utf8mb4",
"comment": "Timezone of the instance - 191 limit due to utf8",
"nullable": true
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"table_definition": {
"name": "ReportTemplateCharts",
"engine": "InnoDB",
"charset": "utf8mb4",
"collation": "utf8mb4_general_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"name": "template_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "normalize_table_test",
"engine": "MyISAM",
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"columns": [
{
"name": "resource_id",
Expand All @@ -17,7 +17,7 @@
"type": "varchar(40)",
"nullable": true,
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"comment": "This is a comment"
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"table_definition": {
"name": "normalize_table_test",
"engine": "myisam",
"charset": "UTF8",
"collation": "UTF8_GENERAL_CI",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"name": "resource_id",
Expand All @@ -16,8 +16,8 @@
"name": "RESOURCE",
"type": "VARCHAR(40)",
"nullable": true,
"charset": "UTF8",
"collation": "utf8_general_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"comment": "This is a comment"
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"comment": "",
"engine": "myisam",
"charset": "latin1",
"collation": "latin1_swedish_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "varchar(40)",
"charset": "latin1",
"collation": "latin1_swedish_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"nullable": true,
"default": null,
"extra": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"comment": "",
"engine": "myisam",
"charset": "latin1",
"collation": "latin1_swedish_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "varchar(40)",
"charset": "latin1",
"collation": "latin1_swedish_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"nullable": true,
"default": null,
"extra": null,
Expand All @@ -17,8 +17,8 @@
},
{
"type": "varchar(40)",
"charset": "latin1",
"collation": "latin1_swedish_ci",
"charset": "utf8",
"collation": "utf8_unicode_ci",
"nullable": true,
"default": null,
"extra": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"comment": "",
"engine": "myisam",
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"columns": [
{
"type": "int(11) unsigned",
Expand All @@ -18,7 +18,7 @@
{
"type": "varchar(40)",
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"nullable": true,
"default": null,
"extra": null,
Expand All @@ -29,7 +29,7 @@
{
"type": "varchar(16)",
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"nullable": false,
"default": "first name",
"extra": null,
Expand All @@ -40,7 +40,7 @@
{
"type": "enum('Sample1','sample2')",
"charset": "utf8",
"collation": "utf8_general_ci",
"collation": "utf8_unicode_ci",
"nullable": true,
"default": null,
"extra": null,
Expand Down Expand Up @@ -75,7 +75,7 @@
"event": "INSERT",
"table": "normalize_table_test",
"body": "BEGIN\nSET @resource = CONCAT(@resource, 'X');\nEND",
"definer": "xdmod@localhost",
"definer": "xdmod@xdmod.xdmod_default",
"schema": "test",
"name": "mytrigger"
}
Expand Down
Loading