Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dereckmartin/4e2eafdf1e6a146cb2fe35c7a1a7df97 to your computer and use it in GitHub Desktop.
Save dereckmartin/4e2eafdf1e6a146cb2fe35c7a1a7df97 to your computer and use it in GitHub Desktop.
Export Harbor LDAP usergroups to puppet-harbor hieradata
#!/bin/python
import requests
from requests.auth import HTTPBasicAuth
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
'''
Translate Harbor LDAP usergroup data to Puppet Hieradata
for puppet-harbor module [https://github.com/walkamongus/puppet-harbor]
1. Set Harbor host (i.e., https://host.domain.com)
2. Set Harbor username
3. Set Harbor password
4. Set hierakey (i.e., harbor::harbor_member_groups:)
5. Execute
Sample Output:
harbor::harbor_member_groups:
'Sample-Group':
ensure: present
ldap_group_dn: 'cn=sample-group,ou=security groups,dc=sample,dc=com'
group_name: 'Sample-Group'
'''
host = ""
user = ""
password = ""
hierakey = ""
usergroups_endpoint = "/api/usergroups"
usergroups = requests.get(host + usergroups_endpoint, auth=HTTPBasicAuth(user, password), verify=False)
print (hierakey)
for usergroup in usergroups.json():
print (" '{}':".format(usergroup['group_name']))
print (" ensure: present")
print (" ldap_group_dn: '{}'".format(usergroup['ldap_group_dn']))
print (" group_name: '{}'".format(usergroup['group_name']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment