| 627 | /// CloudPubError: Если регистрация не удалась |
| 628 | #[pyo3(signature = (protocol, address, name=None, auth=None, acl=None, headers=None, rules=None))] |
| 629 | fn register( |
| 630 | &self, |
| 631 | protocol: Protocol, |
| 632 | address: String, |
| 633 | name: Option<String>, |
| 634 | auth: Option<Auth>, |
| 635 | acl: Option<Vec<Acl>>, |
| 636 | headers: Option<Vec<Header>>, |
| 637 | rules: Option<Vec<FilterRule>>, |
| 638 | ) -> PyResult<ServerEndpoint> { |
| 639 | let proto: protocol::Protocol = protocol.into(); |
| 640 | let auth_type = auth.map(|a| a.into()); |
| 641 | let acl_list = acl.map(|list| list.into_iter().map(|a| a.into()).collect()); |
| 642 | let header_list = headers.map(|list| list.into_iter().map(|h| h.into()).collect()); |
| 643 | let rule_list = rules.map(|list| list.into_iter().map(|r| r.into()).collect()); |
| 644 | |
| 645 | let endpoint = self |
| 646 | .runtime |
| 647 | .block_on(async { |
| 648 | let mut conn = self.connection.write(); |
| 649 | conn.register( |
| 650 | proto, |
| 651 | address, |
| 652 | name, |
| 653 | auth_type, |
| 654 | acl_list, |
| 655 | header_list, |
| 656 | rule_list, |
| 657 | ) |
| 658 | .await |
| 659 | }) |
| 660 | .map_err(|e| CloudPubError::new_err(format!("Регистрация не удалась: {}", e)))?; |
| 661 | |
| 662 | Ok(ServerEndpoint { |
| 663 | url: endpoint.as_url(), |
| 664 | guid: endpoint.guid, |
| 665 | status: endpoint.status, |
| 666 | remote_proto: format!("{:?}", endpoint.remote_proto).to_lowercase(), |
| 667 | remote_addr: endpoint.remote_addr, |
| 668 | remote_port: endpoint.remote_port, |
| 669 | error: endpoint.error, |
| 670 | }) |
| 671 | } |
| 672 | |
| 673 | /// Опубликовать сервис (зарегистрировать и запустить) |
| 674 | /// |