diff --git a/libs/gl-client-py/glclient/__init__.py b/libs/gl-client-py/glclient/__init__.py index 7108a7ec6..dbde842d6 100644 --- a/libs/gl-client-py/glclient/__init__.py +++ b/libs/gl-client-py/glclient/__init__.py @@ -64,11 +64,10 @@ def is_running(self) -> bool: class Scheduler(object): - def __init__(self, node_id: bytes, network: str, creds: Optional[Credentials] = None): - self.node_id = node_id + def __init__(self, network: str, creds: Optional[Credentials] = None): self.network = network self.creds = creds if creds is not None else native.Credentials() - self.inner = native.Scheduler(node_id, network, self.creds) + self.inner = native.Scheduler(network, self.creds) def schedule(self) -> schedpb.NodeInfoResponse: res = self.inner.schedule() @@ -99,7 +98,7 @@ def node(self) -> "Node": res = self.inner.node() info = schedpb.NodeInfoResponse.FromString(bytes(res)) return Node( - node_id=self.node_id, + node_id=self.creds.node_id(), grpc_uri=info.grpc_uri, creds=self.creds, ) diff --git a/libs/gl-client-py/glclient/glclient.pyi b/libs/gl-client-py/glclient/glclient.pyi index 6e1704b1d..858455995 100644 --- a/libs/gl-client-py/glclient/glclient.pyi +++ b/libs/gl-client-py/glclient/glclient.pyi @@ -29,6 +29,7 @@ class Credentials: def from_path(path: str) -> Credentials: ... @staticmethod def from_parts(cert: bytes, key: bytes, ca: bytes, rune: str) -> Credentials: ... + def node_id() -> bytes: ... def upgrade(self, scheduler: Scheduler, signer: Signer) -> Credentials: ... def to_bytes(self) -> bytes: ... @@ -49,7 +50,7 @@ class Signer: class Scheduler: - def __init__(self, node_id: bytes, network: str, creds: Optional[Credentials]): ... + def __init__(self, network: str, creds: Optional[Credentials]): ... def register(self, signer: Signer, invite_code: Optional[str]) -> bytes: ... def recover(self, signer: Signer) -> bytes: ... def authenticate(self, creds: Credentials): ... diff --git a/libs/gl-client-py/src/credentials.rs b/libs/gl-client-py/src/credentials.rs index 8745a04b5..939cdd652 100644 --- a/libs/gl-client-py/src/credentials.rs +++ b/libs/gl-client-py/src/credentials.rs @@ -169,6 +169,10 @@ impl Credentials { pub fn ensure_nobody(&self) -> Result<()> { self.inner.ensure_nobody() } + + pub fn node_id(&self) -> Result> { + Ok(self.inner.node_id()?) + } } type Result = std::result::Result; diff --git a/libs/gl-client-py/tests/test_scheduler.py b/libs/gl-client-py/tests/test_scheduler.py index c18f1bc5f..06ebe0505 100644 --- a/libs/gl-client-py/tests/test_scheduler.py +++ b/libs/gl-client-py/tests/test_scheduler.py @@ -8,7 +8,7 @@ def test_connect(scheduler, creds): """Test that we can connect to the scheduler.""" sig = Signer(b"\x00" * 32, network="regtest", creds=creds) node_id = sig.node_id() - s = Scheduler(node_id, network="regtest", creds=creds) + s = Scheduler(network="regtest", creds=creds) with pytest.raises(ValueError): s.recover(sig) diff --git a/libs/gl-client/src/scheduler.rs b/libs/gl-client/src/scheduler.rs index 9f0ae5a93..28aec6cac 100644 --- a/libs/gl-client/src/scheduler.rs +++ b/libs/gl-client/src/scheduler.rs @@ -41,7 +41,7 @@ where /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Nobody::new(); - /// let scheduler = Scheduler::new(node_id, network, creds).await.unwrap(); + /// let scheduler = Scheduler::new(network, creds).await.unwrap(); /// # } /// ``` pub async fn new(network: Network, creds: Creds) -> Result> { @@ -65,7 +65,7 @@ where /// let network = Network::Regtest; /// let creds = Nobody::new(); /// let uri = "https://example.com".to_string(); - /// let scheduler = Scheduler::with(node_id, network, creds, uri).await.unwrap(); + /// let scheduler = Scheduler::with(network, creds, uri).await.unwrap(); /// # } /// ``` pub async fn with( @@ -114,7 +114,7 @@ impl Scheduler { /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Nobody::new(); - /// let scheduler = Scheduler::new(node_id.clone(), network, creds.clone()).await.unwrap(); + /// let scheduler = Scheduler::new(network, creds.clone()).await.unwrap(); /// let secret = vec![0, 0, 0, 0]; /// let signer = Signer::new(secret, network, creds).unwrap(); // Create or obtain a signer instance /// let registration_response = scheduler.register(&signer, None).await.unwrap(); @@ -242,7 +242,7 @@ impl Scheduler { /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Nobody::new(); - /// let scheduler = Scheduler::new(node_id.clone(), network, creds.clone()).await.unwrap(); + /// let scheduler = Scheduler::new(network, creds.clone()).await.unwrap(); /// let secret = vec![0, 0, 0, 0]; /// let signer = Signer::new(secret, network, creds).unwrap(); // Create or obtain a signer instance /// let recovery_response = scheduler.recover(&signer).await.unwrap(); @@ -341,7 +341,7 @@ impl Scheduler { /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Nobody::new(); - /// let scheduler_unauthed = Scheduler::new(node_id.clone(), network, creds.clone()).await.unwrap(); + /// let scheduler_unauthed = Scheduler::new(network, creds.clone()).await.unwrap(); /// let secret = vec![0, 0, 0, 0]; /// let signer = Signer::new(secret, network, creds).unwrap(); // Create or obtain a signer instance /// let registration_response = scheduler_unauthed.register(&signer, None).await.unwrap(); @@ -391,7 +391,7 @@ where /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Device::from_path("my/path/to/credentials.glc"); - /// let scheduler = Scheduler::new(node_id.clone(), network, creds.clone()).await.unwrap(); + /// let scheduler = Scheduler::new(network, creds.clone()).await.unwrap(); /// let info = scheduler.schedule().await.unwrap(); /// let node_client: Client = Node::new(node_id, creds).unwrap().connect(info.grpc_uri).await.unwrap(); /// # } @@ -421,7 +421,7 @@ where /// let node_id = vec![0, 1, 2, 3]; /// let network = Network::Regtest; /// let creds = Device::from_path("my/path/to/credentials.glc"); - /// let scheduler = Scheduler::new(node_id.clone(), network, creds.clone()).await.unwrap(); + /// let scheduler = Scheduler::new(network, creds.clone()).await.unwrap(); /// let node_client: Client = scheduler.node().await.unwrap(); /// # } /// ``` @@ -518,33 +518,4 @@ where .await?; Ok(res.into_inner()) } -} - -#[cfg(test)] -mod tests { - use crate::credentials::Device; - - use super::*; - - #[tokio::test] - async fn test_node_returns_error_on_node_id_mismatch() { - let cert_node_id: [u8; 32] = rand::random(); - let device_cert = tls::generate_self_signed_device_cert( - &hex::encode(cert_node_id.clone()), - "default".into(), - vec!["localhost".into()], - ); - - let device_crt = device_cert.serialize_pem().unwrap(); - let device_key = device_cert.serialize_private_key_pem(); - - let creds = Device::with(device_crt, device_key, String::new(), ""); - - let scheduler_node_id: [u8; 32] = rand::random(); - let sched = Scheduler::new(scheduler_node_id.to_vec(), Network::Bitcoin, creds) - .await - .unwrap(); - - assert!(sched.node::().await.is_err_and(|e| e.to_string().contains("The node_id defined on the Credential's certificate does not match the node_id the scheduler was initialized with"))); - } -} +} \ No newline at end of file diff --git a/libs/gl-testing/gltesting/clients.py b/libs/gl-testing/gltesting/clients.py index 0e2f9306c..c4b18deb1 100644 --- a/libs/gl-testing/gltesting/clients.py +++ b/libs/gl-testing/gltesting/clients.py @@ -100,7 +100,7 @@ def creds(self) -> glclient.Credentials: def scheduler(self, authenticate: bool = False) -> glclient.Scheduler: """Return a scheduler stub configured with our identity if configured.""" - scheduler = glclient.Scheduler(self.node_id, network=NETWORK, creds=self.creds()) + scheduler = glclient.Scheduler(network=NETWORK, creds=self.creds()) if authenticate: scheduler.authenticate(creds=self.creds()) return scheduler