github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/packaging/ci/lambda/GitPullS3/pygit2/credentials.py (about) 1 # -*- coding: utf-8 -*- 2 # 3 # Copyright 2010-2015 The pygit2 contributors 4 # 5 # This file is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License, version 2, 7 # as published by the Free Software Foundation. 8 # 9 # In addition to the permissions in the GNU General Public License, 10 # the authors give you unlimited permission to link the compiled 11 # version of this file into combinations with other programs, 12 # and to distribute those combinations without any restriction 13 # coming from the use of this file. (The General Public License 14 # restrictions do apply in other respects; for example, they cover 15 # modification of the file, and distribution when not linked into 16 # a combined executable.) 17 # 18 # This file is distributed in the hope that it will be useful, but 19 # WITHOUT ANY WARRANTY; without even the implied warranty of 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 # General Public License for more details. 22 # 23 # You should have received a copy of the GNU General Public License 24 # along with this program; see the file COPYING. If not, write to 25 # the Free Software Foundation, 51 Franklin Street, Fifth Floor, 26 # Boston, MA 02110-1301, USA. 27 28 from .ffi import C 29 30 GIT_CREDTYPE_USERPASS_PLAINTEXT = C.GIT_CREDTYPE_USERPASS_PLAINTEXT 31 GIT_CREDTYPE_SSH_KEY = C.GIT_CREDTYPE_SSH_KEY 32 33 34 class UserPass(object): 35 """Username/Password credentials 36 37 This is an object suitable for passing to a remote's credentials 38 callback and for returning from said callback. 39 """ 40 41 def __init__(self, username, password): 42 self._username = username 43 self._password = password 44 45 @property 46 def credential_type(self): 47 return GIT_CREDTYPE_USERPASS_PLAINTEXT 48 49 @property 50 def credential_tuple(self): 51 return (self._username, self._password) 52 53 def __call__(self, _url, _username, _allowed): 54 return self 55 56 57 class Keypair(object): 58 """SSH key pair credentials 59 60 This is an object suitable for passing to a remote's credentials 61 callback and for returning from said callback. 62 63 :param str username: the username being used to authenticate with the 64 remote server 65 :param str pubkey: the path to the user's public key file 66 :param str privkey: the path to the user's private key file 67 :param str passphrase: the password used to decrypt the private key file, 68 or empty string if no passphrase is required. 69 """ 70 71 def __init__(self, username, pubkey, privkey, passphrase): 72 self._username = username 73 self._pubkey = pubkey 74 self._privkey = privkey 75 self._passphrase = passphrase 76 77 @property 78 def credential_type(self): 79 return GIT_CREDTYPE_SSH_KEY 80 81 @property 82 def credential_tuple(self): 83 return (self._username, self._pubkey, self._privkey, self._passphrase) 84 85 def __call__(self, _url, _username, _allowed): 86 return self 87 88 89 class KeypairFromAgent(Keypair): 90 def __init__(self, username): 91 super(KeypairFromAgent, self).__init__(username, None, None, None)