function getClientForKey(key, log) {
    // if extraction only return the id, it is not a scality arnPrefix
    const detail = extractDetailFromArn(key);
    let clientIdentifier;
    if (detail.type) {
        // if type was extracted, it is a scality arnPrefix, it needs validation
        // might throw if arn malformed or backend not available
        // for any request (PUT or GET)
        const error = validateKeyDetail(detail, availableBackends);
        if (error) {
            log.error('KMS key arn is invalid', { key, detail, availableBackends });
            return { error };
        }
        clientIdentifier = `${detail.type}:${detail.protocol}:${detail.provider}`;
    } else if (config.sseMigration) {
        // if not a scality arnPrefix but migration from previous KMS
        clientIdentifier = previousIdentifier;
    } else {
        // if not a scality arnPrefix and no migration
        clientIdentifier = currentIdentifier;
    }

    const instance = clientInstances[clientIdentifier];

    if (instance) {
        // was already instantiated
        // return the extracted key id to avoid further processing of potential arn
        // return clientIdentifier to allow usage restriction
        return { ...instance, clientIdentifier, key: detail.id };
    }

    // Only pre instantiated previous KMS from sseMigration is supported now
    // Here we could instantiate other provider on the fly to manage multi providers
    log.error('KMS key doesn\'t match any KMS instance', { key, detail, availableBackends });
    return { error: new errors.InvalidArgument
        // eslint-disable-next-line new-cap
        .customizeDescription(`KMS unknown provider for key ${key}`),
    };
}
Extract backend provider from key, validate arn for errors.
@param {string} key KeyId or KeyArn
@param {object} log logger
@returns {object} error or client with extracted KeyId