lib/localKeyUtil.js
function listPrivateKey(keyType, folder, name, noRetry) {
    let privateKeyName;

    // Try with .key suffix first. If unsuccessful, retry without the .key suffix
    if (noRetry) {
        // If present, remove '.key' suffix
        privateKeyName = name.replace(REG_EXPS.KEY_SUFFIX, '');
    } else {
        // Append '.key' suffix, if not present
        privateKeyName = (name.match(REG_EXPS.KEY_SUFFIX)) ? name : `${name}.key`;
    }

    return util.runTmshCommand(`list sys ${keyType} /${folder}/${privateKeyName}`)
        .then((keyData) => {
            // If no result, retry if a retry hasn't occurred yet.
            if (!keyData) {
                if (!noRetry) {
                    return listPrivateKey(keyType, folder, name, true);
                }
                return q();
            }
            return q({ privateKeyName, keyData });
        })
        .catch((err) => {
            // If the object is not found (code: 01020036:3), retry if a retry hasn't occurred yet.
            const notFoundRegex = /01020036:3/;
            if (err.message.match(notFoundRegex) && !noRetry) {
                return listPrivateKey(keyType, folder, name, true);
            }
            return q.reject(err);
        });
}
function listPrivateKey(keyType, folder, name, noRetry) {
    let privateKeyName;

    // Try with .key suffix first. If unsuccessful, retry without the .key suffix
    if (noRetry) {
        // If present, remove '.key' suffix
        privateKeyName = name.replace(REG_EXPS.KEY_SUFFIX, '');
    } else {
        // Append '.key' suffix, if not present
        privateKeyName = (name.match(REG_EXPS.KEY_SUFFIX)) ? name : `${name}.key`;
    }

    return util.runTmshCommand(`list sys ${keyType} /${folder}/${privateKeyName}`)
        .then((keyData) => {
            // If no result, retry if a retry hasn't occurred yet.
            if (!keyData) {
                if (!noRetry) {
                    return listPrivateKey(keyType, folder, name, true);
                }
                return q();
            }
            return q({ privateKeyName, keyData });
        })
        .catch((err) => {
            // If the object is not found (code: 01020036:3), retry if a retry hasn't occurred yet.
            const notFoundRegex = /01020036:3/;
            if (err.message.match(notFoundRegex) && !noRetry) {
                return listPrivateKey(keyType, folder, name, true);
            }
            return q.reject(err);
        });
}
function listPrivateKey ( keyType , folder , name , noRetry ) { let privateKeyName ; // Try with .key suffix first. If unsuccessful, retry without the .key suffix if ( noRetry ) { // If present, remove '.key' suffix privateKeyName = name . replace ( REG_EXPS . KEY_SUFFIX , '' ) ; } else { // Append '.key' suffix, if not present privateKeyName = ( name . match ( REG_EXPS . KEY_SUFFIX ) ) ? name : ` ${ name } ` ; } return util . runTmshCommand ( ` ${ keyType } ${ folder } ${ privateKeyName } ` ) . then ( ( keyData ) => { // If no result, retry if a retry hasn't occurred yet. if ( ! keyData ) { if ( ! noRetry ) { return listPrivateKey ( keyType , folder , name , true ) ; } return q ( ) ; } return q ( { privateKeyName , keyData } ) ; } ) . catch ( ( err ) => { // If the object is not found (code: 01020036:3), retry if a retry hasn't occurred yet. const notFoundRegex = / 01020036:3 / ; if ( err . message . match ( notFoundRegex ) && ! noRetry ) { return listPrivateKey ( keyType , folder , name , true ) ; } return q . reject ( err ) ; } ) ; }
List a private key by folder and name.

Will first search for a private key with a '.key' suffix, and then without a '.key' suffix

@param {String}  keyType      - Key Type to list. Examples: 'file ssl-key', crypto key
@param {String}  folder       - Folder in which to search for the private key.
@param {String}  name         - Name of the private key to search for
@param {Boolean} [noRetry]    - Whether or not to retry command with a different private key name.

@returns {Promise}   A promise which will be resolved with a dictionary containing the name of the
found private key, and the tmsh command response:

{
privateKeyName: <String>,
response: <String>
}
List a private key by folder and name .