[Title] Added default admin user, Added -U option for specifying user on build-cli
authordonghee yang <donghee.yang@samsung.com>
Mon, 29 Oct 2012 09:13:18 +0000 (18:13 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Mon, 29 Oct 2012 09:13:18 +0000 (18:13 +0900)
build-cli
src/build_server/BuildClientOptionParser.rb
src/build_server/BuildServer.rb
src/build_server/CommonJob.rb
src/build_server/ProjectManager.rb
src/build_server/SocketJobRequestListener.rb
test/build-server.basic1/build-cli-01.testcase
test/build-server.basic1/build-cli-30.testcase [new file with mode: 0644]
test/build-server.basic1/testsuite

index cfb2da93ba9cb649657ba3eb50092e9b75526287..e2bdf66c82f9753564c01d9aa2e6012541b89200 100755 (executable)
--- a/build-cli
+++ b/build-cli
@@ -161,7 +161,7 @@ begin
                end
                client = BuildCommClient.create( result[0], result[1], nil, 0 )
                if not client.nil? then
-                       client.send "BUILD|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:noreverse]}|#{option[:dist]}"
+                       client.send "BUILD|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:noreverse]}|#{option[:dist]}|#{option[:user]}"
                        if not client.print_stream then
                                puts "ERROR: #{client.get_error_msg()}"
                        end
@@ -181,7 +181,7 @@ begin
                end
                client = BuildCommClient.create( result[0], result[1], nil, 0 )
                if not client.nil? then
-                       client.send "RESOLVE|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:dist]}"
+                       client.send "RESOLVE|GIT|#{option[:project]}|#{option[:passwd]}|#{option[:os]}|#{option[:async]}|#{option[:dist]}|#{option[:user]}"
                        if not client.print_stream then
                                puts "ERROR: #{client.get_error_msg()}"
                        end
@@ -319,7 +319,7 @@ begin
                        puts "Can't access server #{bs_ip}:#{bs_port}"
                        exit(-1)
                end
-               client.send("REGISTER|BINARY|#{File.basename(option[:package])}|#{option[:passwd]}|#{dock}|#{option[:dist]}")
+               client.send("REGISTER|BINARY|#{File.basename(option[:package])}|#{option[:passwd]}|#{dock}|#{option[:dist]}|#{option[:user]}")
                if not client.print_stream then
                        puts "ERROR: #{client.get_error_msg()}"
                end
index b95cc4a1267b771609ad0c59cfcac9a35f73d40d..b7a57263aad4071f3167b9a603d0158d74d078a3 100644 (file)
@@ -31,14 +31,14 @@ require 'optparse'
 require 'utils'
 
 class BuildClientUsage
-       BUILD="build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]"
-       RESOLVE="build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]"
+       BUILD="build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email]"
+       RESOLVE="build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email]"
        QUERY="build-cli query -d <server address>"
        QUERY_SYSTEM="build-cli query-system -d <server address>"
        QUERY_PROJECT="build-cli query-project -d <server address>"
        QUERY_JOB="build-cli query-job -d <server address>"
        CANCEL="build-cli cancel -j <job number> -d <server address> [-w <password>]"
-       REGISTER="build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>]"
+       REGISTER="build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]"
 end
 
 
@@ -179,6 +179,11 @@ def option_parse
                        options[:fdomain] = domain
                end
 
+               options[:user] = "admin@user"
+               opts.on( '-U', '--user <user email>', 'user email infomation' ) do|user|
+                       options[:user] = user
+               end
+
                opts.on( '-h', '--help', 'display help' ) do
                        opts.help.split("\n").each {|op| puts op if not op.include? "--noreverse"}
                        exit
index 4fddc08009d8df4b5113f33bc5c70987b75309b0..25628877aa3b01fa603448886250889f904a6854 100644 (file)
@@ -598,9 +598,11 @@ class BuildServer
                        db.do "CREATE TABLE supported_os(name VARCHAR(32) PRIMARY KEY)"
 
                        # USERS/GROUPS
-                       db.do "CREATE TABLE users(id INTEGER PRIMARY KEY #{inc}, email VARCHAR(256), password_hash VARCHAR(256), password_salt VARCHAR(256), name VARCHAR(256), group_id INTEGER)"
-                       db.do "CREATE TABLE groups(id INTEGER PRIMARY KEY #{inc}, name VARCHAR(256))"
-                       db.do "CREATE TABLE group_project_accesses(group_id INTEGER, prj_id INTEGER, build VARCHAR(32))"
+                       db.do "CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY #{inc}, email VARCHAR(256), password_hash VARCHAR(256), password_salt VARCHAR(256), name VARCHAR(256), group_id INTEGER)"
+                       db.do "CREATE TABLE IF NOT EXISTS groups(id INTEGER PRIMARY KEY #{inc}, name VARCHAR(256))"
+                       db.do "CREATE TABLE IF NOT EXISTS group_project_accesses(group_id INTEGER, prj_id INTEGER, build VARCHAR(32))"
+                       db.do "INSERT INTO groups VALUES (0, 'administrators')"
+                       db.do "INSERT INTO users VALUES (0, 'admin@user', '', '', 'admin', 0)"
 
                        # PROJECTS
                        db.do "CREATE TABLE projects(id INTEGER PRIMARY KEY #{inc}, name VARCHAR(32), ptype VARCHAR(32), password VARCHAR(32), dist_name VARCHAR(32))"
@@ -646,5 +648,41 @@ class BuildServer
                @db = db
                return @db
        end
+
+
+       def check_user_id_from_email(user_email)
+               begin
+                       db = get_db_connection()
+                       row = db.select_one("SELECT * FROM users WHERE email='#{user_email}'")
+                       if not row.nil?  then
+                               return row['id']
+                       else
+                               return -1 
+                       end
+               rescue DBI::DatabaseError => e
+                       @log.error "DB failed!"
+                       @log.error e.errstr
+                       @log.error e.backtrace.inspect
+               end
+
+               return -1
+       end
+
+
+       def qualify_admin_to_access(prj_id)
+               begin
+                       db = get_db_connection()
+                       row = db.select_one("SELECT * FROM group_project_accesses WHERE group_id=0 and prj_id=#{prj_id}")
+                       if row.nil?  then
+                               db.do("INSERT INTO group_project_accesses VALUES(0, #{prj_id}, 'TRUE')")
+                       else
+                               db.do("UPDATE group_project_accesses SET build='TRUE' WHERE group_id=0 and prj_id=#{prj_id}")
+                       end
+               rescue DBI::DatabaseError => e
+                       @log.error "DB failed!"
+                       @log.error e.errstr
+                       @log.error e.backtrace.inspect
+               end
+       end
 end
 
index 00f69d1da70e5e4e2debf2feaeb08f94ce5b930f..e8faf78f04a870dc120aa173fcecbb7b8b9cc566 100644 (file)
@@ -120,6 +120,12 @@ class CommonJob
        end
 
 
+       public
+       def set_user_id( id )
+               @user_id = id
+       end
+
+
        # execute
        public
        def execute(sync=false)
index 7cef95210f2550689cc8c1caaa0e5a782822cf75..07310914910235e7f38d074de4e65ea20ab9abd6 100644 (file)
@@ -112,6 +112,7 @@ class ProjectManager
 
 
        def add_git_project(name, repos, branch, passwd, os_list, dist_name)
+               new_prj = nil
                begin
                        db = @server.get_db_connection()
                        db['AutoCommit'] = false
@@ -142,12 +143,16 @@ class ProjectManager
                        db['AutoCommit'] = true if not db.nil?
                end
 
+               # authorize admin to access
+               @server.qualify_admin_to_access(new_prj.get_project_id())
+
                @server.log.info "Added new GIT project \"#{name}\"(#{dist_name})"
                return true
        end
 
 
        def add_binary_project(name, pkg_name, passwd, os_list, dist_name)
+               new_prj = nil
                begin
                        db = @server.get_db_connection()
                        db['AutoCommit'] = false
@@ -170,7 +175,7 @@ class ProjectManager
                                # init
                                new_prj.init()
                        end
-       
+
                rescue DBI::DatabaseError => e
                        @server.log.error "DB failed!"
                        @server.log.error e.errstr
@@ -181,6 +186,9 @@ class ProjectManager
                        db['AutoCommit'] = true if not db.nil?
                end
 
+               # authorize admin to access
+               @server.qualify_admin_to_access(new_prj.get_project_id())
+       
                @server.log.info "Added new BINARY project \"#{name}\"(#{dist_name})"
                return true
        end
index 57bb66f3bacfdee93c19b37ce54d410576cdd672..1ca0714176a53e77e4f316cfef1f664635ef434e 100644 (file)
@@ -186,8 +186,8 @@ class SocketJobRequestListener
                        raise "Invalid request format is used: #{line}"
                end
 
-               # Case1. BUILD|GIT|project_name|passwd|os_list|async|no_reverse|dist_name
-               # Case2. BUILD|GIT|git_repos||os|async|no_reverse|internal|rev_build|commit|pkgs|dock_num|dist_name
+               # Case1. BUILD|GIT|project_name|passwd|os_list|async|no_reverse|dist_name|user_email
+               # Case2. BUILD|GIT|git_repos||os|async|no_reverse|internal|rev_build|commit|pkgs|dock_num|dist_name|user_email
 
                # parse
                project_name_list = tok[2].split(",")
@@ -203,8 +203,10 @@ class SocketJobRequestListener
                dock_num = (not tok[11].nil? and not tok[11].empty?) ? tok[11].strip : "0"
                if not is_internal then
                        dist_name = tok[7].strip
+                       user_email = tok[8].strip
                else
                        dist_name = tok[12].strip
+                       user_email = tok[13].strip
                end
                if (dist_name.nil? or dist_name.empty?) then
                        dist_name = @parent_server.distmgr.get_default_distribution_name()
@@ -272,6 +274,18 @@ class SocketJobRequestListener
                        raise "No valid jobs!"
                end
 
+               # check user email
+               user_id = @parent_server.check_user_id_from_email( user_email )
+               if user_id != -1 then
+                       new_job.set_user_id( user_id )
+               else
+                       BuildCommServer.send_begin(req)
+                       req.puts "Error: Cannot find the user with \"#{user_email}\"!"
+                       BuildCommServer.send_end(req)
+                       raise "No user information!"
+               end
+
+               # check reverse build
                if no_reverse then new_job.set_no_reverse end
 
                # create logger and set
index 83852c384328e3f3cd746168e9c7d70f3dab269d..f414dcc2e5afdc8eea006f806e491a4cfbdb1468 100644 (file)
@@ -18,14 +18,14 @@ cancel        Cancel a building project.
 register      Register the package to the build-server.
 
 Subcommand usage:
-build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]
-build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>]
+build-cli build -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email]
+build-cli resolve -N <project name> -d <server address> [-o <os>] [-w <password>] [--async] [-D <distribution name>] [-U user-email]
 build-cli query -d <server address>
 build-cli query-system -d <server address>
 build-cli query-project -d <server address>
 build-cli query-job -d <server address>
 build-cli cancel -j <job number> -d <server address> [-w <password>]
