def read_configs()

in 5-app-infra/3-artifact-publish/docker/cdmc/tag_engine_api/TagEngineStoreHandler.py [0:0]


    def read_configs(self, service_account, config_type='ALL', template_id=None, template_project=None, template_region=None):
        
        print('* enter read_configs *')
        
        colls = []
        pending_running_configs = []
        active_configs = []
        combined_configs = []
        
        if template_id and template_project and template_region:
            template_exists, template_uuid = self.read_tag_template(template_id, template_project, template_region)
        else:
            template_exists = False
            template_uuid = None
        
        if config_type == 'ALL':
            colls = self.get_config_collections()
        else:
            colls.append(self.lookup_config_collection(config_type))
        
        #print('colls: ', colls)
        
        for coll_name in colls:
            
            # skip the export configs because they are tied to a project, not template
            if coll_name == 'export_configs':
                continue
            
            config_ref = self.db.collection(coll_name)
            
            if coll_name == 'restore_configs':
            
                if template_exists == True:
                    config_ref = config_ref.where(filter=FieldFilter('target_template_uuid', '==', template_uuid))
            else:
                
                if template_exists == True:
                    config_ref = config_ref.where(filter=FieldFilter('template_uuid', '==', template_uuid))
                
            docs = config_ref.where(filter=FieldFilter('config_status', '!=', 'INACTIVE'))
            docs = docs.where(filter=FieldFilter('service_account', '==', service_account)).stream()
                                    
            for doc in docs:
                config = doc.to_dict()
                print('read config from FS:', config)
                
                if 'job_status' not in config or 'PENDING' in config['job_status'] or 'RUNNING' in config['job_status']:
                    pending_running_configs.append(config)
                else:
                    active_configs.append(config)
                        
        
        
        combined_configs = pending_running_configs + active_configs
        
        return combined_configs