Та "How to use factory?" хуудсын утсгах уу. Баталгаажуулна уу!
We would create simple API keys factory with "test" prefix.
import cx_apikey as apikey
factory = apikey.apikey_factory("test")
We would change size of the API keys to the 512 letters. That function return factory, and we could use it, or store it into variable
factory.set_size(512)
# It also return factory itself
new_factory = apikey.apikey_factory("test").set_size(512)
We could generate new random API key. It would be apikey object. It could be converted to string, to store it in the database.
new_apikey = factory.generate()
# We could convert it to string
as_string = new_apikey.key
also_as_string = str(new_apikey)
Other useable function is importing string to API key object. It checks also that given API key is valid, that mean have good lenght and prefix.
from_string = factory.load(as_string)
# When API key is not valid that would raise apikey_syntax_error
try:
from_string = factory.load(as_string)
except apikey.apikey_syntax_error as error:
print("It is not valid API key")
We could also get API key validator to validating API keys without importing.
validator = factory.get_validator()
Та "How to use factory?" хуудсын утсгах уу. Баталгаажуулна уу!