Skip to content

Commit 8e5c4da

Browse files
committed
Support new token paramater when deploying certificate
1 parent 5a6539d commit 8e5c4da

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/Endpoint/Certificates.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function all()
2121
$certificates = [];
2222

2323
foreach ($this->get($this->getEndpoint()) as $certificate) {
24-
$certificates[] = str_replace('/'.$this->client->getApiVersion().$this->getEndpoint(), '', $certificate);
24+
$certificates[] = str_replace('/' . $this->client->getApiVersion() . $this->getEndpoint(), '', $certificate);
2525
}
2626

2727
return $certificates;
@@ -35,7 +35,7 @@ public function all()
3535
*/
3636
public function info($fingerprint)
3737
{
38-
return $this->get($this->getEndpoint().$fingerprint);
38+
return $this->get($this->getEndpoint() . $fingerprint);
3939
}
4040

4141
/**
@@ -51,14 +51,15 @@ public function info($fingerprint)
5151
* @param string $password Password for untrusted client
5252
* @param string $name Name for the certificate. If nothing is provided, the host in the TLS header for
5353
* the request is used.
54+
* @param string $token The join token to use in modern LXD (leave password as null)
5455
* @return string fingerprint of certificate
5556
*/
56-
public function add($certificate, $password = null, $name = null)
57+
public function add($certificate, $password = null, $name = null, $token = null)
5758
{
5859
// Convert PEM certificate to DER certificate
5960
$begin = "CERTIFICATE-----";
6061
$end = "-----END";
61-
$pem_data = substr($certificate, strpos($certificate, $begin)+strlen($begin));
62+
$pem_data = substr($certificate, strpos($certificate, $begin) + strlen($begin));
6263
$pem_data = substr($pem_data, 0, strpos($pem_data, $end));
6364
$der = base64_decode($pem_data);
6465

@@ -72,11 +73,15 @@ public function add($certificate, $password = null, $name = null)
7273
$options['password'] = $password;
7374
}
7475

76+
if ($token !== null) {
77+
$options['trust_token'] = $token;
78+
}
79+
7580
if ($name !== null) {
7681
$options['name'] = $name;
7782
}
7883

79-
$response = $this->post($this->getEndpoint(), $options);
84+
$this->post($this->getEndpoint(), $options);
8085

8186
return $fingerprint;
8287
}
@@ -88,6 +93,6 @@ public function add($certificate, $password = null, $name = null)
8893
*/
8994
public function remove($fingerprint)
9095
{
91-
$this->delete($this->getEndpoint().$fingerprint);
96+
$this->delete($this->getEndpoint() . $fingerprint);
9297
}
9398
}

0 commit comments

Comments
 (0)