Package: ultra-auth
ultra_authA compact Python client for managing a connection with the UltraDNS API. For the "official," and much more ambitious project, gohere.FeaturesSupport for authenticating with username and password, or directly with a bearer token.Automatic token refreshing when the token expires.Built-in handling of various content types.InstallationYou can easily installultra_authusingpip:pipinstallultra_authOnce installed, you can use the ultra_auth module in your Python scripts:fromultra_authimportUltraApiclient=UltraApi(args)UsageAuthenticating using Username and Passwordclient=UltraApi(your_username,your_password)Authenticating using Bearer Tokenclient=UltraApi(your_bearer_token,use_token=True)Authenticating using Bearer Token and Refresh Tokenclient=UltraApi(your_bearer_token,your_refresh_token,True)Making API Calls# Make a GET requestresponse=client.get("/ultra/api/endpoint")# Make a POST requestresponse=client.post("/ultra/api/endpoint",payload={"key":"value"})# ... similarly for PUT, PATCH, DELETEResponse HandlingThe client can return data in the form of dictionaries, strings, or bytes depending on the response content type.For example:The zone export endpoint, when requesting more than one zone, will return a zip fileThe zone export endpoint, when requesting one zone, returns a plain text responseMost endpoints return JSONDebuggingDebug ModeWhen debug mode is enabled the client will print some verbose information about the request to stdout.client=UltraApi(your_username,your_password,debug=True)# Toggle it on and offclient.toggle_debug()Pretty Print ModeWhen pretty print mode is enabled the client will print the JSON response in a more human-readable format. This returns
a string instead of a dictionary, so be aware of that.client=UltraApi(your_username,your_password,pprint=True)# Toggle it on and offclient.toggle_pprint()User-AgentThe client will send a unique User-Agent header with each request. By default, the User-Agent header will be "python-ultra-auth/vX.X.X (+repository_url)" where X.X.X is the version of the client.You can override this by passing a custom User-Agent header to the client.client=UltraApi(your_username,your_password,user_agent="my-custom-user-agent")# This can be modified using the set_user_agent method. You return to the default, simply set it to None.client.set_user_agent(None)client.set_user_agent("my-new-custom-user-agent")Managing TasksSome endpoints return tasks, indicating that the operation might take some time to complete. For these scenarios, there's aTaskHandlerhelper class.InitializationCreate an instance ofUltraApi.importultra_authclient=ultra_auth.UltraApi(your_username,your_password)Pass this to theTaskHandler.task=ultra_auth.TaskHandler(client)Getting the Task IDWhen an endpoint returns a task, the response will contain atask_id.response=client.post('/v3/zones/export',{'zoneNames':['your_domain_name.com']})task_id=response['task_id']Checking Task StatusYou can check the current status of a task usingcheckor implicitly wait for it to be completed usingwait.print(task.check(task_id))print(task.wait(task_id,5))The secondwaitarg is the number of seconds to pause between polling. The default is 10.Task ResultsOnce a task is completed, you can retrieve the result using theresultmethod:print(task.result(task_id))NoteUsing a bearer token without a refresh token means the client state will expire in approximately 1 hour (assuming the token was just generated). The client won't stop you from doing this, but be warned.ContributeContributions are always welcome! Please open a pull request with your changes, or open an issue if you encounter any problems or have suggestions.LicenseThis project is licensed under the MIT License - see theLICENSEfile for details