Ejemplo n.º 1
0
 def remove_user(self):
     pghba = PgHba()
     for role in ('dsp_role1', 'dsp_role2', 'dsp_role3', 'dsp_role4', 'dsp_role5'):
         entries = pghba.search( user = role )
         for ent in entries:
             ent.delete()
         pghba.write()
     gpstop = GpStop()
     gpstop.run_gpstop_cmd(reload=True) # reload to activate the users
Ejemplo n.º 2
0
 def remove_user(self, role):
     """
     @description: Remove an entry for user in pg_hba.conf
     """
     pghba = PgHba()
     entries = pghba.search( user = role )
     for ent in entries:
         ent.delete()
     pghba.write()
     gpstop = GpStop()
     gpstop.run_gpstop_cmd(reload=True) # reload to activate the users
Ejemplo n.º 3
0
 def remove_user(self, role):
     """
     @description: Remove an entry for user in pg_hba.conf
     """
     pghba = PgHba()
     entries = pghba.search( user = role )
     for ent in entries:
         ent.delete()
     pghba.write()
     gpstop = GpStop()
     gpstop.run_gpstop_cmd(reload=True) # reload to activate the users
Ejemplo n.º 4
0
    def __addEntryHBA(self, usr):
        """
        Add an entry to $MASTER_DATA_DIRECTORY/pg_hba.conf,
        so that a specified user can access the database from any IP addresses.
         Commands:
         "local all usr trust" >> $MASTER_DATA_DIRECTORY/pg_hba.conf0
            gpstop -u
        @note: If the entry already exists, nothing will be done.
        @param usr: name of the user to be added to pg_hba.conf.
        @param ent: an entry object from PgHba.py which represents a PGHBA_CONF entry
        @raise GpUserRoleError: if pg_hba.conf can not be accessed.
        @return: None.
        
        @change: Johnny Soedomo
        Uses fileUtil to search and append content
        
        @change: Ritesh Jaltare
        Uses PgHba.py to create entry and remove fileUtil
        Uses lib.util.network to get ipv4 and ipv6 address
        Uses lib.modules.gpdb.Gpstop.gpstop_reload
        Add an entry, uses lib.Globals, use location of PGPASSFILE, default is home folder ~/.pgpass
        """
        try:
            #add an entry to the PGPASS file if the the user doesn't exist already
            if not self.searchForUserEntry(PGPASSFILE, r'%s:.*:%s:.*' % (self.host, usr)):   
                if self.password is None:
                        fileUtil.append_content("%s:*:%s:%s:password" % (self.host, self.pgpassdb, usr), PGPASSFILE, self.host)
                else:
                        fileUtil.append_content("%s:*:%s:%s:%s" % (self.host, self.pgpassdb, usr, self.password), PGPASSFILE, self.host)
            #search if the entry for user already exists in PGHBA_CONF          
            if self.searchForUserEntry(PGHBA_CONF, r'.*\s+.*\s+%s\s+.*\s+.*' % usr):
                return False
            pghba = PgHba()
            netobj = network()
            ipv4 = netobj.get_ipv4()
            ipv6 = netobj.get_ipv6()
            
            #add entry if ipv4 address exits
            if ipv4 is not "":
                ipv4 += "/32"
                ent1 = Entry(entry_type=self.entry_type, database=self.db,user=usr, authmethod=self.authmethod, address=ipv4)
                pghba.add_entry(ent1)
                
            #add entry if ipv6 address exists
            if ipv6 is not "":
                ipv6 += "/128"
		ent2 = Entry(entry_type=self.entry_type, database=self.db, user=usr, authmethod=self.authmethod, address=ipv6)
                pghba.add_entry(ent2)    
            pghba.write()
            return True
        except Exception, e:
            raise GpUserRoleError("Error in adding user %s to pg_hba.conf" % (usr))
Ejemplo n.º 5
0
    def add_user(self):
        """
        @description: Add an entry for each user in pg_hba.conf
        """
        pghba = PgHba()
        for role in ("dsp_role1", "dsp_role2", "dsp_role3", "dsp_role4", "dsp_role5"):
            new_entry = Entry(entry_type="local", database="all", user=role, authmethod="password")
            pghba.add_entry(new_entry)
            pghba.write()
            # Check if the roles are added correctly
            res = pghba.search(type="local", database="all", user=role, authmethod="password")
            if not res:
                raise Exception("The entry is not added to pg_hba.conf correctly")

        gpstop = GpStop()
        gpstop.run_gpstop_cmd(reload=True)  # reload to activate the users
Ejemplo n.º 6
0
    def add_user(self, role, mode):
        """
        @description: Add an entry for each user in pg_hba.conf
        """
        pghba = PgHba()
        new_entry = Entry(entry_type='local',
                            database = 'all',
                            user = role,
                            authmethod = mode)
        pghba.add_entry(new_entry)
        pghba.write()
        # Check if the roles are added correctly
        res = pghba.search(type='local',
                        database='all',
                        user = role,
                        authmethod= mode)
        if not res:
            raise Exception('The entry is not added to pg_hba.conf correctly')

        gpstop = GpStop()
        gpstop.run_gpstop_cmd(reload=True) # reload to activate the users
Ejemplo n.º 7
0
    def add_user(self, role, mode):
        """
        @description: Add an entry for each user in pg_hba.conf
        """
        pghba = PgHba()
        new_entry = Entry(entry_type='local',
                            database = 'all',
                            user = role,
                            authmethod = mode)
        pghba.add_entry(new_entry)
        pghba.write()
        # Check if the roles are added correctly
        res = pghba.search(type='local',
                        database='all',
                        user = role,
                        authmethod= mode)
        if not res:
            raise Exception('The entry is not added to pg_hba.conf correctly')

        gpstop = GpStop()
        gpstop.run_gpstop_cmd(reload=True) # reload to activate the users