blog-templates/consumption.yaml [192:252]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
              principal_json = {}
              table_json = {}
              tableWithColumns_json = {}
              perm_json = {}
              if 'Principal' in event:
                  principal_json['DataLakePrincipalIdentifier'] = event['Principal']
              else:
                  raise LFAttributeError

              if 'Table' in event:
                  if 'DatabaseName' not in event['Table']:
                      raise LFAttributeError
                  table_json['DatabaseName'] = event['Table']['DatabaseName']
                  # Need to create a env variable Foundations Account ID
                  table_json['CatalogId'] = f_acc_id
                  response = grant_db_describe(principal_json,
                                                      table_json['DatabaseName'])
                  if 'foundation_' in table_json['DatabaseName']:
                      table_json['DatabaseName']=table_json['DatabaseName'].split('foundation_')[1]
                  if 'Name' in event['Table']:
                      table_json['Name'] = event['Table']['Name']
                  elif 'TableWildcard' in event['Table']:
                      table_json['TableWildcard'] = event['Table']['TableWildcard']
                  else:
                      raise LFAttributeError
              elif 'TableWithColumns' in event:
                  if 'DatabaseName' not in event['TableWithColumns']:
                      raise LFAttributeError
                  tableWithColumns_json['DatabaseName'] = event['TableWithColumns']['DatabaseName']
                  tableWithColumns_json['CatalogId'] = f_acc_id
                  response = grant_db_describe(principal_json,
                                                      tableWithColumns_json['DatabaseName'])
                  if 'foundation_' in tableWithColumns_json['DatabaseName']:
                      tableWithColumns_json['DatabaseName']=tableWithColumns_json['DatabaseName'].split('foundation_')[1]
                  if 'Name' not in event['TableWithColumns']:
                      raise LFAttributeError
                  tableWithColumns_json['Name'] = event['TableWithColumns']['Name']
                  if 'ColumnNames' in event['TableWithColumns']:
                      tableWithColumns_json['ColumnNames'] = event['TableWithColumns']['ColumnNames']
                  elif 'ColumnWildcard' in event['TableWithColumns']:
                      tableWithColumns_json['ColumnWildcard'] = event['TableWithColumns']['ColumnWildcard']
                  else:
                      raise LFAttributeError
              else:
                  raise LFAttributeError

              if 'Permissions' in event:
                  perm_lit = ["SELECT"]
                  if list(set(perm_lit) - set(event['Permissions'])):
                      logger.info('Found permissions other than SELECT and DESCRIBE ignoring them')
                      perm_json['Permissions'] = perm_lit
                  else:
                      perm_json['Permissions'] = event['Permissions']
              else:
                  LFAttributeError


              return principal_json, table_json, tableWithColumns_json, perm_json


          def grant_lf_permissions(principal_json, table_json, tableWithColumns_json, perm_json):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



src/lakeformation_permissions/consumption/lambda_function.py [147:207]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    principal_json = {}
    table_json = {}
    tableWithColumns_json = {}
    perm_json = {}
    if 'Principal' in event:
        principal_json['DataLakePrincipalIdentifier'] = event['Principal']
    else:
        raise LFAttributeError
    
    if 'Table' in event:
        if 'DatabaseName' not in event['Table']:
            raise LFAttributeError
        table_json['DatabaseName'] = event['Table']['DatabaseName']
        # Need to create a env variable Foundations Account ID
        table_json['CatalogId'] = f_acc_id
        response = grant_db_describe(principal_json, 
                                            table_json['DatabaseName'])
        if 'foundation_' in table_json['DatabaseName']:
            table_json['DatabaseName']=table_json['DatabaseName'].split('foundation_')[1]
        if 'Name' in event['Table']:
            table_json['Name'] = event['Table']['Name']
        elif 'TableWildcard' in event['Table']:
            table_json['TableWildcard'] = event['Table']['TableWildcard']
        else:
            raise LFAttributeError
    elif 'TableWithColumns' in event:
        if 'DatabaseName' not in event['TableWithColumns']:
            raise LFAttributeError
        tableWithColumns_json['DatabaseName'] = event['TableWithColumns']['DatabaseName']
        tableWithColumns_json['CatalogId'] = f_acc_id
        response = grant_db_describe(principal_json, 
                                            tableWithColumns_json['DatabaseName'])
        if 'foundation_' in tableWithColumns_json['DatabaseName']:
            tableWithColumns_json['DatabaseName']=tableWithColumns_json['DatabaseName'].split('foundation_')[1]
        if 'Name' not in event['TableWithColumns']:
            raise LFAttributeError
        tableWithColumns_json['Name'] = event['TableWithColumns']['Name']
        if 'ColumnNames' in event['TableWithColumns']:
            tableWithColumns_json['ColumnNames'] = event['TableWithColumns']['ColumnNames']
        elif 'ColumnWildcard' in event['TableWithColumns']:
            tableWithColumns_json['ColumnWildcard'] = event['TableWithColumns']['ColumnWildcard']
        else:
            raise LFAttributeError
    else:
        raise LFAttributeError
    
    if 'Permissions' in event:
        perm_lit = ["SELECT"]
        if list(set(perm_lit) - set(event['Permissions'])):
            logger.info('Found permissions other than SELECT and DESCRIBE ignoring them')
            perm_json['Permissions'] = perm_lit
        else:
            perm_json['Permissions'] = event['Permissions']
    else:
        LFAttributeError
    
    
    return principal_json, table_json, tableWithColumns_json, perm_json


def grant_lf_permissions(principal_json, table_json, tableWithColumns_json, perm_json):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



