Return the lock correspoding to `secrethash` or None if the lock is
    unknown.
970135
def get_lock(
        end_state: NettingChannelEndState,
        secrethash: SecretHash,
) -> Optional[HashTimeLockState]:
    
    lock = end_state.secrethashes_to_lockedlocks.get(secrethash)

    if not lock:
        partial_unlock = end_state.secrethashes_to_unlockedlocks.get(secrethash)

        if not partial_unlock:
            partial_unlock = end_state.secrethashes_to_onchain_unlockedlocks.get(secrethash)

        if partial_unlock:
            lock = partial_unlock.lock

    assert isinstance(lock, HashTimeLockState) or lock is None
    return lock
268986
def get(key, profile=None):
    '''
    
    '''
    conn = salt.utils.memcached.get_conn(profile)
    return salt.utils.memcached.get(conn, key)
211371
def get_key(keyfile=None):
    
    keyfile = keyfile or application_path(settings.SECRETKEY.SECRET_FILE)
    with file(keyfile, 'rb') as f:
        return f.read()
137292
async def unlock(self, device):
        
        device = self._find_device(device)
        if not self.is_handleable(device) or not device.is_crypto:
            self._log.warn(_('not unlocking {0}: unhandled device', device))
            return False
        if device.is_unlocked:
            self._log.info(_('not unlocking {0}: already unlocked', device))
            return True
        if not self._prompt:
            self._log.error(_('not unlocking {0}: no password prompt', device))
            return False
        unlocked = await self._unlock_from_cache(device)
        if unlocked:
            return True
        unlocked = await self._unlock_from_keyfile(device)
        if unlocked:
            return True
        options = dict(allow_keyfile=self.udisks.keyfile_support,
                       allow_cache=self._cache is not None,
                       cache_hint=self._cache_hint)
        password = await self._prompt(device, options)
        # password can be: None, str, or udiskie.prompt.PasswordResult
        cache_hint = getattr(password, 'cache_hint', self._cache_hint)
        password = getattr(password, 'password', password)
        if password is None:
            self._log.debug(_('not unlocking {0}: cancelled by user', device))
            return False
        if isinstance(password, bytes):
            self._log.debug(_('unlocking {0} using keyfile', device))
            await device.unlock_keyfile(password)
        else:
            self._log.debug(_('unlocking {0}', device))
            await device.unlock(password)
        self._update_cache(device, password, cache_hint)
        self._log.info(_('unlocked {0}', device))
        return True
410888
def _get_secret_from_vault(
        key, environment=None, stage=None, namespace=None,
        wait_exponential_multiplier=50, wait_exponential_max=5000,
        stop_max_delay=10000):
    """"""
    # Get the encrypted secret from DynamoDB
    table_name = _secrets_table_name(environment=environment, stage=stage)

    if namespace:
        key = "{}:{}".format(namespace, key)

    if table_name is None:
        logger.warning("Can't produce secrets table name: unable to retrieve "
                       "secret '{}'".format(key))
        return

    client = boto3.client('dynamodb')
    logger.info("Retriving key '{}' from table '{}'".format(
        key, table_name))

    @retry(retry_on_exception=_is_critical_exception,
           wait_exponential_multiplier=wait_exponential_multiplier,
           wait_exponential_max=wait_exponential_max,
           stop_max_delay=stop_max_delay)
    def get_item():
        try:
            return client.get_item(
                TableName=table_name,
                Key={'id': {'S': key}}).get('Item', {}).get(
                    'value', {}).get('B')
        except Exception as err:
            if _is_dynamodb_critical_exception(err):
                raise CriticalError(err)
            else:
                raise

    encrypted = get_item()

    if encrypted is None:
        return

    # Decrypt using KMS
    client = boto3.client('kms')
    try:
        value = client.decrypt(CiphertextBlob=encrypted)['Plaintext'].decode()
    except ClientError:
        logger.error("KMS error when trying to decrypt secret")
        traceback.print_exc()
        return

    try:
        value = json.loads(value)
    except (TypeError, ValueError):
        # It's ok, the client should know how to deal with the value
        pass

    return value
858032
public SecretKey getSecretKey(String alias, String password) {
        Key key = getKey(alias, password);
        if (key instanceof PrivateKey) {
            return (SecretKey) key;
        } else {
            throw new IllegalStateException(format("Key with alias '%s' was not a secret key, but was: %s",
                    alias, key.getClass().getSimpleName()));
        }
    }
367633
protected Tuple<SecretKey,byte[]> getSecretKeyFromAbove() {
        return (Tuple<SecretKey,byte[]>)up_prot.up(new Event(Event.GET_SECRET_KEY));
    }
