code: def gpg_decrypt(cfg, gpg_config=None):
      def decrypt(obj):
          if isinstance(obj, list):
              res_v = []
              for item in obj:
                  res_v.append(decrypt(item))
              return res_v
          elif isinstance(obj, dict):
              if '_gpg' in obj:
                  try:
                      decrypted = gpg.decrypt(obj['_gpg'])
                      if decrypted.ok:
                          obj = n(decrypted.data.decode('utf-8').encode())
                      else:
                          log.error("gpg error unpacking secrets %s", decrypted.stderr)
                  except Exception as err:
                      log.error("error unpacking secrets %s", err)
              else:
                  for k, v in obj.items():
                      obj[k] = decrypt(v)
          else:
              try:
                  if 'BEGIN PGP' in obj:
                      try:
                          decrypted = gpg.decrypt(obj)
                          if decrypted.ok:
                              obj = n(decrypted.data.decode('utf-8').encode())
                          else:
                              log.error("gpg error unpacking secrets %s", decrypted.stderr)
                      except Exception as err:
                          log.error("error unpacking secrets %s", err)
              except TypeError:
                  log.debug('Pass on decryption. Only decrypt strings')
          return obj
      if GPG_IMPORTED:
          if not gpg_config:
              gpg_config = {}
              defaults = {'homedir': '~/.gnupg/'}
              env_fields = {'homedir': 'FIGGYPY_GPG_HOMEDIR',
                            'binary': 'FIGGYPY_GPG_BINARY',
                            'keyring': 'FIGGYPY_GPG_KEYRING'}
              for k, v in env_fields.items():
                  gpg_config[k] = env_or_default(v, defaults[k] if k in defaults else None)
          try:
              gpg = gnupg.GPG(**gpg_config)
          except (OSError, RuntimeError):
              log.exception('Failed to configure gpg. Will be unable to decrypt secrets.')
          return decrypt(cfg)
      return cfg