You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2017/04/14 20:23:31 UTC

[07/13] incubator-trafficcontrol git commit: added better usage and removed the create_user function

added better usage and removed the create_user function


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/a6bf5588
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/a6bf5588
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/a6bf5588

Branch: refs/heads/master
Commit: a6bf558867ef8688c453567e103e9e2f706d9e4d
Parents: d7494ad
Author: Dewayne Richardson <de...@apache.org>
Authored: Thu Apr 13 10:47:09 2017 -0600
Committer: Dan Kirkwood <da...@gmail.com>
Committed: Fri Apr 14 14:22:51 2017 -0600

----------------------------------------------------------------------
 traffic_ops/app/db/admin.pl | 53 +++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/a6bf5588/traffic_ops/app/db/admin.pl
----------------------------------------------------------------------
diff --git a/traffic_ops/app/db/admin.pl b/traffic_ops/app/db/admin.pl
index 3e9488d..e8391b8 100755
--- a/traffic_ops/app/db/admin.pl
+++ b/traffic_ops/app/db/admin.pl
@@ -37,11 +37,30 @@ my $usage = "\n"
 	. "Example:  $PROGRAM_NAME --env=test reset\n\n"
 	. "Purpose:  This script is used to manage database. The environments are\n"
 	. "          defined in the dbconf.yml, as well as the database names.\n\n"
-	. "arguments:   \n\n"
+	. "NOTE: \n"
+	. "Postgres Superuser: The 'postgres' superuser needs to be created to run $PROGRAM_NAME and setup databases.\n"
+	. "If the 'postgres' superuser hasn't been created or password has been set then run the following commands accordingly. \n\n"
+	. "Create the 'postgres' user (if not created):\n"
+	. "     \$ createuser postgres\n\n"
+	. "Set the 'postgres' user password:\n"
+	. "     ALTER ROLE postgres WITH ENCRYPTED PASSWORD 'yourpassword'; \n\n"
+	. "Postgres Password: file allows for easy command line access by defaulting the user and password for the database\n"
+	. "without prompts.\n\n"
+	. " Postgres .pgpass file format:\n"
+	. " hostname:port:database:username:password\n\n"
+	. " ----------------------\n"
+	. " Example Contents\n"
+	. " ----------------------\n"
+	. " *:*:*:postgres:yourpassword \n"
+	. " ----------------------\n\n"
+	. " Save the following example into this file $HOME/.pgpass with the permissions of this file\n"
+	. " so only $USER can read and write.\n\n"
+	. "     \$ chmod 0600 $HOME/.pgpass\n\n"
+	. "===================================================================================================================\n"
+	. "$PROGRAM_NAME arguments:   \n\n"
 	. "createdb  - Execute db 'createdb' the database for the current environment.\n"
 	. "dropdb  - Execute db 'dropdb' on the database for the current environment.\n"
 	. "down  - Roll back a single migration from the current version.\n"
-	. "create_superuser  - Execute 'create_superuser' the user for the current environment (postgres).\n"
 	. "create_user  - Execute 'create_user' the user for the current environment (traffic_ops).\n"
 	. "drop_user  - Execute 'drop_user' the user for the current environment (traffic_ops).\n"
 	. "show_users  - Execute sql to show all of the user for the current environment.\n"
@@ -59,6 +78,7 @@ my $db_protocol;
 # you don't have to specify --env=development for dev workstations
 my $db_name     = 'to_development';
 my $db_super_user = 'postgres';
+my $db_replication_user = 'to_replication';
 my $db_user = 'traffic_ops';
 my $db_password = '';
 my $host_ip     = '';
@@ -77,9 +97,6 @@ if ( defined($argument) ) {
 	elsif ( $argument eq 'dropdb' ) {
 		dropdb();
 	}
-	elsif ( $argument eq 'create_superuser' ) {
-		create_superuser();
-	}
 	elsif ( $argument eq 'create_user' ) {
 		create_user();
 	}
@@ -202,37 +219,13 @@ sub createdb {
 sub create_user {
 	my $user_exists = `psql -h $host_ip -p $host_port -U $db_user -tAc "SELECT 1 FROM pg_roles WHERE rolname='$db_user'"`;
 
-	my $cmd = "CREATE USER $db_user WITH CREATEDB ENCRYPTED PASSWORD '$db_password'";
+	my $cmd = "CREATE USER $db_user WITH LOGIN ENCRYPTED PASSWORD '$db_password'";
 	if ( system(qq{psql -h $host_ip -p $host_port -U $db_super_user -tAc "$cmd"}) != 0 ) {
 		die "Can't create user $db_user\n";
 	}
 	update_pgpass($db_user, $db_password);
 }
 
-sub create_superuser {
-
-	system('stty', '-echo');  # Disable echoing
-	print "Set a password for the 'postgres' superuser: ";
-	my $db_super_user_password = <STDIN>; 
-	chomp $db_super_user_password; 
-	exit 0 if ($db_super_user_password eq ""); # If empty string, exit.
-
-    my $cmd;
-	my $user_exists = `psql -h $host_ip -p $host_port -U $db_super_user -tAc "SELECT 1 FROM pg_roles WHERE rolname='$db_super_user'"`;
-    if  ( $user_exists ) {
-   	   $cmd = "ALTER ROLE $db_super_user WITH ENCRYPTED PASSWORD '$db_super_user_password'";
-	   if ( system(qq{psql -h $host_ip -p $host_port -U $db_super_user -tAc "$cmd"}) != 0 ) {
-		 die "Can't alter user $db_super_user\n";
-	   }
-    } else {
-   	   $cmd = "CREATE USER $db_super_user WITH CREATEDB ENCRYPTED PASSWORD '$db_super_user_password'";
-	   if ( system(qq{psql -h $host_ip -p $host_port -U $db_super_user -tAc "$cmd"}) != 0 ) {
-		 die "Can't create user $db_super_user\n";
-	   }
-    }
-	update_pgpass($db_super_user, $db_super_user_password);
-}
-
 sub drop_user {
 	if ( system("dropuser -h $host_ip -p $host_port -i -e $db_user;") != 0 ) {
 		die "Can't drop user $db_user\n";