Commit 368d1db7 authored by Ignacio Corderi's avatar Ignacio Corderi
Browse files

Added pin operations

parent d2c3cced
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -4,16 +4,17 @@ This section will document changes to the library since the last release

## Important
- Kinetic Protocol version updated to [3.0.0](https://github.com/Seagate/kinetic-protocol/tree/3.0.0)
- Everything requires requires proto 3.0.0 or higher on the device

## New features
- Added `--version` to cmd line tool
- Added background operations Scan and Optimize (Requires proto 3.0.0)
- Added background operations Scan and Optimize
- Added pin operations

## Behavior changes
- Removed GreenClient (Feature overlap with AsyncClient)
- Removed PipelinedClient (Only used internally by the kineticc)


Changes from 0.7.2 to 0.7.3
===========================

+19 −11
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ class AdminClient(baseclient.BaseClient):
            kwargs['socket_timeout'] = 60.0
        super(AdminClient, self).__init__(*args, **kwargs)


    # TODO(Nacho): this code is duplicated with client... not sure if its worth refactoring
    # it's pretty generic, maybe we can move it to the baseclient or something
    def _process(self, op, *args, **kwargs):
@@ -43,25 +44,32 @@ class AdminClient(baseclient.BaseClient):
        except Exception as e:
            return op.onError(e)


    def getLog(self, *args, **kwargs):
        return self._process(operations.GetLog, *args, **kwargs)

    def setPin(self, new_pin, pin=None):
        return self._process(operations.Setup, pin=pin, setPin=new_pin)
    def setClusterVersion(self, *args, **kwargs):
        return self._process(operations.SetClusterVersion, *args, **kwargs)

    def updateFirmware(self, *args, **kwargs):
        return self._process(operations.UpdateFirmware, *args, **kwargs)

    def unlock(self, *args, **kwargs):
        return self._process(operations.UnlockDevice, *args, **kwargs)

    def instantSecureErase(self, pin=None):
        return self._process(operations.Setup, instantSecureErase=True, pin=pin)
    def lock(self, *args, **kwargs):
        return self._process(operations.LockDevice, *args, **kwargs)

    def setClusterVersion(self, cluster_version, pin=None):
        return self._process(operations.Setup, newClusterVersion=cluster_version, pin=pin)
    def erase(self, *args, **kwargs):
        return self._process(operations.EraseDevice, *args, **kwargs)

    def updateFirmware(self, binary, pin=None):
        return self._process(operations.Setup, firmware=binary, pin=pin)
    def instantSecureErase(self, *args, **kwargs):
        return self._process(operations.SecureEraseDevice, *args, **kwargs)

    def setSecurity(self, acls):
    def setSecurity(self, *args, **kwargs):
        """
            Set the access control lists to lock users out of different permissions.
            Arguments: aclList -> A list of ACL (Access Control List) objects.
        """
        return self._process(operations.Security, acls=acls)
        return self._process(operations.Security, *args, **kwargs)
+15 −12
Original line number Diff line number Diff line
@@ -39,8 +39,10 @@ class BaseAsync(Client):
         # start background workers
        self._initialize()


    def _initialize(self): pass


    def _raise(self, e, onError=None):
        if onError:
            try:
@@ -56,9 +58,11 @@ class BaseAsync(Client):
                LOG.warn("Unhandled exception when handling unhandled exception. " + str(e))
                # just swallow it (the other option is faulting)


    def dispatch(self, fn, *args, **kwargs):
        fn(*args,**kwargs)


    def _fault_client(self, e):
        self.error = e
        self.faulted = True
@@ -70,6 +74,7 @@ class BaseAsync(Client):
                LOG.error("Unhandled exception on callers code when reporting internal error. {0}".format(e2))
        self._pending = {}


    def _async_recv(self):
        if self.faulted:
            raise common.ConnectionFaulted("Connection {0} is faulted. Can't receive message when connection is on a faulted state.".format(self))
@@ -116,6 +121,7 @@ class BaseAsync(Client):

    ###


    def sendAsync(self, command, value, onSuccess, onError):
        if self.faulted: # TODO(Nacho): should we fault through onError on fault or bow up on the callers face?
            self._raise(common.ConnectionFaulted("Can't send message when connection is on a faulted state."), onError)
@@ -142,10 +148,12 @@ class BaseAsync(Client):
        # transmit
        self.network_send(command, value)


    def _process(self, op, *args, **kwargs):
        if not self.isConnected: raise common.NotConnected("Must call connect() before sending operations.")
        return super(BaseAsync, self)._process(op, *args, **kwargs)


    def _processAsync(self, op, onSuccess, onError, *args, **kwargs):
        if not self.isConnected: raise common.NotConnected("Must call connect() before sending operations.")

@@ -162,6 +170,7 @@ class BaseAsync(Client):
        header, value = op.build(*args, **kwargs)
        self.sendAsync(header, value, innerSuccess, innerError)


    def putAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.Put, onSuccess, onError, *args, **kwargs)

