def __get_structure_info_filtered(self, struct_type, structure_svc):
     structure_info = self.__get_structure_info(struct_type, structure_svc)
     if structure_info is None or utils.is_filtered(
             structure_info.metadata):
         return None
     structure_info.fields = [
         field for field in structure_info.fields
         if not utils.is_filtered(field.metadata)
     ]
     return structure_info
Esempio n. 2
0
    def process_service_urls(self, package_name, service_urls, output_dir,
                             structure_dict, enum_dict, service_dict,
                             service_url_dict, http_error_map,
                             rest_navigation_url, enable_filtering, spec,
                             gen_unique_op_id):

        print('processing package ' + package_name + os.linesep)
        type_dict = {}
        path_list = []
        for service_url in service_urls:
            service_name, service_end_point = service_url_dict.get(
                service_url, None)
            service_info = service_dict.get(service_name, None)
            if service_info is None:
                continue
            if utils.is_filtered(service_info.metadata, enable_filtering):
                continue
            for operation_id, operation_info in service_info.operations.items(
            ):
                method, url = self.api_get_url_and_method(
                    operation_info.metadata)

                # check for query parameters
                if 'params' in operation_info.metadata[method].elements:
                    element_value = operation_info.metadata[method].elements[
                        'params']
                    params = "&".join(element_value.list_value)
                    url = url + '?' + params

                if spec == '2':
                    path = swagg.get_path(operation_info, method, url,
                                          service_name, type_dict,
                                          structure_dict, enum_dict,
                                          operation_id, http_error_map,
                                          enable_filtering)
                if spec == '3':
                    path = openapi.get_path(operation_info, method, url,
                                            service_name, type_dict,
                                            structure_dict, enum_dict,
                                            operation_id, http_error_map,
                                            enable_filtering)

                path_list.append(path)
            continue

        path_dict = self.convert_path_list_to_path_map(path_list)
        self.cleanup(path_dict=path_dict, type_dict=type_dict)

        if spec == '2':
            api_swagg_fpp.process_output(path_dict, type_dict, output_dir,
                                         package_name, gen_unique_op_id)
        if spec == '3':
            api_openapi_fpp.process_output(path_dict, type_dict, output_dir,
                                           package_name, gen_unique_op_id)
 def process_enum_info(self, type_name, enum_info, type_dict):
     enum_type = {'type': 'string', 'description': enum_info.documentation}
     if self.show_unreleased_apis:
         enum_type.setdefault('enum',
                              [value.value for value in enum_info.values])
     else:
         enum_type.setdefault('enum', [
             value.value for value in enum_info.values
             if not utils.is_filtered(value.metadata)
         ])
     type_dict[type_name] = enum_type
 def process_enum_info(
         self,
         type_name,
         enum_info,
         type_dict,
         enable_filtering):
     enum_type = {'type': 'string', 'description': enum_info.documentation}
     enum_type.setdefault(
         'enum', [
             value.value for value in enum_info.values if not utils.is_filtered(
                 value.metadata, enable_filtering)])
     type_dict[type_name] = enum_type
 def get_structure_info(self, struct_type, structure_svc, enable_filtering):
     """
     Given a type, return its structure info, if the type is a structure.
     """
     try:
         structure_info = structure_svc.get(struct_type)
         if structure_info is None:
             utils.eprint(
                 "Could not fetch structure info for " +
                 struct_type)
         elif utils.is_filtered(structure_info.metadata, enable_filtering):
             return None
         else:
             structure_info.fields = [
                 field for field in structure_info.fields if not utils.is_filtered(
                     field.metadata, enable_filtering)]
             return structure_info
     except Exception as ex:
         utils.eprint("Error fetching structure info for " + struct_type)
         utils.eprint(ex)
         return None
Esempio n. 6
0
    def test_is_filtered(self): 
        '''create a mock object for service info'''
        ServiceInfoMock = mock.Mock()
        ServiceInfoMock.metadata = { 'TechPreview' : {} }
        
        #case 1: enable filtering is False
        bool_value_expected = False
        bool_value_actual = utils.is_filtered(ServiceInfoMock.metadata, False)
        self.assertEqual(bool_value_expected, bool_value_actual)

        #case 2: enable filtering True
        bool_value_expected = False
        bool_value_actual = utils.is_filtered(ServiceInfoMock.metadata, True)
        self.assertEqual(bool_value_expected, bool_value_actual)

        #case 3: metadata is empty
        ServiceInfoMock.metadata = {}
        bool_value_expected = False
        bool_value_actual = utils.is_filtered(ServiceInfoMock.metadata, True)
        self.assertEqual(bool_value_expected, bool_value_actual)
       
        #case 4: enable filtering is True and metadata contains changing 
        ServiceInfoMock.metadata = { 
                'Changing' : {},
                'Proposed' : {}
            }
        bool_value_expected = True
        bool_value_actual = utils.is_filtered(ServiceInfoMock.metadata, True)
        self.assertEqual(bool_value_expected, bool_value_actual)

        # case 5: enable filtering is True and metadata does not contain 'TechPreview', 'Changing' or 'Proposed'
        ServiceInfoMock.metadata = { 
                'mock metadata key' : {}
            }
        bool_value_expected = False
        bool_value_actual = utils.is_filtered(ServiceInfoMock.metadata, True)
        self.assertEqual(bool_value_expected, bool_value_actual)
 def get_enum_info(self, type_name, enum_svc, enable_filtering):
     """
     Given a type, return its enum info, if the type is enum.
     """
     try:
         enum_info = enum_svc.get(type_name)
         if enum_info is None:
             utils.eprint("Could not fetch enum info for " + type_name)
         elif utils.is_filtered(enum_info.metadata, enable_filtering):
             return None
         else:
             return enum_info
     except Exception as exception:
         utils.eprint("Error fetching enum info for " + type_name)
         utils.eprint(exception)
         return None
