Esempio n. 1
0
    def _init_from_body_ack(self, body):
        # N2H
        assert isinstance(body, dict), repr(body)
        _result = self.ack_result = body['result']

        uuid = None
        if _result == 'ok':
            self.ack_username = str(body['username'])  # forcibly de-unicode
            try:
                uuid = UUID(body['uuid'])
            except:
                logger.error('In LoginMessage, received invalid UUID: %r',
                             body)

        self.ack_host_uuid = uuid
        self.ack_groups = \
            [UserGroup.from_json(gr)()
                 for gr in body['ack_groups']] if 'ack_groups' in body \
                                               else []

        try:
            self.ack_ssl_cert = \
                crypto.load_certificate(crypto.FILETYPE_PEM,
                                        body['SSL certificate'])
        except:
            self.ack_ssl_cert = None
Esempio n. 2
0
def add_group(arguments):
    node_map = proceed_with_node()

    if node_map is not None:
        if len(arguments) < 1:
            cli_error('You must pass at least 1 argument to this command: '
                          'the name of the group.')
        else:
            groupname_str = arguments.popleft()

            # Parse group UUID (optional)
            try:
                group_uuid = UUID(arguments[0])
                # Parsed successfully
                arguments.popleft()
            except (IndexError, ValueError):
                group_uuid = gen_uuid()

            user_group = UserGroup(uuid=UserGroupUUID.safe_cast_uuid(
                                            group_uuid),
                                   name=str(groupname_str),
                                   private=False,
                                   enc_key=gen_rand_key())
            NodeApp.add_ugroup(user_group)
            print(u'Added group "{}" with UUID {}'
                      .format(groupname_str, group_uuid))
Esempio n. 3
0
        def add_user_with_group(cls, username, group_uuid, digest, is_trusted,
                                dw):
            """Add the user (and the appropriate group to the data stores).

            @param group_uuid: UUID of the user group.
            @type group_uuid: UserGroupUUID

            @param is_trusted: whether the user stands for the Trusted Hosts.
            @type is_trusted: bool

            @param dw: data wrapper
            @type dw: DataWrapper
            """
            enc_key = gen_rand_key()

            group = UserGroup(uuid=group_uuid,
                              name=username,
                              private=True,
                              enc_key=enc_key)
            TrustedQueries.TrustedUsers.add_user_with_group(
                username, group, digest, dw.rdbw)
            FDBQueries.Users.add_user(username=username,
                                      digest=digest,
                                      is_trusted=is_trusted,
                                      fdbw=dw.fdbw)
Esempio n. 4
0
File: login.py Progetto: shvar/redfs
    def _init_from_body_ack(self, body):
        # N2H
        assert isinstance(body, dict), repr(body)
        _result = self.ack_result = body["result"]

        uuid = None
        if _result == "ok":
            self.ack_username = str(body["username"])  # forcibly de-unicode
            try:
                uuid = UUID(body["uuid"])
            except:
                logger.error("In LoginMessage, received invalid UUID: %r", body)

        self.ack_host_uuid = uuid
        self.ack_groups = [UserGroup.from_json(gr)() for gr in body["ack_groups"]] if "ack_groups" in body else []

        try:
            self.ack_ssl_cert = crypto.load_certificate(crypto.FILETYPE_PEM, body["SSL certificate"])
        except:
            self.ack_ssl_cert = None
Esempio n. 5
0
    def _init_from_body(self, body):
        # N2H
        assert 'files' in body, \
               repr(body)

        if 'dataset' in body:
            self.dataset = \
                AbstractBasicDatasetInfo.from_json(body['dataset'])()

        if 'ugroup' in body:
            self.ugroup = UserGroup.from_json(body['ugroup'])()

        self.sync = bool(int(body['sync']))

        _files_pre = {LocalPhysicalFileState.from_json(
                              json.loads(file_key))(): blocks
                          for file_key, blocks in body['files'].iteritems()}
        self.files = {file: [Chunk.Block.from_json(ser_block, file)()
                                  for ser_block in blocks]
                          for file, blocks in _files_pre.iteritems()}

        if 'want_restore' in body:
            self.wr_uuid = TransactionUUID(body['want_restore'])