@@ -169,38 +178,32 @@ class BaseAsync(Client):
        self._processAsync(operations.Get, onSuccess, onError, *args, **kwargs)

    def getMetadataAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetMetadata, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.GetMetadata, onSuccess, onError, *args, **kwargs)

    def deleteAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.Delete, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.Delete, onSuccess, onError, *args, **kwargs)

    def getNextAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetNext, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.GetNext, onSuccess, onError, *args, **kwargs)

    def getPreviousAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetPrevious, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.GetPrevious, onSuccess, onError, *args, **kwargs)

    def getKeyRangeAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetKeyRange, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.GetKeyRange, onSuccess, onError, *args, **kwargs)

    def getVersionAsync(self, onSuccess, onError, *args, **kwargs):
        return self._processAsync(operations.GetVersion, onSuccess, onError, *args, **kwargs)
        self._processAsync(operations.GetVersion, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('2.0.3')
    def flushAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.Flush, onSuccess, onError, *args, **kwargs)

    def noopAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.Noop, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaScanAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.MediaScan, onSuccess, onError, *args, **kwargs)

    # @RequiresProtocol('3.0.0')
    def mediaOptimizeAsync(self, onSuccess, onError, *args, **kwargs):
        self._processAsync(operations.MediaOptimize, onSuccess, onError, *args, **kwargs)


+11 −6
Original line number Diff line number Diff line
@@ -67,10 +67,9 @@ class BaseClient(object):
                 chunk_size=common.DEFAULT_CHUNK_SIZE,
                 connect_timeout=common.DEFAULT_CONNECT_TIMEOUT,
                 socket_timeout=common.DEFAULT_SOCKET_TIMEOUT,
                 socket_address=None,
                 socket_port=0,
                 socket_address=None, socket_port=0,
                 defer_read=False,
                 use_ssl=False):
                 use_ssl=False, pin=None):
        self.hostname = hostname
        self.port = port
        self.identity = identity
@@ -88,6 +87,7 @@ class BaseClient(object):
        self.defer_read = defer_read
        self.wait_on_read = None
        self.use_ssl = use_ssl
        self.pin = pin

    @property
    def socket(self):
@@ -169,6 +169,7 @@ class BaseClient(object):
        if LOG.isEnabledFor(logging.DEBUG):
            LOG.debug("Header updated. Connection=%s, Sequence=%s" % (header.connectionID, header.sequence))


    def _send_delimited_v2(self, header, value):
        # build message (without value) to write
        out = header.SerializeToString()
@@ -209,6 +210,10 @@ class BaseClient(object):
        m = messages.Message()
        m.commandBytes = command.SerializeToString()

        if self.pin:
            m.authType = messages.Message.PINAUTH
            m.pinAuth.pin = self.pin
        else: # Hmac
            m.authType = messages.Message.HMACAUTH
            m.hmacAuth.identity = self.identity
            m.hmacAuth.hmac = calculate_hmac(self.secret, command)
+1 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class Client(BaseClient):
    def mediaOptimize(self, *args, **kwargs):
        return self._process(operations.MediaOptimize, *args, **kwargs)


class KineticRangeIter(object):

    def __init__(self, client, startKey, endKey, startKeyInclusive,endKeyInclusive, prefetch):
Loading