Skip to content

Instantly share code, notes, and snippets.

@fracai
Created February 2, 2020 05:07
Show Gist options
  • Save fracai/794b0c8b440bccfeab7dc9b40e36f164 to your computer and use it in GitHub Desktop.
Save fracai/794b0c8b440bccfeab7dc9b40e36f164 to your computer and use it in GitHub Desktop.
Clean stale FreeNAS certificates
#!/usr/bin/env python
import requests, json, time, sys
password='password'
host='hostname'
login = ('root', password)
headers = {'Content-Type': "application/json"}
url = 'http://'+host+'/api/v1.0/system/certificate/'
result = requests.get(
url,
headers=headers,
auth=login
)
if not result.json():
sys.exit()
for record in result.json()[:-1]:
print ('deleting id: %(id)2i, name: %(cert_common)s, valid until: %(cert_until)s' % record)
result = requests.delete(
url + str(record['id']) + '/',
headers=headers,
auth=login
)
if result.status_code != 204:
print ('error: ' + str(result.status_code))
break
print ('keeping id: %(id)2i, name: %(cert_common)s, valid until: %(cert_until)s' % result.json()[-1])
#for cert in ids_to_delete:
# print (str(cert['id']) + ': ' + cert['cert_until'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment