File: ssh.py

package info (click to toggle)
python-bitbucket-api 0.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 128 kB
  • sloc: python: 661; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
URLS = {
    # SSH keys
    'GET_SSH_KEYS': 'ssh-keys/',
    'GET_SSH_KEY': 'ssh-keys/%(key_id)s',
    'SET_SSH_KEY': 'ssh-keys/',
    'DELETE_SSH_KEY': 'ssh-keys/%(key_id)s',
}


class SSH(object):
    """ This class provide ssh-related methods to Bitbucket objects."""

    def __init__(self, bitbucket):
        self.bitbucket = bitbucket
        self.bitbucket.URLS.update(URLS)

    def all(self):
        """ Get all ssh keys associated with your account.
        """
        url = self.bitbucket.url('GET_SSH_KEYS')
        return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth)

    def get(self, key_id=None):
        """ Get one of the ssh keys associated with your account.
        """
        url = self.bitbucket.url('GET_SSH_KEY', key_id=key_id)
        return self.bitbucket.dispatch('GET', url, auth=self.bitbucket.auth)

    def create(self, key=None, label=None):
        """ Associate an ssh key with your account and return it.
        """
        key = '%s' % key
        url = self.bitbucket.url('SET_SSH_KEY')
        return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, key=key, label=label)

    def delete(self, key_id=None):
        """ Delete one of the ssh keys associated with your account.
            Please use with caution as there is NO confimation and NO undo.
        """
        url = self.bitbucket.url('DELETE_SSH_KEY', key_id=key_id)
        return self.bitbucket.dispatch('DELETE', url, auth=self.bitbucket.auth)