Esempio n. 8
0
    def process_service_urls(self, package_name, service_urls, output_dir,
                             structure_dict, enum_dict, service_dict,
                             service_url_dict, http_error_map,
                             rest_navigation_url, enable_filtering, spec,
                             gen_unique_op_id):

        print('processing package ' + package_name + os.linesep)
        type_dict = {}
        path_list = []
        for service_url in service_urls:
            service_name, service_end_point = service_url_dict.get(
                service_url, None)
            service_info = service_dict.get(service_name, None)
            if service_info is None:
                continue
            if utils.is_filtered(service_info.metadata, enable_filtering):
                continue
            if self.contains_rm_annotation(service_info):
                for operation in service_info.operations.values():
                    url, method = self.find_url_method(operation)
                    operation_id = operation.name
                    op_metadata = service_info.operations[
                        operation_id].metadata
                    if utils.is_filtered(op_metadata, enable_filtering):
                        continue
                    operation_info = service_info.operations.get(operation_id)

                    if spec == '2':
                        path = swagg.get_path(operation_info, method, url,
                                              service_name, type_dict,
                                              structure_dict, enum_dict,
                                              operation_id, http_error_map,
                                              enable_filtering)
                    if spec == '3':
                        path = openapi.get_path(operation_info, method, url,
                                                service_name, type_dict,
                                                structure_dict, enum_dict,
                                                operation_id, http_error_map,
                                                enable_filtering)

                    path_list.append(path)
                continue
            # use rest navigation service to get the REST mappings for a
            # service.
            service_operations = utils.get_json(
                rest_navigation_url + service_url + '?~method=OPTIONS', False)
            if service_operations is None:
                continue

            for service_operation in service_operations:
                service_name = service_operation['service']
                # service_info must be re-assigned when service_operations are obtained through ?~method=OPTIONS.
                # this is because all service operations matching the prefix of the service is returned instead of returning
                # only operations which has exact match.
                # for example OPTIONS on com.vmware.content.library returns operations from following services
                # instead of just com.vmware.content.library.item
                # com.vmware.content.library.item.storage
                # com.vmware.content.library.item
                # com.vmware.content.library.item.file
                # com.vmware.content.library.item.update_session
                # com.vmware.content.library.item.updatesession.file
                service_info = service_dict.get(service_name, None)
                if service_info is None:
                    continue
                operation_id = service_operation['name']
                if operation_id not in service_info.operations:
                    continue
                op_metadata = service_info.operations[operation_id].metadata
                if utils.is_filtered(op_metadata, enable_filtering):
                    continue
                url, method = self.find_url(service_operation['links'])
                url = self.get_service_path_from_service_url(
                    url, rest_navigation_url)
                operation_info = service_info.operations.get(operation_id)

                if spec == '2':
                    path = swagg.get_path(operation_info, method, url,
                                          service_name, type_dict,
                                          structure_dict, enum_dict,
                                          operation_id, http_error_map,
                                          enable_filtering)
                if spec == '3':
                    path = openapi.get_path(operation_info, method, url,
                                            service_name, type_dict,
                                            structure_dict, enum_dict,
                                            operation_id, http_error_map,
                                            enable_filtering)

                path_list.append(path)
        path_dict = self.convert_path_list_to_path_map(path_list)
        self.cleanup(path_dict=path_dict, type_dict=type_dict)
        if spec == '2':
            rest_swagg_fpp.process_output(path_dict, type_dict, output_dir,
                                          package_name, gen_unique_op_id)
        if spec == '3':
            rest_openapi_fpp.process_output(path_dict, type_dict, output_dir,
                                            package_name, gen_unique_op_id)
    def get_path_and_type_dicts(
            self,
            package_name,
            service_urls,
            structure_dict,
            enum_dict,
            service_dict,
            service_url_dict,
            http_error_map,
            rest_navigation_handler,
            show_unreleased_apis,
            spec,
            auth_navigator=None,
            deprecation_handler=None):

        print('processing package ' + package_name + os.linesep)
        type_dict = {}
        path_list = []

        for service_url in service_urls:
            service_name, service_end_point = service_url_dict.get(
                service_url, None)
            service_info = service_dict.get(service_name, None)
            if service_info is None:
                continue
            if (not show_unreleased_apis) and utils.is_filtered(service_info.metadata):
                continue
            if self.contains_rm_annotation(service_info):
                for operation in service_info.operations.values():
                    url, method = self.find_url_method(operation)
                    operation_id = operation.name
                    op_metadata = service_info.operations[operation_id].metadata
                    if (not show_unreleased_apis) and utils.is_filtered(op_metadata):
                        continue
                    operation_info = service_info.operations.get(operation_id)

                    if spec == '2':
                        path = swagg.get_path(
                            operation_info,
                            method,
                            url,
                            service_name,
                            type_dict,
                            structure_dict,
                            enum_dict,
                            operation_id,
                            http_error_map,
                            show_unreleased_apis)

                        if auth_navigator is not None:
                            scheme_set = auth_navigator.find_schemes_set(operation_id, service_name, package_name)
                            if scheme_set is not None and len(scheme_set) != 0:
                                swagg.decorate_path_with_security(path, scheme_set)

                    if spec == '3':
                        path = openapi.get_path(
                            operation_info,
                            method,
                            url,
                            service_name,
                            type_dict,
                            structure_dict,
                            enum_dict,
                            operation_id,
                            http_error_map,
                            show_unreleased_apis)

                    if deprecation_handler is not None and service_end_point == "/deprecated":
                        deprecation_handler.add_deprecation_information(path, package_name, service_name)
                    path_list.append(path)
                continue
            # use rest navigation service to get the REST mappings for a
            # service.
            service_operations = rest_navigation_handler.get_service_operations(service_url)
            if service_operations is None:
                continue

            for service_operation in service_operations:
                service_name = service_operation['service']
                # service_info must be re-assigned when service_operations are obtained through ?~method=OPTIONS.
                # this is because all service operations matching the prefix of the service is returned instead of returning
                # only operations which has exact match.
                # for example OPTIONS on com.vmware.content.library returns operations from following services
                # instead of just com.vmware.content.library.item
                # com.vmware.content.library.item.storage
                # com.vmware.content.library.item
                # com.vmware.content.library.item.file
                # com.vmware.content.library.item.update_session
                # com.vmware.content.library.item.updatesession.file
                service_info = service_dict.get(service_name, None)
                if service_info is None:
                    continue
                operation_id = service_operation['name']
                if operation_id not in service_info.operations:
                    continue
                op_metadata = service_info.operations[operation_id].metadata
                if (not show_unreleased_apis) and utils.is_filtered(op_metadata):
                    continue
                url, method = self.find_url(service_operation['links'])
                url = self.get_service_path_from_service_url(
                    url, rest_navigation_handler.get_rest_navigation_url())
                operation_info = service_info.operations.get(operation_id)

                if spec == '2':
                    path = swagg.get_path(
                        operation_info,
                        method,
                        url,
                        service_name,
                        type_dict,
                        structure_dict,
                        enum_dict,
                        operation_id,
                        http_error_map,
                        show_unreleased_apis)

                    if auth_navigator is not None:
                        scheme_set = auth_navigator.find_schemes_set(operation_id, service_name, package_name)
                        if scheme_set is not None and len(scheme_set) != 0:
                            swagg.decorate_path_with_security(path, scheme_set)

                if spec == '3':
                    path = openapi.get_path(
                        operation_info,
                        method,
                        url,
                        service_name,
                        type_dict,
                        structure_dict,
                        enum_dict,
                        operation_id,
                        http_error_map,
                        show_unreleased_apis)

                if deprecation_handler is not None and service_end_point == "/deprecated":
                    deprecation_handler.add_deprecation_information(path, package_name, service_name)
                path_list.append(path)
        path_dict = self.convert_path_list_to_path_map(path_list)
        self.cleanup(path_dict=path_dict, type_dict=type_dict)
        return path_dict, type_dict
