예제 #1
0
    def update_service_public_key(self,
                                  service_id,
                                  key_id,
                                  expires=False,
                                  active=None):
        """
        Updates a public key from a Service
        :param service_id: Unique Service ID
        :param key_id: MD5 fingerprint of the public key,
        IE: e0:2f:a9:5a:76:92:6b:b5:4d:24:67:19:d1:8a:0a:75
        :param expires: datetime.datetime stating a time in which the key will
        no longer be valid
        :param active: Bool stating whether the key should be considered active
        and usable
        :raise: launchkey.exceptions.PublicKeyDoesNotExist - The key_id you
        supplied could not be found
        :raise: launchkey.exceptions.Forbidden - The Service you requested
        either does not exist or you do not have sufficient permissions.
        :return:
        """
        kwargs = {"service_id": str(service_id), "key_id": key_id}
        if active is not None:
            kwargs['active'] = active
        if expires is not False:
            kwargs['date_expires'] = iso_format(expires)

        self._transport.patch("{}/keys".format(self.__service_base_path[0:-1]),
                              self._subject, **kwargs)
예제 #2
0
 def add_service_public_key(self,
                            service_id,
                            public_key,
                            expires=None,
                            active=None):
     """
     Adds a public key to a Service
     :param service_id: Unique Service ID
     :param public_key: String RSA public key
     :param expires: Optional datetime.datetime stating a time in which the
     key will no longer be valid
     :param active: Optional bool stating whether the key should be
     considered active and usable.
     :raise: launchkey.exceptions.InvalidParameters - Input parameters were
     not correct
     :raise: launchkey.exceptions.InvalidPublicKey - The public key you
     supplied is not valid.
     :raise: launchkey.exceptions.PublicKeyAlreadyInUse - The public key
     you supplied already exists for the requested entity. It cannot be
     added again.
     :return: MD5 fingerprint (key_id) of the public key,
     IE: e0:2f:a9:5a:76:92:6b:b5:4d:24:67:19:d1:8a:0a:75
     """
     kwargs = {"service_id": str(service_id), "public_key": public_key}
     if expires is not None:
         kwargs['date_expires'] = iso_format(expires)
     if active is not None:
         kwargs['active'] = active
     key_id = self._transport.post(
         "{}/keys".format(self.__service_base_path[0:-1]), self._subject,
         **kwargs).data['key_id']
     return key_id
예제 #3
0
 def test_iso_format_success(self):
     self.assertEqual(
         "2017-10-03T22:50:15Z",
         iso_format(
             datetime(year=2017,
                      month=10,
                      day=3,
                      hour=22,
                      minute=50,
                      second=15,
                      tzinfo=pytz.timezone("UTC"))))
예제 #4
0
 def test_iso_format_none(self):
     self.assertIsNone(iso_format(None))
예제 #5
0
 def test_iso_format_none(self):
     self.assertIsNone(iso_format(None))
예제 #6
0
 def test_iso_format_success(self):
     self.assertEqual(
         "2017-10-03T22:50:15Z",
         iso_format(datetime(year=2017, month=10, day=3, hour=22, minute=50, second=15, tzinfo=pytz.timezone("UTC")))
     )