async def getKeyToCreds(self, keyfile, basePath=".ssh"): if basePath != ".": keyfile = os.path.join(basePath, keyfile) from baboossh.params import Extensions keysFolder = os.path.join(self.wspaceFolder, "keys") filename = str(self.connection.getEndpoint()).replace( ":", "-") + "_" + str( self.connection.getUser()) + "_" + keyfile.replace("/", "_") filepath = os.path.join(keysFolder, filename) try: await asyncssh.scp((self.socket, keyfile), filepath) except Exception as e: print(e) return None subprocess.run(["chmod", "600", filepath]) p = subprocess.run(["sha1sum", filepath], stdout=subprocess.PIPE) output = p.stdout.decode("utf-8") output = output.split(" ", 1)[0] if output in self.keysHash.keys(): if filepath != self.keysHash[output]: os.remove(filepath) return None valid, haspass = Extensions.getAuthMethod("privkey").checkKeyfile( filepath) if valid: self.keysHash[output] = filepath c = {"passphrase": "", "keypath": filepath, "haspass": haspass} cred = Creds("privkey", json.dumps(c)) if not self.connection.inScope(): cred.unscope() if cred.getId() is None: cred.setFound(self.connection.getEndpoint()) cred.save() self.newCreds.append(cred) return cred else: os.remove(filepath) return None
def addCreds(self,credsType,stmt): credsContent = Extensions.getAuthMethod(credsType).fromStatement(stmt) newCreds = Creds(credsType,credsContent) newCreds.save() return newCreds.getId()