Esempio n. 10
0
    def get_path_and_type_dicts(self,
                                package_name,
                                service_urls,
                                structure_dict,
                                enum_dict,
                                service_dict,
                                service_url_dict,
                                http_error_map,
                                show_unreleased_apis,
                                spec,
                                auth_navigator=None):

        print('processing package ' + package_name + os.linesep)
        type_dict = {}
        path_list = []
        for service_url in service_urls:
            service_name, service_end_point = service_url_dict.get(
                service_url, None)
            service_info = service_dict.get(service_name, None)
            if service_info is None:
                continue
            if (not show_unreleased_apis) and utils.is_filtered(
                    service_info.metadata):
                continue
            for operation_id, operation_info in service_info.operations.items(
            ):

                method, url = self.api_get_url_and_method(
                    operation_info.metadata)
                if method is None or url is None:
                    continue

                # check for query parameters
                if 'params' in operation_info.metadata[method].elements:
                    element_value = operation_info.metadata[method].elements[
                        'params']
                    params = "&".join(element_value.list_value)
                    url = url + '?' + params

                if spec == '2':
                    path = swagg.get_path(operation_info, method, url,
                                          service_name, type_dict,
                                          structure_dict, enum_dict,
                                          operation_id, http_error_map,
                                          show_unreleased_apis)
                    if auth_navigator is not None:
                        scheme_set = auth_navigator.find_schemes_set(
                            operation_id, service_name, package_name)
                        if scheme_set is not None and len(scheme_set) != 0:
                            swagg.decorate_path_with_security(path, scheme_set)
                if spec == '3':
                    path = openapi.get_path(operation_info, method, url,
                                            service_name, type_dict,
                                            structure_dict, enum_dict,
                                            operation_id, http_error_map,
                                            show_unreleased_apis)

                path_list.append(path)
            continue

        path_dict = self.convert_path_list_to_path_map(path_list)
        self.cleanup(path_dict=path_dict, type_dict=type_dict)
        return path_dict, type_dict
 def __get_enum_info_filtered(self, type_name, enum_svc):
     enum_info = self.__get_enum_info(type_name, enum_svc)
     if enum_info is None or utils.is_filtered(enum_info.metadata):
         return None
     return enum_info