Keypairs
========

Setup
-----

.. include:: service.sample.rst


Generate a new keypair
----------------------

This operation creates a new keypair under a provided name; the public key
value is automatically generated for you.

.. code:: php

  // Instantiate empty object
  $keypair = $service->keypair();

  // Send to API
  $keypair->create(array(
     'name' => 'jamie_keypair_1'
  ));

  // Save these!
  $pubKey = $keypair->getPublicKey();
  $priKey = $keypair->getPrivateKey();


Upload existing keypair
-----------------------

This operation creates a new keypair according to a provided name and public
key value. This is useful when the public key already exists on your local
filesystem.

.. code:: php

  $keypair = $service->keypair();

  // $key needs to be the string content of the key file, not the filename
  $content = file_get_contents('~/.ssh/id_rsa.pub');

  $keypair->create(array(
     'name'      => 'main_key',
     'publicKey' => $content
  ));

List keypairs
-------------

To list all existing keypairs:

.. code:: php

  $keys = $service->listKeypairs();

  foreach ($keys as $key) {

  }


Delete keypairs
---------------

To delete a specific keypair:

.. code:: php

  $keypair->delete();
