code: def _flatten(self, roles=None, groups=None):
          
          if roles is None:
              roles_in = copy.deepcopy(self.roles_raw)
          else:
              roles_in = roles
          for roleid in roles_in:
              role = roles_in[roleid]
              if groups is not None:
                  role['backends_groups'] = self._merge_groups(
                      [role['backends_groups'], groups],
                      )
              if 'subroles' in role:
                  self._flatten(
                      role['subroles'],
                      role['backends_groups'],
                      )
                  del role['subroles']
  
              self.flatten[roleid] = role
docs: flatten a (semi) nest roles structure