def get_behavior_on_interface_by_id( self, behavior_id, interface_id) -> Behavior: # noqa: E501 """Get the behavior details by its ID on the given interface. :param behavior_id: Id of the behavior. :param interface_id: Id of the interface. :return: The behavior details. """ response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.GET, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.INTERFACES}" f"/{interface_id}" f"/{CloudApiResource.BEHAVIORS}" f"/{behavior_id}") return Behavior(**response_body)
def create_behavior_on_interface(self, behavior: Behavior, interface_id) -> Behavior: # noqa: E501 """Create Behavior on the specified Interface. :param behavior: Behavior to be created. :param interface_id: Interface Id on which behavior is supposed to be created. :return: The created behavior object. """ response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.POST, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.INTERFACES}" f"/{interface_id}" f"/{CloudApiResource.BEHAVIORS}", payload=asdict(behavior)) return Behavior(**response_body)
def get_behavior_on_entity_type_by_id( self, behavior_interface_id, entity_type_id) -> Behavior: # noqa: E501 """Get the behavior on the entity type id. Note: Passing behavior-type id will not be accepted. :param behavior_interface_id: Id of the behavior-interface. :param entity_type_id: Id of the entity type. :return: The behavior details. """ response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.GET, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}" f"/{entity_type_id}" f"/{CloudApiResource.BEHAVIORS}" f"/{behavior_interface_id}") return Behavior(**response_body)
def override_behavior_on_entity_type( self, behavior: Behavior, entity_type_id) -> Behavior: # noqa: E501 """Override the behavior-interface on the specified entity type. Only Execution portion of the Behavior can be overridden. :param behavior: The updated behavior to be overridden on the entity-type. # noqa: E501 :param entity_type_id: Id of the entity type :return: Overridden behavior on the entity type. """ response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.PUT, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}" f"/{entity_type_id}" f"/{CloudApiResource.BEHAVIORS}" f"/{behavior.ref}", payload=asdict(behavior)) return Behavior(**response_body)
def list_behaviors_on_interface(self, interface_id) -> Iterator[Behavior]: """List all the behaviors on the specified interface. :param interface_id: Interface Id. :return: List of behaviors on the interface. """ page_num = 0 while True: page_num += 1 response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.GET, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.INTERFACES}" f"/{interface_id}" f"/{CloudApiResource.BEHAVIORS}?" f"page={page_num}") if len(response_body['values']) > 0: for behavior in response_body['values']: yield Behavior(**behavior) else: break
def create_behavior_on_entity_type( self, behavior: Behavior, entity_type_id) -> Behavior: # noqa: E501 """Create a behavior directly on the entity type. This method is non-functional. Under discussion with the Extensibility team on the error. TODO: Either update the docstring (or) remove the method. :param behavior: :param entity_type_id: :return: """ response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.POST, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}" f"/{entity_type_id}" f"/{CloudApiResource.BEHAVIORS}", payload=asdict(behavior)) return Behavior(**response_body)
def list_behaviors_on_entity_type( self, entity_type_id) -> Iterator[Behavior]: # noqa: E501 """List behaviors on the specified entity type. :param entity_type_id: Id of the entity type. :return: List of behaviors. """ # TODO Test this later, there is pagination issue on the entity types # endpoint. page_num = 0 while True: page_num += 1 response_body = self._cloudapi_client.do_request( method=cse_shared_constants.RequestMethod.GET, cloudapi_version=CloudApiVersion.VERSION_1_0_0, resource_url_relative_path=f"{CloudApiResource.ENTITY_TYPES}" f"/{entity_type_id}" f"/{CloudApiResource.BEHAVIORS}?" f"page={page_num}") if len(response_body['values']) > 0: for behavior in response_body['values']: yield Behavior(**behavior) else: break