-build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>]
+build-cli register -P <package file> -d <server address>  [-t <ftp server url>] [-w <password>] [-D <distribution name>] [-U user-email]
 
 Options:
 -N, --project <project name>     project name
@@ -37,5 +37,6 @@ Options:
 -P, --pkg <package file>         package file path
 -D, --dist <distribution name>   distribution name
 -t, --ftp <ftp server url>       ftp server url: ftp://dibsftp:dibsftp@127.0.0.1
+-U, --user <user email>          user email infomation
 -h, --help                       display help
 -v, --version                    display version
diff --git a/test/build-server.basic1/build-cli-30.testcase b/test/build-server.basic1/build-cli-30.testcase
new file mode 100644 (file)
index 0000000..33a5460
--- /dev/null
@@ -0,0 +1,7 @@
+#PRE-EXEC
+echo "user check"
+#EXEC
+../../build-cli build -N testa -d 127.0.0.1:2223 -o ubuntu-32 -U xxuser@user
+#POST-EXEC
+#EXPECT
+Error: Cannot find the user with "xxuser@user"!
index 9904eb3e86ed58ea8f8f25cc5c16ac9b1fafaa9d..b5b590390cefcd6bef537798069d7849fbb09323 100644 (file)
@@ -28,3 +28,4 @@ build-cli-26.testcase
 build-cli-27.testcase
 build-cli-28.testcase
 build-cli-29.testcase
+build-cli-30.testcase