def retrieveIdentities(self)->None: """ Retrieve the custom mixins. """ aepp.importConfigFile( self.CONFIG['original']['config_file_location']) identity_instance = aep_identity.Identity( self.CONFIG['original']['instance_region']) custom_identities = identity_instance.getIdentities( only_custom=True, save=True)
def duplicateIdentities(self, folder: str = "Identity", save: bool = False, verbose: bool = False)->dict: """ Create the identities in the duplicate instances placed in the config file. Expecting a file identities.json in a folder location. It returns a dictionary of the different duplicate_ids with identities created. Arguments: folder : OPTIONAL : if you have place the identities.json file in another folder. (default "Identity") save : OPTIONAL : if set to True, will generate a json file for your new identities. verbose : OPTIONAL : set to True, it will print comment during the processing. """ identities = self._readIdentities(folder=folder) dict_identities = {} if verbose: print(f"Number of identities to create : {len(identities)}") for duplicate in self.CONFIG['duplicates']: if verbose: print(f"Selecting : {duplicate['duplicate_id']}") aepp.importConfigFile( duplicate['config_file_location']) schema_instance = aep_schema.Schema() tenant_id = schema_instance.getTenantId() identity_instance = aep_identity.Identity( duplicate['instance_region']) list_identities = [] for identity in identities: if verbose: print(f"Creating : {identity['name']}") try: new_identity = identity_instance.createIdentity(name=identity['name'], code=identity['code'], idType=identity['idType'], description=identity.get( 'description', 'Python duplication tool'),) list_identities.append(new_identity) except Exception as e: print( f"Error trying to create Identity : {identity['name']}, idType: {identity['idType']}") print(e) if verbose and save: print( f"creating a file in Identity Folder : {duplicate['duplicate_id']}_identities.json") aepp.saveFile(module='identity', file=list_identities, filename=f"{duplicate['duplicate_id']}_identities.json") dict_identities[duplicate['duplicate_id']] = list_identities return dict_identities
def retrieveSchemas(self)->None: """ Retrieve the schema and the mixin Arguments: """ aepp.importConfigFile( self.CONFIG['original']['config_file_location']) schema_instance = aep_schema.Schema() tenant_id = schema_instance.getTenantId() schemas = schema_instance.getSchemas() obj_schema = {schema['title']: schema['meta:altId'] for schema in schemas if schema['title'].startswith("Adhoc") == False} for schema in obj_schema.values(): schema = schema_instance.getSchema(schema, full=False, save=True) allOf = schema['allOf'] allOf = [element for element in allOf if '$ref' in element.keys()] for element in allOf: if 'classes' in element['$ref']: myClass = schema_instance.getClass( element['$ref'], save=True) if 'mixins' in element['$ref']: myMixin = schema_instance.getMixin( element['$ref'], save=True)
def duplicateSchemas(self, folder: str = "Schema", enableProfile: bool = False, verbose: bool = False)->dict: """ It will duplicate the schemas, mixins, classes from the original instance to the duplicates. Expecting a folder to exist with the different schema retrieved previously. Arguments: folder : OPTIONAL : if you have place the files in another folder. (default "Schema") enableProfile : OPTIONAL : If you want to enable schemas for Profile. verbose : OPTIONAL : set to True, it will print comment during the processing. """ dict_elements = self._readSchemas(folder=folder) list_descriptors = self._readDescriptors() aepp.importConfigFile( self.CONFIG['original']['config_file_location']) schema_instance = aep_schema.Schema() original_tenant = schema_instance.getTenantId() if enableProfile: if verbose: print('retrieving Enabled Schema for Union Profile') list_enabledSchemas = self._retrieveEnabledSchemas( schema_instance, verbose=verbose) if verbose: print(f"{len(dict_elements['classes'])} classes to create") print(f"{len(dict_elements['mixins'])} mixins to create") print(f"{len(dict_elements['schemas'])} schemas to create") duplicates_ids = {} for duplicate in self.CONFIG['duplicates']: if verbose: print(f"Selecting : {duplicate['duplicate_id']}") aepp.importConfigFile( duplicate['config_file_location']) schema_instance = aep_schema.Schema() tenant_id = schema_instance.getTenantId() # starting creating classes classes_translate = self._createClasses( class_elements=dict_elements['classes'], header=schema_instance.header, verbose=verbose) # need to change tenant_id for mixins old_mixins = dict_elements['mixins'] new_mixins = {} for mixin in old_mixins: obj = modules.deepcopy(old_mixins[mixin]) new_def = { "customFields": { "properties": { f"_{tenant_id}": old_mixins[mixin]['definitions']['customFields']['properties'][f"_{original_tenant}"]} } } obj["definitions"] = new_def # translate classes meta_extends = [] for clas in obj["meta:intendedToExtend"]: if clas in classes_translate.keys(): meta_extends.append(classes_translate[clas]) else: meta_extends.append(clas) obj["meta:intendedToExtend"] = meta_extends new_mixins[mixin] = obj mixins_translate = self._createMixins( new_mixins, header=schema_instance.header, verbose=verbose) # need to translate the schemas translat = {**classes_translate, **mixins_translate} old_schemas = dict_elements['schemas'] new_schemas = {} for schema in old_schemas: obj = modules.deepcopy(old_schemas[schema]) allOf = [] for element in obj['allOf']: if "$ref" in element.keys(): if element['$ref'] in translat.keys(): allOf.append( {'$ref': translat[element['$ref']]}) else: allOf.append({'$ref': element['$ref']}) obj['allOf'] = allOf new_schemas[schema] = obj # creating schemas trans_schemas = self._createSchemas( schemas=new_schemas, header=schema_instance.header, verbose=verbose) new_descriptors = [] if verbose: print('translating descriptors') for desc in list_descriptors: new_sourceProperty = desc["xdm:sourceProperty"].replace( f'_{original_tenant}/', f'_{tenant_id}/') new_descriptors.append({ "desc_type": "xdm:descriptorIdentity", "sourceSchema": trans_schemas[desc['xdm:sourceSchema']], "sourceProperty": new_sourceProperty, "namespace": desc["xdm:namespace"], "xdmProperty": "xdm:code", "primary": desc["xdm:isPrimary"] }) res = self._createDescriptors( new_descriptors, schema_instance.header, verbose=verbose) duplicates_ids[duplicate['duplicate_id']] = trans_schemas if enableProfile: if verbose: print( f'Enabling {len(list_enabledSchemas)} Schemas for Union Profile') self._duplicateEnabledSchemas( schema_instance, list_enabledSchemas, trans_schemas, verbose=verbose) return duplicates_ids # return old id and new id for schema
def retrieveDescriptors(self)->None: aepp.importConfigFile( self.CONFIG['original']['config_file_location']) schema_instance = aep_schema.Schema() descriptors = schema_instance.getDescriptors( type_desc="xdm:descriptorIdentity", save=True)