def set_credentials(hostname, username=None, password=None): """Set authentication credentials for a remote URL in the :class:`podpac.settings`. Parameters ---------- hostname : str Hostname for `username` and `password`. username : str, optional Username to store in settings for `hostname`. If no username is provided and the username does not already exist in the settings, the user will be prompted to enter one. password : str, optional Password to store in settings for `hostname` If no password is provided and the password does not already exist in the settings, the user will be prompted to enter one. """ if hostname is None or hostname == "": raise ValueError("`hostname` must be defined") # see whats stored in settings already u_settings = settings.get("username@{}".format(hostname)) p_settings = settings.get("password@{}".format(hostname)) # get username from 1. function input 2. settings 3. python input() u = username or u_settings or input("Username: "******"username@{}".format(hostname)] = u settings["password@{}".format(hostname)] = p _log.debug("Set credentials for hostname {}".format(hostname))
def get_default_cache_ctrl(): """ Get the default CacheCtrl according to the settings. Returns ------- ctrl : CacheCtrl or None Default CachCtrl """ if settings.get("DEFAULT_CACHE") is None: # missing or None return CacheCtrl([]) return make_cache_ctrl(settings["DEFAULT_CACHE"])
def release_n_threads(self, n): """This releases the number of threads specified. Parameters ------------ n : int Number of threads to be released Returns -------- int Number of threads available after releases 'n' threads """ with self._lock: self._n_threads_used = max(0, self._n_threads_used - n) available = max( 0, settings.get("N_THREADS", DEFAULT_N_THREADS) - self._n_threads_used) return available
def password(self): """Returns password stored in settings for accessing `self.hostname`. The password is stored under key `password@<hostname>` Returns ------- str password stored in settings for accessing `self.hostname` Raises ------ ValueError Raises a ValueError if not password is stored in settings for `self.hostname` """ key = "password@{}".format(self.hostname) password = settings.get(key) if not password: raise ValueError( "No password found for hostname {0}. Use `{1}.set_credentials(username='******', password='******') to store credentials for this host" .format(self.hostname, self.__class__.__name__)) return password
def username(self): """Returns username stored in settings for accessing `self.hostname`. The username is stored under key `username@<hostname>` Returns ------- str username stored in settings for accessing `self.hostname` Raises ------ ValueError Raises a ValueError if not username is stored in settings for `self.hostname` """ key = "username@{}".format(self.hostname) username = settings.get(key) if not username: raise ValueError( "No username found for hostname '{0}'. Use `{1}.set_credentials(username='******', password='******') to store credentials for this host" .format(self.hostname, self.__class__.__name__)) return username
def request_n_threads(self, n): """Returns the number of threads allowed for a pool taking into account all other threads application, as specified by podpac.settings["N_THREADS"]. Parameters ----------- n : int Number of threads requested by operation Returns -------- int Number of threads a pool may use. Note, this may be less than or equal to n, and may be 0. """ with self._lock: available = max( 0, settings.get("N_THREADS", DEFAULT_N_THREADS) - self._n_threads_used) claimed = min(available, n) self._n_threads_used += claimed return claimed
def max_size(self): return settings.get(self._limit_setting)