visch
02/09/2022, 6:23 PMvisch
02/09/2022, 6:24 PMvisch
02/09/2022, 6:25 PM# Check for plugin.  If exists, read it from keyring and set values.
		self._plugin = plugin
		if self._plugin:
			import keyring
			# Set default blank values for creds
			keyring_creds = {
				"client_id": None,
				"client_secret": None,
				"access_token": None
			}
			# Try to update the blank creds with values from keyring
			try:
				keyring_creds.update( json.loads( keyring.get_password( self._base_url, self._plugin) ) )
			except:
				pass
			# Prompt for client_id or client_secret if not defined
			if not keyring_creds['client_id'] or not keyring_creds['client_secret']:
				import getpass
				# Prompt for client_id if not defined
				while not keyring_creds['client_id']:
					keyring_creds['client_id'] = getpass.getpass( f"No client_id found for plugin {self._plugin} on {self._base_url}.  Please enter: ")
				# Prompt for client_secret if not defined
				while not keyring_creds['client_secret']:
					keyring_creds['client_secret'] = getpass.getpass( f"No client_secret found for plugin {self._plugin} on {self._base_url}.  Please enter: ")
				# Set keyring password value as a stringified JSON object with the client_id and client_secret
				keyring.set_password( self._base_url, self._plugin, json.dumps(keyring_creds) )
			# Set client_id, client_secret, and access_token
			self._client_id = keyring_creds['client_id']
			self._client_secret = keyring_creds['client_secret']
			self._access_token = keyring_creds['access_token']
if self._plugin:
			import keyring
			keyring.set_password( self._base_url, self._plugin, json.dumps({
				"client_id": self._client_id,
				"client_secret": self._client_secret,
				"access_token": self._access_token
			}))visch
02/09/2022, 6:27 PMaaronsteers
02/09/2022, 6:29 PMaaronsteers
02/09/2022, 6:30 PMvisch
02/09/2022, 6:30 PMvisch
02/09/2022, 6:31 PMaaronsteers
02/09/2022, 6:41 PM