def get_access_token(self, username=None, password=None, quiet=False): """ Generate an access token """ # Check that a client for this session has been created by checking api # key and secret. if (self.api_key == "" or self.api_key is None or self.api_secret == "" or self.api_secret is None): print("Please create a client first. See \"clients_create(client_name, description)\"\n") return # Set tenant url. tenant_url = self.api_server # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) # Create access token. token_data = token_create(self.api_key, self.api_secret, tenant_url, username=self.username, password=password, quiet=quiet) # Update client. self.token = token_data.get("access_token") self.refresh_token = token_data.get("refresh_token") self.expires_in = token_data.get("expires_in") self.created_at = token_data.get("created_at") self.expires_at = token_data.get("expires_at")
def clients_create(self, client_name, description, username=None, password=None, quiet=False): """ Create an Oauth client Save the api key and secret upon a successfull request to Agave. PARAMETERS ---------- client_name: string Name of the oauth client to be created. description: string Description of the client to be created. """ # Set tenant url. tenant_url = self.api_server # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) self.api_key, self.api_secret = clients_create( client_name, description, tenant_url, username=self.username, password=password, quiet=quiet) # Save client name upon successful return of function. self.client_name = client_name
def clients_subscribe(self, api_name, api_version, api_provider, client_name=None, username=None, password=None, quiet=False): """ Subscribe the oauth client to an api """ # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) # If client_name is not set, then delete the current client, if it # exists. if client_name is None: client_name = self.client_name # Subscribe client. clients_subscribe(client_name, self.api_server, api_name, api_version, api_provider, username=self.username, password=password, quiet=quiet)
def clients_delete(self, client_name=None, username=None, password=None, quiet=False): """ Delete an Oauth client If no client_name is passed then we will try to delete the oauth client stored in the current session. """ # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) # If client_name is not set, then delete the current client, if it # exists. if client_name is None: client_name = self.client_name # Delete client. clients_delete(self.api_server, client_name, self.username, password=password, quiet=quiet) # If we deleted the current client, then zero out its secret and key. if self.client_name == client_name: self.api_key, self.api_secret = "", ""
def clients_list(self, username=None, password=None, quiet=False): """ List all oauth clients """ # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) # Set tenant url. tenant_url = self.api_server clients_list(tenant_url, username=self.username, password=password, quiet=quiet)
def clients_subscriptions(self, client_name=None, username=None, password=None, quiet=False): """ List oauth client subscriptions """ # Set username. if self.username == "" or self.username is None: self.username = prompt_username(username) # If client_name is not set, then delete the current client, if it # exists. if client_name is None: client_name = self.client_name # List subscriptions. clients_subscriptions(client_name, self.api_server, username=self.username, password=password, quiet=quiet)