def ensure_protect(protect_lines): """Require that 'p4 protect' table includes grant of admin to git-fusion-user. """ with p4.at_exception_level(p4.RAISE_NONE): r = p4.run('protects', '-m', '-u', p4gf_const.P4GF_USER) if p4gf_p4msg.find_msgid(p4, p4gf_p4msgid.MsgDm_ProtectsEmpty): report(INFO, "Protect table empty. Setting....") report(DEBUG, 'p4 protects -mu git-fusion-user\n{}'.format(r)) perm = p4gf_util.first_value_for_key(r, KEY_PERM_MAX) if perm and perm in ['admin', 'super']: report(INFO, ("Protect table already grants 'admin'" + " to user {}. Not changing").format(p4gf_const.P4GF_USER)) return False l = protect_lines if p4gf_version.p4d_version_supports_admin_user(p4): perm = 'admin' else: perm = 'super' l.append('{perm} user {user} * //...'.format(perm=perm, user=p4gf_const.P4GF_USER)) p4gf_util.set_spec(p4, 'protect', values={KEY_PROTECTIONS: l}) report( INFO, "Protect table modified. {} granted admin permission.".format( p4gf_const.P4GF_USER)) return True
def ensure_protect(protect_lines): """Require that 'p4 protect' table includes grant of admin to git-fusion-user. """ with p4.at_exception_level(p4.RAISE_NONE): r = p4.run('protects', '-m', '-u', p4gf_const.P4GF_USER) if p4gf_p4msg.find_msgid(p4, p4gf_p4msgid.MsgDm_ProtectsEmpty): report(INFO, "Protect table empty. Setting....") report(DEBUG, 'p4 protects -mu git-fusion-user\n{}'.format(r)) perm = p4gf_util.first_value_for_key(r, KEY_PERM_MAX) if perm and perm in ['admin', 'super']: report(INFO, ( "Protect table already grants 'admin'" + " to user {}. Not changing").format(p4gf_const.P4GF_USER)) return False l = protect_lines if p4gf_version.p4d_version_supports_admin_user(p4): perm = 'admin' else: perm = 'super' l.append('{perm} user {user} * //...'.format(perm=perm, user=p4gf_const.P4GF_USER)) p4gf_util.set_spec(p4, 'protect', values={KEY_PROTECTIONS : l}) report(INFO, "Protect table modified. {} granted admin permission." .format(p4gf_const.P4GF_USER)) return True
def create(self): """Create the group with ourself as the owner. Don't bother setting all the fields: Owner is all we need for future 'p4 group -a' modification requests to succeed. """ spec_id = self._spec[KEY_GROUP] spec = self._fetch_spec(SPEC_TYPE_GROUP, spec_id) spec[KEY_OWNERS] = self._spec[KEY_OWNERS] self._p4.input = self._spec if p4gf_version.p4d_version_supports_admin_user(self._p4): return self._p4.run(SPEC_TYPE_GROUP, "-i", "-A") else: return self._p4.run(SPEC_TYPE_GROUP, "-i")
def create(self): """Create the group with ourself as the owner. Don't bother setting all the fields: Owner is all we need for future 'p4 group -a' modification requests to succeed. """ spec_id = self._spec[KEY_GROUP] spec = self._fetch_spec(SPEC_TYPE_GROUP, spec_id) spec[KEY_OWNERS] = self._spec[KEY_OWNERS] self._p4.input = self._spec if p4gf_version.p4d_version_supports_admin_user(self._p4): return self._p4.run(SPEC_TYPE_GROUP, "-i", "-A") else: return self._p4.run(SPEC_TYPE_GROUP, "-i")
def write(self): """Create before writing. Pass -a to modify existing group. Complete override. """ r = self.create_if() # +++ don't need to write if the only thing that changed was Owner. if not self._other_changed: return r #LOG.debug("GroupWriter.write() spec=\n{}".format(self._spec)) self._p4.input = self._spec if p4gf_version.p4d_version_supports_admin_user(self._p4): r = self._p4.run(self._spec_type, "-i", "-a") else: r = self._p4.run(self._spec_type, "-i") return r
def write(self): """Create before writing. Pass -a to modify existing group. Complete override. """ r = self.create_if() # +++ don't need to write if the only thing that changed was Owner. if not self._other_changed: return r #LOG.debug("GroupWriter.write() spec=\n{}".format(self._spec)) self._p4.input = self._spec if p4gf_version.p4d_version_supports_admin_user(self._p4): r = self._p4.run(self._spec_type, "-i", "-a") else: r = self._p4.run(self._spec_type, "-i") return r
def ensure_protects_configurable(): """Grant 'p4 protects -u' permission to admin users.""" if not p4gf_version.p4d_version_supports_admin_user(p4): return v = p4gf_util.first_value_for_key( p4.run('configure', 'show', CONFIGURABLE_ALLOW_ADMIN), KEY_VALUE) if v == '1': report( INFO, 'Configurable {} already set to 1. Not setting.'.format( CONFIGURABLE_ALLOW_ADMIN)) return False p4.run('configure', 'set', '{}=1'.format(CONFIGURABLE_ALLOW_ADMIN)) report(INFO, 'Configurable {} set to 1.'.format(CONFIGURABLE_ALLOW_ADMIN)) return True
def ensure_protects_configurable(): """Grant 'p4 protects -u' permission to admin users.""" if not p4gf_version.p4d_version_supports_admin_user(p4): return v = p4gf_util.first_value_for_key( p4.run('configure', 'show', CONFIGURABLE_ALLOW_ADMIN), KEY_VALUE) if v == '1': report(INFO, 'Configurable {} already set to 1. Not setting.' .format(CONFIGURABLE_ALLOW_ADMIN)) return False p4.run('configure', 'set', '{}=1'.format(CONFIGURABLE_ALLOW_ADMIN)) report(INFO, 'Configurable {} set to 1.' .format(CONFIGURABLE_ALLOW_ADMIN)) return True