| 688 | /// CloudPubError: Если публикация не удалась |
| 689 | #[pyo3(signature = (protocol, address, name=None, auth=None, acl=None, headers=None, rules=None))] |
| 690 | fn publish( |
| 691 | &self, |
| 692 | protocol: Protocol, |
| 693 | address: String, |
| 694 | name: Option<String>, |
| 695 | auth: Option<Auth>, |
| 696 | acl: Option<Vec<Acl>>, |
| 697 | headers: Option<Vec<Header>>, |
| 698 | rules: Option<Vec<FilterRule>>, |
| 699 | ) -> PyResult<ServerEndpoint> { |
| 700 | let proto: protocol::Protocol = protocol.into(); |
| 701 | let auth_type = auth.map(|a| a.into()); |
| 702 | let acl_list = acl.map(|list| list.into_iter().map(|a| a.into()).collect()); |
| 703 | let header_list = headers.map(|list| list.into_iter().map(|h| h.into()).collect()); |
| 704 | let rule_list = rules.map(|list| list.into_iter().map(|r| r.into()).collect()); |
| 705 | |
| 706 | let endpoint = self |
| 707 | .runtime |
| 708 | .block_on(async { |
| 709 | let mut conn = self.connection.write(); |
| 710 | conn.publish( |
| 711 | proto, |
| 712 | address, |
| 713 | name, |
| 714 | auth_type, |
| 715 | acl_list, |
| 716 | header_list, |
| 717 | rule_list, |
| 718 | ) |
| 719 | .await |
| 720 | }) |
| 721 | .map_err(|e| CloudPubError::new_err(format!("Публикация не удалась: {}", e)))?; |
| 722 | |
| 723 | Ok(ServerEndpoint { |
| 724 | url: endpoint.as_url(), |
| 725 | guid: endpoint.guid, |
| 726 | status: endpoint.status, |
| 727 | remote_proto: format!("{:?}", endpoint.remote_proto).to_lowercase(), |
| 728 | remote_addr: endpoint.remote_addr, |
| 729 | remote_port: endpoint.remote_port, |
| 730 | error: endpoint.error, |
| 731 | }) |
| 732 | } |
| 733 | |
| 734 | /// Запустить публикацию по GUID |
| 735 | /// |