Replace an existing key
172471
def _replace_auth_key(
        user,
        key,
        enc='ssh-rsa',
        comment='',
        options=None,
        config='.ssh/authorized_keys'):
    '''
    
    '''

    auth_line = _format_auth_line(key, enc, comment, options or [])

    lines = []
    full = _get_config_file(user, config)

    try:
        # open the file for both reading AND writing
        with salt.utils.files.fopen(full, 'r') as _fh:
            for line in _fh:
                # We don't need any whitespace-only containing lines or arbitrary doubled newlines
                line = salt.utils.stringutils.to_unicode(line.strip())
                if line == '':
                    continue
                line += '\n'

                if line.startswith('#'):
                    # Commented Line
                    lines.append(line)
                    continue
                comps = re.findall(r'((.*)\s)?(ssh-[a-z0-9-]+|ecdsa-[a-z0-9-]+)\s([a-zA-Z0-9+/]+={0,2})(\s(.*))?', line)
                if comps and len(comps[0]) > 3 and comps[0][3] == key:
                    # Found our key, replace it
                    lines.append(auth_line)
                else:
                    lines.append(line)
            _fh.close()
            # Re-open the file writable after properly closing it
            with salt.utils.files.fopen(full, 'wb') as _fh:
                # Write out any changes
                _fh.writelines(salt.utils.data.encode(lines))
    except (IOError, OSError) as exc:
        raise CommandExecutionError(
            'Problem reading or writing to key file: {0}'.format(exc)
        )
759942
def config_amend_key_(self,key,value):
        
        cfg_i = self._cfg
        keys = key.split('.')
        last_key = keys.pop()
        trail = []
        for e in keys:
            cfg_i.setdefault(e,{})
            cfg_i = cfg_i[e]
            trail.append(e)
            if not isinstance(cfg_i,dict):
                raise Exception('.'.join(trail) + ' has conflicting dict/scalar types!')
        cfg_i.setdefault(last_key,value)
1028447
def _construct_new_key(name, units=None):
    """"""
    to_replace = ["/", "\\", "*", "^", "#", " ", "\n", "\t", ",", ".", ")", "(", "'", "`", "-"]
    to_remove = ["$", "{", "}"]

    cat = name
    if units:
        cat = "_".join([name, units])
    for c in to_replace:
       cat = cat.replace(c, "_")
    for c in to_remove:
       cat = cat.replace(c, "")

    cat = re.sub('_+','_', cat)

    return cat
393319
public void restoreKey(String key) {
		if (!key.equalsIgnoreCase("test_mode_opened")) {
			String originalKey = key.substring(keyTestMode.length());
			Object value = get(key);
			put(originalKey, value);
			clear(key);
		}
	}
1269289
function (key) {
                    this._initializeKeys();
                    var args = copyargs(arguments);
                    args[0] = this._keys.indexOf(key);
                    return this.splice.apply(this, args);
                }
688610
public V replace(K key, V value) {
        V curValue;
        if (((curValue = get(key)) != null) || containsKey(key)) {
            curValue = put(key, value);
        }
        return curValue;
    }
1039207
public function replaceKey($data, $replace_key, $key = "--key--")
    {
        foreach ($data as $elem_key => $elem) {
            if (is_array($elem)) {
                $data[$elem_key] = $this->replaceKey($elem, $replace_key);
            } else {
                if ($data[$elem_key] == $key) {
                    $data[$elem_key] = $replace_key;
                }
            }
        }
        return $data;
    }
848078
public boolean replace(K key, V oldValue, V newValue) {
        Object curValue = get(key);
        if (!Objects.equals(curValue, oldValue) || (curValue == null && !containsKey(key))) {
            return false;
        }
        put(key, newValue);
        return true;
    }
994071
function replaceKeyDeep(obj, keyMap) {
  return Object.keys(obj).reduce((memo, key)=> {

    // determine which key we are going to use
    let targetKey = keyMap[key] ? keyMap[key] : key;

    // assign the new value
    memo[targetKey] = obj[key];

    // recurse if an array
    if (Array.isArray(memo[targetKey])) {
      memo[targetKey].forEach((val, idx) => {
        if (Object.prototype.toString.call(val) === '[object Object]') {
          memo[targetKey][idx] = replaceKeyDeep(val, keyMap);
        }
      });
    } else if (Object.prototype.toString.call(memo[targetKey]) === '[object Object]') {
      // recurse if Object
      memo[targetKey] = replaceKeyDeep(memo[targetKey], keyMap);
    }

    // return the modified object
    return memo;
  }, {});
}
794874
def rename_key(d: Dict[str, Any], old: str, new: str) -> None:
    
    d[new] = d.pop(old)
1262492
function rename(key, newkey, req) {
  var val = this.getKey(key);
  this.delKey(key);
  this.setKey(newkey, val);
  return OK;
}
99739
def replace(key, value, ttl=nil, options=nil)
      perform(:replace, key, value, ttl_or_default(ttl), 0, options)
    end
654583
function simpleKeys (original) {
        return Object.keys(original).reduce(function (obj, key) {
          obj[key] = typeof original[key] === 'object' ? '{ ... }' : original[key];
          return obj;
        }, {});
      }
735283
def replace_cas(key, value, cas, ttl=nil, options=nil)
      ttl ||= @options[:expires_in].to_i
      perform(:replace, key, value, ttl, cas, options)
    end
325358
function updateKeys(obj, _) {
    var newObj = null;
    if (_.isArray(obj)) {
        newObj = [];
    } else if (_.isObject(obj)) {
        newObj = {};
    } else {
        return obj;
    }
    _.forEach(obj, function(value, key) {
        if (key.replace) {
            var newKey = key.replace(/\$|\./g, '_');
            newObj[newKey] = updateKeys(value, _);
        } else {
            newObj[key] = updateKeys(value, _);
        }
    });
    return newObj;
}
1243776
def _fix_key(self, key):
        
        if not key.startswith(self.GCONF_DIR):
            return self.GCONF_DIR + key
        else:
            return key
1174002
function replacer(key, value) {
  if (value instanceof Buffer)
    return value.toString('base64');
  // eslint-disable-next-line valid-typeof
  if (typeof value === 'bigint')
    return value.toString();
  return value;
}