1365629
private int obtainLock(CoordinationLockHandle handle)
  {
      if (tc.isEntryEnabled()) Tr.entry(tc, "obtainLock",handle);

      int result = LOCK_FAILURE;

      try
      {
          final File file = new File(handle._directory,handle._fileName);

          try
          {
              // handle._raf = (RandomAccessFile)AccessController.doPrivileged(
              handle._raf = (RandomAccessFile) Configuration.getAccessController().
                  doPrivileged(
              new java.security.PrivilegedExceptionAction()
              {
                public java.lang.Object run() throws Exception
                {
                    if (tc.isEntryEnabled()) Tr.entry(tc, "run", this);

//                    RandomAccessFile raf = new RandomAccessFile(file, "rw");
                    RandomAccessFile raf = RLSAccessFile.getRLSAccessFile(file); // @255605C

                    if (tc.isEntryEnabled()) Tr.exit(tc, "run");
                    return raf;
                }
              });

              handle._channel = handle._raf.getChannel();
          }
          catch (java.security.PrivilegedActionException exc)
          {
              FFDCFilter.processException(exc, "com.ibm.ws.recoverylog.spi.CoordinationLock.obtainLock", "253", this);
              throw exc;
          }
          catch (Exception exc)
          {
              FFDCFilter.processException(exc, "com.ibm.ws.recoverylog.spi.CoordinationLock.obtainLock", "258", this);
              throw exc;
          }

          boolean halt = false;
          int lockAttempt = 0;

          while (!halt)
          {
              lockAttempt++;

              if (tc.isDebugEnabled()) Tr.debug(tc,"RLSHA: Lock attempt #" + lockAttempt + " on lock file " + handle);

              handle._fileLock = handle._channel.tryLock();

              if (handle._fileLock != null)
              {
                  if (tc.isDebugEnabled()) Tr.debug(tc,"RLSHA: Obtained an exclusive access lock on lock file " + handle);
                  halt = true;
                  result = LOCK_SUCCESS;
              }
              else
              {
                  if (tc.isDebugEnabled()) Tr.debug(tc,"RLSHA: Unable to obtain an exclusive access lock on lock file " + handle);

                  // Should we allow a retry on this lock.
                  if ((LOCKRETRYCOUNT <= 0) || (lockAttempt < LOCKRETRYCOUNT))
                  {
                      if (LOCKRETRYDELAY > 0)
                      {
                          // Output a message if we cannot get a lock - delay the message for the
                          // first pass through...
                          int l = lockAttempt - 2;
                          if ((l/LOCKRETRYTIMES)*LOCKRETRYTIMES == l)
                          {
                            Tr.warning(tc,"CWRLS0026_RECOVERY_LOG_LOCK_RETRY", file);
                          }
                          try
                          {
                              if (tc.isDebugEnabled()) Tr.debug(tc,"Sleeping for " + LOCKRETRYDELAY + " ms before re-try");
                              Thread.sleep(LOCKRETRYDELAY);
                          }
                          catch (Exception exc)
                          {
                              // No FFDC code needed
                          }
                      }

                      // INTERRUPT HANDLER - Check that the interrupt has not been flagged. If it has then abort
                      // and return the interrupted status.
                      if (_interrupted)
                      {
                        halt = true;
                        result = LOCK_INTERRUPT;
                        try                  // @255605A
                        {
                          handle._raf.close();
                        }
                        catch (Exception e)
                        {
                        }
                      }
                  }
                  else
                  {
                      if (tc.isDebugEnabled()) Tr.debug(tc,"Retry count exceeded, aborting lock attempt on lock file " + handle);
                      halt = true;
                      try                  // @255605A
                      {
                        handle._raf.close();
                      }
                      catch (Exception e)
                      {
                      }
                  }
              }
          }
      }
      catch (Exception exc)
      {
          if (tc.isDebugEnabled()) Tr.debug(tc,"An unexpected exception has occured when trying to obtain the exclusive lock " + exc);
          // d251015 - Output the exception to assist with PD when locks fail as we can get some
          // non-obvious errors with NFS, etc.  The callers message will also assist.
          Tr.error(tc,"CWRLS0024_EXC_DURING_RECOVERY", exc);
          if (handle._raf != null) // @255605A
          {
              try
              {
                  handle._raf.close();
              }
              catch (Exception e)
              {
              }
          }
      }

      if (tc.isEntryEnabled()) Tr.exit(tc, "obtainLock",new Integer(result));
      return result;
  }
656919
def _get_secrets(self, secure_data_path, version=None):
        
        if not version:
            version = "CURRENT"
        payload = {'versionId': str(version)}
        secret_resp = get_with_retry(str.join('', [self.cerberus_url, '/v1/secret/', secure_data_path]),
                                   params=payload, headers=self.HEADERS)

        throw_if_bad_response(secret_resp)

        return secret_resp.json()
1280025
def is_lock_pending(
        end_state: NettingChannelEndState,
        secrethash: SecretHash,
) -> bool:
    
    return (
        secrethash in end_state.secrethashes_to_lockedlocks or
        secrethash in end_state.secrethashes_to_unlockedlocks or
        secrethash in end_state.secrethashes_to_onchain_unlockedlocks
    )
1221829
def get_secret(self, handle, contributor):
        
        queryset = self.all()
        if contributor is not None:
            queryset = queryset.filter(contributor=contributor)
        secret = queryset.get(handle=handle)
        return secret.value
748212
def lock_pid(self):
        
        
        if os.path.exists(self.lock_filename):
            return int(open(self.lock_filename).read())
        else:
            return None
407217
def get_common_secret(self, server_public, client_public):
        
        return self.hash(self.pad(client_public), self.pad(server_public))
1350746
def set_lock(key, value=None, expiry_time=60):
    """"""
    from uliweb.utils.common import get_uuid

    redis = get_redis()
    value = value or get_uuid()
    return redis.set(key, value, ex=expiry_time, xx=True)
1035186
def _create_lock_object(self, key):
        '''
        
        '''
        return redis_lock.Lock(self.redis_conn, key,
                               expire=self.settings['REDIS_LOCK_EXPIRATION'],
                               auto_renewal=True)
1027682
def thread_lock(lock):
    """"""
    if hasattr(lock, '_lock'):
        return lock._lock
    elif hasattr(lock, 'acquire'):
        return lock
    else:
        raise TypeError('expecting Lock/RLock')
87646
private String hashKeyForDisk(LoaderRequest request) {
        String key = request.getCacheKey();

        // We don't except to have a lot of threads
        // so it's okay to synchronize access
        synchronized (hasher) {
            return hasher.hash(key);
        }
    }