I'm trying to create a setup.xml for my app that takes in an API key as an input from the user. I have it working for credentials using the 'admin/passwords' endpoint. I tried using the same endpoint to store an API Key as a password, but it doesn't work because I need a username also, and there isn't one. I wouldn't mind storing something in the name field, but I don't want the user to have to input it. I have two ideas on how to solve this problem, but not sure which are possible...
Idea 1: Use a hidden input in setup.xml to fill the name field with a static value like 'apikey'. But I don't think splunk supports hidden inputs in setup.xml?
Idea 2: Create a custom endpoint. But I need the api key to be stored encrypted, and I'm not sure the best way to handle this with a custom endpoint.
i would suggest that you have the user input the api key the same way as the user inputs the username and password. in the case of the apikey, you can give them a hint to have a username called,
Thanks monzy, do you mean to have a username field above the API key field and tell the user to enter a specific user name? I'm trying to avoid potential problems by having only one field in the setup screen, just for the API key. I think a username field would be confusing.
yeah. just give them an additional field called, apiuser or something. this will make it easier for you to find the associated apikey.
I came up with a way to do this. I added the following to my setup.xml file:
To get the API Key for use in a python script, I use the technique found in this Splunk blog entry and documentation:
The only difference is the line that says:
return c['username'], c['clear_password']
I have replaced with the following:
if c['username'] == 'api_key': return c['clear_password']
Here is how I store my SMTP_PASSWORD
try: #attempt it (exception if not already there) ent=entity.getEntity("storage/passwords","SMTP_PASSWORD", namespace=self.getAppName(), owner='smartwall', sessionKey=cherrypy.session['sessionKey']) ent['password']= .... clear text password here.... ent['clear_password'] = None ent['encr_password'] = None ent['username'] = None entity.setEntity(ent) except Exception as e: #create a new one logger.info("SMTP_PASSWORD does not exist, try creating a new one") ent = entity.Entity("storage/passwords", "SMTP_PASSWORD", namespace=self.getAppName(), owner='smartwall') ent['password'] = ....clear text password here.... ent['name'] = "SMTP_PASSWORD" entity.setEntity(ent)