print '+---------------+---------------+---------------+ \n'
print 'Each Top Level Space and user/group access levels \n'

# print spaces_content_metadata_ids, non_personal_descendant_ids
# Put all the dataframes in a list so we can concatenate at the end using pd.concat and get rid of headers

list_of_dataframes = []
inheriting_space_ids = []
admin_only_access_space_ids = []
for (key, value) in spaces_content_metadata_ids.iteritems():

# Pandas stuff - get the dataframe from the Looker API call, only use certain fields, turn those to columns, rename them so they look good, account for empty json responses

	df1 = \
	    pd.DataFrame(json.loads(json.dumps(looker.get_all_content_metadata_access(value,
	                 fields='content_metadata_id,permission_type,user_id,group_id'
	                 ))), columns=['content_metadata_id',
	                 'permission_type', 'user_id', 'group_id'
	                 ]).rename(index=str,
	                           columns={'permission_type': 'access',
	                           'content_metadata_id': 'cmid',
	                           'name': 'space_name'})

	if df1.empty:

	    # if the dataframe is empty, it either means that there's 0 groups/users and only Admins can access or the space has inherited permissions from a parent (likely Shared) space

	    inherited_spaces = looker.get_content_metadata(value)
	    if inherited_spaces['inherits'] == True \
	        and inherited_spaces['parent_id'] == 1:
	        inheriting_space_ids.append(value)
Beispiel #2
0
from lookerapi import LookerApi
from datetime import datetime
from pprint import pprint
### ------- HERE ARE PARAMETERS TO CONFIGURE -------

host = 'localhost'

### ------- OPEN THE CONFIG FILE and INSTANTIATE API -------

f = open('config.yml')
params = yaml.load(f)
f.close()

my_host = params['hosts'][host]['host']
my_secret = params['hosts'][host]['secret']
my_token = params['hosts'][host]['token']

looker = LookerApi(host=my_host,
                 token=my_token,
                 secret = my_secret)

spaces = looker.get_all_spaces(fields='id,is_personal,creator_id,is_personal_descendant,content_metadata_id')

for space in spaces:
    if space['is_personal'] and not space['is_personal_descendant']:
        content_metadata_access = looker.get_all_content_metadata_access(space['content_metadata_id'],fields='id,permission_type,group_id,user_id')
        for access_grant in content_metadata_access:
            if access_grant['user_id'] != space['creator_id']:
                print "deleting access on space " + str(space['id'])
                looker.delete_content_metadata(access_grant['id'])