| 1 |  |  | #! /usr/bin/env python | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | """Team Password Manager API | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | To simplify usage of Team Password Manager API. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | You can authenticate with username and password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     >>> import tpm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     >>> URL = "https://mypasswordmanager.example.com" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     >>> USER = 'MyUser' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     >>> PASS = 'Secret' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     >>> tpmconn = tpm.TpmApiv4(URL, username=USER, password=PASS) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | Or with Private/Public Key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     >>> pubkey = '3726d93f2a0e5f0fe2cc3a6e9e3ade964b43b07f897d579466c28b7f8ff51cd0' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     >>> privkey = '87324bedead51af96a45271d217b8ad5ef3f220da6c078a9bce4e4318729189c' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     >>> tpmconn = tpm.TpmApiv4(URL, private_key=privkey, public_key=pubkey) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | With the connection object you can use all TPM functions, like list all passwords: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     >>> tpmconn.list_passwords() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | All API functions from Team Password Manager are included. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | see http://teampasswordmanager.com/docs/api/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | :copyright: (c) 2017 by Andreas Hubert. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | :license: The MIT License (MIT), see LICENSE for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | __version__ = '3.4' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | import hmac | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | import hashlib | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | import time | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | import requests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | import re | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | import json | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | import logging | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | from future.standard_library import install_aliases | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | install_aliases() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | from urllib.parse import quote_plus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | # set logger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | log = logging.getLogger(__name__) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | # disable unsecure SSL warning | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | requests.packages.urllib3.disable_warnings() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | class TPMException(Exception): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     pass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | class TpmApi(object): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     """Settings needed for the connection to Team Password Manager.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     class ConfigError(Exception): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         """To throw Exception based on wrong Settings.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         def __init__(self, value): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             self.value = value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             log.critical(value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         def __str__(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             return repr(self.value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     def __init__(self, api, base_url, kwargs): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         """init thing.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         # Check if API version is not bullshit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         REGEXurl = "^" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                    "(?:(?:https?)://)" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                    "(?:\\S+(?::\\S*)?@)?" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                    "(?:" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                    "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                    "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                    "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                    "|" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                    "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                    "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                    "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))?" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                    ".?" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                    ")" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                    "(?::\\d{2,5})?" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                    "(?:[/?#]\\S*)?" \ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                    "$" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         self.apiurl = 'api/' + api + '/' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         log.debug('Set as apiurl: %s' % self.apiurl) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         self.api = self.apiurl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         # Check if URL is not bullshit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         if re.match(REGEXurl, base_url): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             self.base_url = base_url + '/index.php/' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             log.debug('Set Base URL to %s' % self.base_url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             self.url = self.base_url + self.apiurl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             log.debug('Set URL to %s' % self.url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             raise self.ConfigError('Invalid URL: %s' % base_url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         # set headers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         self.headers = {'Content-Type': 'application/json; charset=utf-8', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                         'User-Agent': 'tpm.py/' + __version__ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         log.debug('Set header to %s' % self.headers) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         # check kwargs for either keys or user credentials | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         self.private_key = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         self.public_key = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         self.username = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         self.password = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         self.unlock_reason = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         self.max_retries = 3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         for key in kwargs: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             if key == 'private_key': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 self.private_key = kwargs[key] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             elif key == 'public_key': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 self.public_key = kwargs[key] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             elif key == 'username': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 self.username = kwargs[key] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             elif key == 'password': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                 self.password = kwargs[key] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             elif key == 'max_retries': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 self.max_retries = kwargs[key] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                 if self.max_retries < 1: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                     raise self.ConfigError('Parameter max_retires should be at least 1') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         log.debug("Max retries on ValueError: {}".format(self.max_retries)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         if self.private_key is not False and self.public_key is not False and\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 self.username is False and self.password is False: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             log.debug('Using Private/Public Key authentication.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         elif self.username is not False and self.password is not False and\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                 self.private_key is False and self.public_key is False: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             log.debug('Using Basic authentication.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             raise self.ConfigError('No authentication specified' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                                    ' (user/password or private/public key)') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     def request(self, path, action, data=''): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         """To make a request to the API.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         # Check if the path includes URL or not. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         head = self.base_url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         if path.startswith(head): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             path = path[len(head):] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         if not path.startswith(self.api): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             path = self.api + path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         log.debug('Using path %s' % path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         # If we have data, convert to JSON | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         if data: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             data = json.dumps(data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             log.debug('Data to sent: %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         # In case of key authentication | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         if self.private_key and self.public_key: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             timestamp = str(int(time.time())) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             log.debug('Using timestamp: {}'.format(timestamp)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             unhashed = path + timestamp + str(data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |             log.debug('Using message: {}'.format(unhashed)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             self.hash = hmac.new(str.encode(self.private_key), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                                  msg=unhashed.encode('utf-8'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                                  digestmod=hashlib.sha256).hexdigest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             log.debug('Authenticating with hash: %s' % self.hash) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             self.headers['X-Public-Key'] = self.public_key | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             self.headers['X-Request-Hash'] = self.hash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             self.headers['X-Request-Timestamp'] = timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             auth = False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         # In case of user credentials authentication | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         elif self.username and self.password: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             auth = requests.auth.HTTPBasicAuth(self.username, self.password) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         # Set unlock reason | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         if self.unlock_reason: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             self.headers['X-Unlock-Reason'] = self.unlock_reason | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             log.info('Unlock Reason: %s' % self.unlock_reason) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         url = head + path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         # Try API request and handle Exceptions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             if action == 'get': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |                 log.debug('GET request %s' % url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                 self.req = requests.get(url, headers=self.headers, auth=auth, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                                         verify=False) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             elif action == 'post': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |                 log.debug('POST request %s' % url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 self.req = requests.post(url, headers=self.headers, auth=auth, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                                          verify=False, data=data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             elif action == 'put': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 log.debug('PUT request %s' % url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                 self.req = requests.put(url, headers=self.headers, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                                         auth=auth, verify=False, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                                         data=data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             elif action == 'delete': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                 log.debug('DELETE request %s' % url) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                 self.req = requests.delete(url, headers=self.headers, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                                            verify=False, auth=auth) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |             if self.req.content == b'': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 result = None | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                 log.debug('No result returned.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |                 result = self.req.json() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |                 if 'error' in result and result['error']: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |                     raise TPMException(result['message']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         except requests.exceptions.RequestException as e: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             log.critical("Connection error for " + str(e)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             raise TPMException("Connection error for " + str(e)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         except ValueError as e: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             if self.req.status_code == 403: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |                 log.warning(url + " forbidden") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |                 raise TPMException(url + " forbidden") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             elif self.req.status_code == 404: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                 log.warning(url + " forbidden") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                 raise TPMException(url + " not found") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |                 message = ('%s: %s %s' % (e, self.req.url, self.req.text)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 log.debug(message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 if retries < self.max_retries: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                     continue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                 else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |                     raise ValueError(message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         return result | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     def post(self, path, data=''): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         """For post based requests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         return self.request(path, 'post', data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     def get(self, path): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         """For get based requests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         return self.request(path, 'get') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |     def put(self, path, data=''): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         """For put based requests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         self.request(path, 'put', data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     def delete(self, path): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         """For delete based requests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         self.request(path, 'delete') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |     def get_collection(self, path): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         """To get pagewise data.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         while True: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             items = self.get(path) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             req = self.req | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             for item in items: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |                 yield item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |             if req.links and req.links['next'] and\ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |                     req.links['next']['rel'] == 'next': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |                 path = req.links['next']['url'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |             else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |                 break | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |     def collection(self, path): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         """To return all items generated by get collection.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         data = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         for item in self.get_collection(path): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |             data.append(item) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         return data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     # From now on, Functions that work that way in all API Versions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     # http://teampasswordmanager.com/docs/api-projects/#list_projects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     def list_projects(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         """List projects.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         log.debug('List all projects.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         return self.collection('projects.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     def list_projects_archived(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         """List archived projects.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         log.debug('List all archived projects.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         return self.collection('projects/archived.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |     def list_projects_favorite(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         """List favorite projects.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |         log.debug('List all favorite projects.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         return self.collection('projects/favorite.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     def list_projects_search(self, searchstring): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         """List projects with searchstring.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         log.debug('List all projects with: %s' % searchstring) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         return self.collection('projects/search/%s.json' % | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |                                quote_plus(searchstring)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     def show_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         """Show a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#show_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |         log.debug('Show project info: %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         return self.get('projects/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |     def list_passwords_of_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         """List passwords of project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#list_pwds_prj | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         log.debug('List passwords of project: %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         return self.collection('projects/%s/passwords.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |     def list_user_access_on_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         """List users who can access a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#list_users_prj | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         log.debug('List User access on project: %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         return self.collection('projects/%s/security.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |     def create_project(self, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |         """Create a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#create_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         log.info('Create project: %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         NewID = self.post('projects.json', data).get('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         log.info('Project has been created with ID %s' % NewID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         return NewID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |     def update_project(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |         """Update a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#update_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |         log.info('Update project %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |         self.put('projects/%s.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     def change_parent_of_project(self, ID, NewParrentID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         """Change parent of project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#change_parent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         log.info('Change parrent for project %s to %s' % (ID, NewParrentID)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |         data = {'parent_id': NewParrentID} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |         self.put('projects/%s/change_parent.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |     def update_security_of_project(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         """Update security of project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#update_project_security | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |         log.info('Update project %s security %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         self.put('projects/%s/security.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |     def archive_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |         """Archive a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#arch_unarch_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         log.info('Archive project %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         self.put('projects/%s/archive.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |     def unarchive_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         """Un-Archive a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#arch_unarch_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |         log.info('Unarchive project %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |         self.put('projects/%s/unarchive.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     def delete_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         """Delete a project.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#delete_project | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |         log.info('Delete project %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |         self.delete('projects/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |     # http://teampasswordmanager.com/docs/api-passwords/#list_passwords | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |     def list_passwords(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |         """List passwords.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |         log.debug('List all passwords.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |         return self.collection('passwords.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |     def list_passwords_archived(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |         """List archived passwords.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |         log.debug('List archived passwords.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |         return self.collection('passwords/archived.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |     def list_passwords_favorite(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |         """List favorite passwords.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |         log.debug('List favorite spasswords.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |         return self.collection('passwords/favorite.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |     def list_passwords_search(self, searchstring): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |         """List passwords with searchstring.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         log.debug('List all passwords with: %s' % searchstring) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |         return self.collection('passwords/search/%s.json' % | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |                                quote_plus(searchstring)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |     def show_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |         """Show password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#show_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |         log.info('Show password info: %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |         return self.get('passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |     def list_user_access_on_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |         """List users who can access a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#list_users_pwd | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         log.debug('List user access on password %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |         return self.collection('passwords/%s/security.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |     def create_password(self, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         """Create a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#create_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |         log.info('Create new password %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |         NewID = self.post('passwords.json', data).get('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |         log.info('Password has been created with ID %s' % NewID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         return NewID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |     def update_password(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |         """Update a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#update_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |         log.info('Update Password %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |         self.put('passwords/%s.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |     def update_security_of_password(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         """Update security of a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#update_security_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |         log.info('Update security of password %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |         self.put('passwords/%s/security.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |     def update_custom_fields_of_password(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |         """Update custom fields definitions of a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#update_cf_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |         log.info('Update custom fields of password %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |         self.put('passwords/%s/custom_fields.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |     def delete_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |         """Delete a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#delete_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |         log.info('Delete password %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |         self.delete('passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |     def lock_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |         """Lock a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#lock_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |         log.info('Lock password %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |         self.put('passwords/%s/lock.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |     def unlock_password(self, ID, reason): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |         """Unlock a password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |         # http://teampasswordmanager.com/docs/api-passwords/#unlock_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |         log.info('Unlock password %s, Reason: %s' % (ID, reason)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |         self.unlock_reason = reason | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |         self.put('passwords/%s/unlock.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |     def list_mypasswords(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |         """List my passwords.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |         log.debug('List MyPasswords') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         return self.collection('my_passwords.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |     def list_mypasswords_search(self, searchstring): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         """List my passwords with searchstring.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |         log.debug('List MyPasswords with %s' % searchstring) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |         return self.collection('my_passwords/search/%s.json' % | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |                                quote_plus(searchstring)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |     def show_mypassword(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |         """Show my password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#show_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |         log.debug('Show MyPassword %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |         return self.get('my_passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |     def create_mypassword(self, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |         """Create my password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#create_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |         log.info('Create MyPassword with %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |         NewID = self.post('my_passwords.json', data).get('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |         log.info('MyPassword has been created with %s' % NewID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |         return NewID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |     def update_mypassword(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |         """Update my password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#update_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |         log.info('Update MyPassword %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |         self.put('my_passwords/%s.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |     def delete_mypassword(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |         """Delete my password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |         # http://teampasswordmanager.com/docs/api-my-passwords/#delete_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |         log.info('Delete password %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |         self.delete('my_passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |     def set_favorite_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |         """Set a password as favorite.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |         # http://teampasswordmanager.com/docs/api-favorites/#set_fav | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |         log.info('Set password %s as favorite' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |         self.post('favorite_passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |     def unset_favorite_password(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |         """Unet a password as favorite.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |         # http://teampasswordmanager.com/docs/api-favorites/#del_fav | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |         log.info('Unset password %s as favorite' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |         self.delete('favorite_passwords/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |     def set_favorite_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |         """Set a project as favorite.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |         # http://teampasswordmanager.com/docs/api-favorites/#set_fav | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |         log.info('Set project %s as favorite' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |         self.post('favorite_project/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |     def unset_favorite_project(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |         """Unet a project as favorite.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |         # http://teampasswordmanager.com/docs/api-favorites/#del_fav | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |         log.info('Unset project %s as favorite' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |         self.delete('favorite_project/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |     def list_users(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |         """List users.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |         # http://teampasswordmanager.com/docs/api-users/#list_users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |         log.debug('List users') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |         return self.collection('users.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |     def show_user(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |         """Show a user.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |         # http://teampasswordmanager.com/docs/api-users/#show_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |         log.debug('Show user %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |         return self.get('users/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |     def show_me(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |         """Show me.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |         # http://teampasswordmanager.com/docs/api-users/#show_me | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |         log.debug('Show Info about own user') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |         return self.get('users/me.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |     def who_am_i(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |         """Who am I.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |         return self.show_me() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |     def create_user(self, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |         """Create a User.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |         # http://teampasswordmanager.com/docs/api-users/#create_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |         log.info('Create user with %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |         NewID = self.post('users.json', data).get('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |         log.info('User has been created with ID %s' % NewID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |         return NewID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |     def update_user(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |         """Update a User.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |         # http://teampasswordmanager.com/docs/api-users/#update_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |         log.info('Update user %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |         self.put('users/%s.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |     def change_user_password(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |         """Change password of a User.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |         # http://teampasswordmanager.com/docs/api-users/#change_password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |         log.info('Change user %s password' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |         self.put('users/%s/change_password.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |     def activate_user(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |         """Activate a User.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |         # http://teampasswordmanager.com/docs/api-users/#activate_deactivate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |         log.info('Activate user %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |         self.put('users/%s/activate.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |     def deactivate_user(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |         """Dectivate a User.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |         # http://teampasswordmanager.com/docs/api-users/#activate_deactivate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |         log.info('Deactivate user %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |         self.put('users/%s/deactivate.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |     def convert_user_to_ldap(self, ID, DN): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |         """Convert a normal user to a LDAP user.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |         # http://teampasswordmanager.com/docs/api-users/#convert_to_ldap | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |         data = {'login_dn': DN} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |         log.info('Convert User %s to LDAP DN %s' % (ID, DN)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |         self.put('users/%s/convert_to_ldap.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |     def convert_ldap_user_to_normal(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |         """Convert a LDAP user to a normal user.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |         log.info('Convert User %s from LDAP to normal user' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |         self.put('users/%s/convert_to_normal.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |     def delete_user(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |         """Delete a user.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |         # http://teampasswordmanager.com/docs/api-users/#delete_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |         log.info('Delete user %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |         self.delete('users/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |     def list_groups(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |         """List Groups.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#list_groups | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |         log.debug('List groups') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |         return self.collection('groups.json') | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 556 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 557 |  |  |     def show_group(self, ID): | 
            
                                                                        
                            
            
                                    
            
            
                | 558 |  |  |         """Show a Group.""" | 
            
                                                                        
                            
            
                                    
            
            
                | 559 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#show_group | 
            
                                                                        
                            
            
                                    
            
            
                | 560 |  |  |         log.debug('Show group %s' % ID) | 
            
                                                                        
                            
            
                                    
            
            
                | 561 |  |  |         return self.get('groups/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |     def create_group(self, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |         """Create a Group.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#create_group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |         log.info('Create group with %s' % data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |         NewID = self.post('groups.json', data).get('id') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |         log.info('Group has been created with ID %s' % NewID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |         return NewID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |     def update_group(self, ID, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |         """Update a Group.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#update_group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |         log.info('Update group %s with %s' % (ID, data)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |         self.put('groups/%s.json' % ID, data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |     def add_user_to_group(self, GroupID, UserID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |         """Add a user to a group.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#add_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |         log.info('Add User %s to Group %s' % (UserID, GroupID)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |         self.put('groups/%s/add_user/%s.json' % (GroupID, UserID)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |     def delete_user_from_group(self, GroupID, UserID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |         """Delete a user from a group.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#del_user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |         log.info('Delete user %s from group %s' % (UserID, GroupID)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |         self.put('groups/%s/delete_user/%s.json' % (GroupID, UserID)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |     def delete_group(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |         """Delete a group.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |         # http://teampasswordmanager.com/docs/api-groups/#delete_group | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |         log.info('Delete group %s' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |         self.delete('groups/%s.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |     def generate_password(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  |         """Generate a new random password.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |         # http://teampasswordmanager.com/docs/api-passwords-generator/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |         log.debug('Generate new password') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |         return self.get('generate_password.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |     def get_version(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |         """Get Version Information.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |         # http://teampasswordmanager.com/docs/api-version/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |         log.debug('Get version information') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |         return self.get('version.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  |     def get_latest_version(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  |         """Check for latest version.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |         # http://teampasswordmanager.com/docs/api-version/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  |         log.debug('Get latest version') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |         return self.get('version/check_latest.json') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |     def up_to_date(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |         """Check if Team Password Manager is up to date.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |         VersionInfo = self.get_latest_version() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |         CurrentVersion = VersionInfo.get('version') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |         LatestVersion = VersionInfo.get('latest_version') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |         if  CurrentVersion == LatestVersion: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |             log.info('TeamPasswordManager is up-to-date!') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |             log.debug('Current Version: {} Latest Version: {}'.format(LatestVersion, LatestVersion)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |             return True | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |         else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |             log.warning('TeamPasswordManager is not up-to-date!') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |             log.debug('Current Version: {} Latest Version: {}'.format(LatestVersion, LatestVersion)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |             return False | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  | class TpmApiv3(TpmApi): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |     """API v3 based class.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |     def __init__(self, url, **kwargs): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |         super(TpmApiv3, self).__init__('v3', url, kwargs) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |     """From now on, Functions that only work with API v3.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  | class TpmApiv4(TpmApi): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |     """API v4 based class.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  |     def __init__(self, url, **kwargs): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |         super(TpmApiv4, self).__init__('v4', url, kwargs) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  |     """From now on, Functions that only work with API v4.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  |     def list_subprojects(self, ID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |         """List subprojects.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  |         # http://teampasswordmanager.com/docs/api-projects/#list_subprojects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |         return self.collection('projects/%s/subprojects.json' % ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 645 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 646 |  |  |     def list_subprojects_action(self, ID, action): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 647 |  |  |         """List subprojects with allowed action.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 648 |  |  |         return self.collection('projects/%s/subprojects/%s.json' % | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 649 |  |  |                                (ID, action)) | 
            
                                                        
            
                                    
            
            
                | 650 |  |  |  |