gcs/project.py
def update_key(self, key_id, payload, context):
        """Get an existing HMAC key from the service account."""
        key = self.keys.get(key_id)
        if key is None:
            return testbench.error.notfound("key %s" % key_id, context)
        metadata = key.get("metadata")
        # by constructions our keys always have a `metadata`` field
        assert metadata is not None
        if context is None:
            self._check_etag(metadata, payload.get("etag"), "payload")
            self._check_etag(
                metadata, flask.request.headers.get("if-match-etag"), "header"
            )

        state = payload.get("state")
        if state not in ("ACTIVE", "INACTIVE"):
            return testbench.error.invalid(
                "state `HmacKeys: update` request %s" % key_id, context
            )
        # Unlike production, we never hold on to deleted keys
        assert metadata.get("state") != "DELETED"
        key["generator"] += 1
        metadata["state"] = state
        metadata["etag"] = base64.b64encode(
            bytearray("%d" % key["generator"], "utf-8")
        ).decode("utf-8")
        now = time.gmtime(time.time())
        metadata["updated"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", now)
        return metadata
Get an existing HMAC key from the service account.
Get an existing HMAC key from the service account.
Get an existing HMAC key from the service account .
def update_key(self, key_id, payload, context):
        key = self.keys.get(key_id)
        if key is None:
            return testbench.error.notfound("key %s" % key_id, context)
        metadata = key.get("metadata")
        assert metadata is not None
        if context is None:
            self._check_etag(metadata, payload.get("etag"), "payload")
            self._check_etag(
                metadata, flask.request.headers.get("if-match-etag"), "header"
            )
        state = payload.get("state")
        if state not in ("ACTIVE", "INACTIVE"):
            return testbench.error.invalid(
                "state `HmacKeys: update` request %s" % key_id, context
            )
        assert metadata.get("state") != "DELETED"
        key["generator"] += 1
        metadata["state"] = state
        metadata["etag"] = base64.b64encode(
            bytearray("%d" % key["generator"], "utf-8")
        ).decode("utf-8")
        now = time.gmtime(time.time())
        metadata["updated"] = time.strftime("%Y-%m-%dT%H:%M:%SZ", now)
        return metadata
def update_key ( self , key_id , payload , context ) : key = self . keys . get ( key_id ) if key is None : return testbench . error . notfound ( "key %s" % key_id , context ) metadata = key . get ( "metadata" ) assert metadata is not None if context is None : self . _check_etag ( metadata , payload . get ( "etag" ) , "payload" ) self . _check_etag ( metadata , flask . request . headers . get ( "if-match-etag" ) , "header" ) state = payload . get ( "state" ) if state not in ( "ACTIVE" , "INACTIVE" ) : return testbench . error . invalid ( "state `HmacKeys: update` request %s" % key_id , context ) assert metadata . get ( "state" ) != "DELETED" key [ "generator" ] += 1 metadata [ "state" ] = state metadata [ "etag" ] = base64 . b64encode ( bytearray ( "%d" % key [ "generator" ] , "utf-8" ) ) . decode ( "utf-8" ) now = time . gmtime ( time . time ( ) ) metadata [ "updated" ] = time . strftime ( "%Y-%m-%dT%H:%M:%SZ" , now ) return metadata
Get an existing HMAC key from the service account.
Get an existing HMAC key from the service account .
"""Get an existing HMAC key from the service account.""" # by constructions our keys always have a `metadata`` field # Unlike production, we never hold on to deleted keys
self
key_id
payload
context